Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 61 additions & 107 deletions .github/workflows/magento-cloud-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,38 +60,49 @@ on:
value: ${{ jobs.deploy.outputs.deployment-id }}

jobs:
# Simple validation job
validate:
name: 🔍 Validate Inputs
deploy:
name: 🚀 Deploy to Magento Cloud
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
env:
MAGENTO_CLOUD_CLI_TOKEN: ${{ secrets.magento-cloud-cli-token }}
outputs:
deployment-url: ${{ steps.deploy-info.outputs.url }}
deployment-id: ${{ steps.deploy-info.outputs.id }}
steps:
- name: Validate required inputs
run: |
if [ -z "${{ inputs.magento-cloud-project-id }}" ]; then
echo "❌ Error: magento-cloud-project-id is required"
exit 1
fi

if [ "${{ inputs.environment }}" != "integration" ] && [ "${{ inputs.environment }}" != "staging" ] && [ "${{ inputs.environment }}" != "production" ]; then
echo "❌ Error: environment must be one of: integration, staging, production"
exit 1
fi

echo "✅ All required inputs validated"

# Simple deploy to Magento Cloud
deploy:
name: 🚀 Deploy to Magento Cloud
runs-on: ubuntu-latest
needs: [validate, newrelic-start]
if: always() && needs.validate.result == 'success'
environment: ${{ inputs.environment }}
env:
MAGENTO_CLOUD_CLI_TOKEN: ${{ secrets.magento-cloud-cli-token }}
outputs:
deployment-url: ${{ steps.deploy-info.outputs.url }}
deployment-id: ${{ steps.deploy-info.outputs.id }}
steps:
- name: Create NewRelic deployment marker (start)
if: inputs.newrelic-app-id != '' && secrets.newrelic-api-key != ''
run: |
echo "📊 Creating NewRelic deployment marker (start)..."

curl -X POST "https://api.newrelic.com/v2/applications/${{ inputs.newrelic-app-id }}/deployments.json" \
-H "X-Api-Key: ${{ secrets.newrelic-api-key }}" \
-H "Content-Type: application/json" \
-d '{
"deployment": {
"revision": "${{ github.sha }}",
"changelog": "Magento Cloud deployment started",
"description": "Deployment to ${{ inputs.environment }} environment",
"user": "${{ github.actor }}"
}
}'

echo "✅ NewRelic deployment start marker created"

- name: Checkout code with full git history
uses: actions/checkout@v4
with:
Expand All @@ -103,7 +114,7 @@ jobs:
curl -fsS https://accounts.magento.cloud/cli/installer | php
export PATH=$HOME/.magento-cloud/bin:$PATH
echo "$HOME/.magento-cloud/bin" >> $GITHUB_PATH

# Verify installation
magento-cloud --version
echo "✅ Magento Cloud CLI installed successfully"
Expand All @@ -112,15 +123,15 @@ jobs:
id: deployment
run: |
echo "🚀 Starting deployment to ${{ inputs.environment }}..."

debug=""
if [ "${{ inputs.debug }}" = "true" ]; then
debug="--verbose"
fi

# Set project context
magento-cloud project:set-remote "${{ inputs.magento-cloud-project-id }}"

# Deploy based on environment type
case "${{ inputs.environment }}" in
"integration")
Expand All @@ -134,30 +145,23 @@ jobs:
magento-cloud push --environment "${{ inputs.environment }}" --force --wait $debug
;;
esac

echo "✅ Deployment completed successfully"
echo "deployment-success=true" >> $GITHUB_OUTPUT

- name: Get deployment information
id: deploy-info
run: |
echo "📋 Retrieving deployment information..."

# Get environment URL
URL=$(magento-cloud url --environment "${{ inputs.environment }}" --project "${{ inputs.magento-cloud-project-id }}" --pipe | tr -d '[:space:]')
{
echo "url<<EOF"
echo "url=$URL"
echo "EOF"
} >> "$GITHUB_OUTPUT"

echo "url=$URL" >> "$GITHUB_OUTPUT"

# Get deployment ID
DEPLOYMENT_ID=$(magento-cloud activity:list --environment "${{ inputs.environment }}" --type push --limit 1 --format csv --columns id --no-header | head -1)
{
echo "url<<EOF"
echo "id=$DEPLOYMENT_ID"
echo "EOF"
} >> "$GITHUB_OUTPUT"

echo "id=$DEPLOYMENT_ID" >> "$GITHUB_OUTPUT"

if [ "${{ inputs.debug }}" = "true" ]; then
echo "🔍 Deployment information:"
echo " URL: ${URL}"
Expand All @@ -177,7 +181,7 @@ jobs:
echo "| **Git Commit** | ${{ github.sha }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Deployed By** | ${{ github.actor }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

case "${{ inputs.environment }}" in
"production")
echo "### 🌍 Production Deployment" >> $GITHUB_STEP_SUMMARY
Expand All @@ -196,71 +200,30 @@ jobs:
;;
esac

# NewRelic Start Marker Job - runs before deployment
newrelic-start:
name: 📊 NewRelic Start
runs-on: ubuntu-latest
needs: [validate]
if: inputs.newrelic-app-id != ''
steps:
- name: Create NewRelic deployment marker (start)
run: |
if [ -z "${{ secrets.newrelic-api-key }}" ]; then
echo "⚠️ NewRelic API key not provided, skipping deployment marker"
exit 0
fi

echo "📊 Creating NewRelic deployment marker (start)..."

curl -X POST "https://api.newrelic.com/v2/applications/${{ inputs.newrelic-app-id }}/deployments.json" \
-H "X-Api-Key: ${{ secrets.newrelic-api-key }}" \
-H "Content-Type: application/json" \
-d '{
"deployment": {
"revision": "${{ github.sha }}",
"changelog": "Magento Cloud deployment started",
"description": "Deployment to ${{ inputs.environment }} environment",
"user": "${{ github.actor }}"
}
}'

echo "✅ NewRelic deployment start marker created"

# NewRelic Complete Marker Job - runs after deployment (success or failure)
newrelic-complete:
name: 📊 NewRelic Complete
runs-on: ubuntu-latest
needs: [deploy]
if: always() && inputs.newrelic-app-id != ''
steps:
- name: Create NewRelic deployment marker (complete)
if: always() && inputs.newrelic-app-id != '' && secrets.newrelic-api-key != ''
run: |
if [ -z "${{ secrets.newrelic-api-key }}" ]; then
echo "⚠️ NewRelic API key not provided, skipping deployment marker"
exit 0
fi

echo "📊 Creating NewRelic deployment marker (complete)..."
# Determine deployment status and set appropriate message
if [ "${{ needs.deploy.result }}" == "success" ]; then

# Determine deployment status based on previous step outcomes
if [ "${{ steps.deployment.outcome }}" == "success" ]; then
CHANGELOG="Magento Cloud deployment completed successfully"
DESCRIPTION="Deployment to ${{ inputs.environment }} completed at ${{ needs.deploy.outputs.deployment-url }}"
DESCRIPTION="Deployment to ${{ inputs.environment }} completed at ${{ steps.deploy-info.outputs.url }}"
echo "✅ Deployment was successful"
elif [ "${{ needs.deploy.result }}" == "failure" ]; then
elif [ "${{ steps.deployment.outcome }}" == "failure" ]; then
CHANGELOG="Magento Cloud deployment failed"
DESCRIPTION="Deployment to ${{ inputs.environment }} failed - check workflow logs for details"
echo "❌ Deployment failed"
elif [ "${{ needs.deploy.result }}" == "cancelled" ]; then
elif [ "${{ steps.deployment.outcome }}" == "cancelled" ]; then
CHANGELOG="Magento Cloud deployment cancelled"
DESCRIPTION="Deployment to ${{ inputs.environment }} was cancelled by user"
echo "⚠️ Deployment was cancelled"
else
CHANGELOG="Magento Cloud deployment status: ${{ needs.deploy.result }}"
DESCRIPTION="Deployment to ${{ inputs.environment }} ended with status: ${{ needs.deploy.result }}"
echo "ℹ️ Deployment status: ${{ needs.deploy.result }}"
CHANGELOG="Magento Cloud deployment status: ${{ steps.deployment.outcome }}"
DESCRIPTION="Deployment to ${{ inputs.environment }} ended with status: ${{ steps.deployment.outcome }}"
echo "ℹ️ Deployment status: ${{ steps.deployment.outcome }}"
fi

curl -X POST "https://api.newrelic.com/v2/applications/${{ inputs.newrelic-app-id }}/deployments.json" \
-H "X-Api-Key: ${{ secrets.newrelic-api-key }}" \
-H "Content-Type: application/json" \
Expand All @@ -272,39 +235,30 @@ jobs:
\"user\": \"${{ github.actor }}\"
}
}"

echo "✅ NewRelic deployment marker created with status: ${{ needs.deploy.result }}"

# CST Reporting Job - runs in parallel with NewRelic complete after successful deployment
cst-report:
name: 📡 Report to CST
runs-on: ubuntu-latest
needs: [deploy]
if: needs.deploy.result == 'success'
steps:
- name: Checkout code
uses: actions/checkout@v4
echo "✅ NewRelic deployment marker created with status: ${{ steps.deployment.outcome }}"

- name: Report deployment to CST (Confidentiality and Security Team)
- name: Report deployment to CST
if: steps.deployment.outcome == 'success'
run: |
# Determine CST endpoint - input overrides workspace variable
CST_ENDPOINT="${{ inputs.cst-endpoint }}"
if [ -z "$CST_ENDPOINT" ]; then
CST_ENDPOINT="${{ vars.CST_ENDPOINT }}"
fi

# Determine CST project key - input overrides workspace variable
CST_PROJECT_KEY="${{ inputs.cst-project-key }}"
if [ -z "$CST_PROJECT_KEY" ]; then
CST_PROJECT_KEY="${{ vars.CST_PROJECT_KEY }}"
fi

# Determine CST reporting key - input overrides workspace secret
CST_KEY="${{ secrets.cst-reporting-token }}"
if [ -z "$CST_KEY" ]; then
CST_KEY="${{ secrets.CST_REPORTING_TOKEN }}"
fi

# Check if we have all required CST configuration
if [ -z "$CST_ENDPOINT" ] || [ -z "$CST_PROJECT_KEY" ] || [ -z "$CST_KEY" ]; then
echo "ℹ️ CST reporting skipped (missing endpoint, project key, or auth key)"
Expand All @@ -313,19 +267,19 @@ jobs:
echo " - Auth Key: $([ -n "$CST_KEY" ] && echo "✅ configured" || echo "❌ missing")"
exit 0
fi

echo "📡 Reporting deployment to CST (Confidentiality and Security Team)..."

# Construct full CST URL: endpoint/project_key/adobe-commerce
CST_FULL_URL="${CST_ENDPOINT}/${CST_PROJECT_KEY}/adobe-commerce"

# Send composer.lock file contents to CST endpoint
if [ -f "composer.lock" ]; then
curl -X POST "${CST_FULL_URL}" \
-H "Authorization: Bearer ${CST_KEY}" \
-H "Content-Type: application/octet-stream" \
--data-binary @composer.lock

echo "✅ Deployment reported to CST systems at ${CST_FULL_URL}"
else
echo "⚠️ composer.lock not found, skipping CST reporting"
Expand Down
3 changes: 1 addition & 2 deletions docs/magento-cloud-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ A simple Magento Cloud deployment workflow that pushes code to your Magento Clou
- **CST system integration**: Optional composer.lock reporting to Confidentiality and Security Team
- **Environment protection**: Uses GitHub environment protection rules for deployment gates
- **Full git history support**: Required for Magento Cloud deployment requirements
- **Parallel post-deployment**: NewRelic completion and CST reporting run in parallel for efficiency

#### **Inputs**
| Name | Required | Type | Default | Description |
Expand Down Expand Up @@ -98,4 +97,4 @@ jobs:
secrets:
magento-cloud-cli-token: ${{ secrets.MAGENTO_CLOUD_CLI_TOKEN }}
cst-reporting-token: ${{ secrets.CST_REPORTING_TOKEN }}
```
```