Skip to content

Removed validation and drift detection #20

Removed validation and drift detection

Removed validation and drift detection #20

name: πŸ›οΈ Magento Cloud Deployment

Check failure on line 1 in .github/workflows/magento-cloud-deploy.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/magento-cloud-deploy.yml

Invalid workflow file

(Line: 88, Col: 13): Unrecognized named-value: 'secrets'. Located at position 33 within expression: inputs.newrelic-app-id != '' && secrets.newrelic-api-key != '', (Line: 204, Col: 13): Unrecognized named-value: 'secrets'. Located at position 45 within expression: always() && inputs.newrelic-app-id != '' && secrets.newrelic-api-key != ''
on:
workflow_call:
inputs:
# Magento Cloud Configuration
magento-cloud-project-id:
description: "Magento Cloud project ID (required)"
type: string
required: true
environment:
description: "Target environment (integration/staging/production)"
type: string
required: false
default: "integration"
# Monitoring and Reporting
newrelic-app-id:
description: "NewRelic application ID for deployment markers (optional)"
type: string
required: false
default: ""
# CST Reporting Configuration
cst-endpoint:
description: "CST endpoint base URL (optional, overrides workspace variable)"
type: string
required: false
default: ""
cst-project-key:
description: "CST project key (optional, overrides workspace variable)"
type: string
required: false
default: ""
# Advanced Configuration
debug:
description: "Enable verbose logging and debug output"
type: boolean
required: false
default: false
secrets:
magento-cloud-cli-token:
description: "Magento Cloud CLI token for authentication"
required: true
newrelic-api-key:
description: "NewRelic API key for deployment markers (optional)"
required: false
cst-reporting-token:
description: "CST system reporting token (optional)"
required: false
outputs:
deployment-url:
description: "URL of the deployed Magento application"
value: ${{ jobs.deploy.outputs.deployment-url }}
deployment-id:
description: "Magento Cloud deployment ID"
value: ${{ jobs.deploy.outputs.deployment-id }}
jobs:
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"
- 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:
fetch-depth: 0 # Full git history required for Magento Cloud
- name: Install Magento Cloud CLI
run: |
echo "πŸ“¦ Installing Magento Cloud CLI..."
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"
- name: Deploy to Magento Cloud
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")
# Push to integration environment
echo "Deploying to integration environment..."
magento-cloud push --force --wait $debug
;;
"staging"|"production")
# Push to staging/production branch
echo "Deploying to ${{ inputs.environment }} environment..."
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=$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 "id=$DEPLOYMENT_ID" >> "$GITHUB_OUTPUT"
if [ "${{ inputs.debug }}" = "true" ]; then
echo "πŸ” Deployment information:"
echo " URL: ${URL}"
echo " Deployment ID: ${DEPLOYMENT_ID}"
fi
- name: Generate deployment summary
run: |
echo "## πŸ›οΈ Magento Cloud Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY
echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| **Project ID** | ${{ inputs.magento-cloud-project-id }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Environment** | ${{ inputs.environment }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Deployment ID** | ${{ steps.deploy-info.outputs.id }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Site URL** | [${{ steps.deploy-info.outputs.url }}](${{ steps.deploy-info.outputs.url }}) |" >> $GITHUB_STEP_SUMMARY
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
echo "Your Magento store is now live at:" >> $GITHUB_STEP_SUMMARY
echo "**[${{ steps.deploy-info.outputs.url }}](${{ steps.deploy-info.outputs.url }})**" >> $GITHUB_STEP_SUMMARY
;;
"staging")
echo "### πŸš€ Staging Environment" >> $GITHUB_STEP_SUMMARY
echo "Staging environment updated successfully:" >> $GITHUB_STEP_SUMMARY
echo "**[${{ steps.deploy-info.outputs.url }}](${{ steps.deploy-info.outputs.url }})**" >> $GITHUB_STEP_SUMMARY
;;
*)
echo "### πŸ”§ Integration Environment" >> $GITHUB_STEP_SUMMARY
echo "Integration environment deployed for testing:" >> $GITHUB_STEP_SUMMARY
echo "**[${{ steps.deploy-info.outputs.url }}](${{ steps.deploy-info.outputs.url }})**" >> $GITHUB_STEP_SUMMARY
;;
esac
- name: Create NewRelic deployment marker (complete)
if: always() && inputs.newrelic-app-id != '' && secrets.newrelic-api-key != ''
run: |
echo "πŸ“Š Creating NewRelic deployment marker (complete)..."
# 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 ${{ steps.deploy-info.outputs.url }}"
echo "βœ… Deployment was successful"
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 [ "${{ 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: ${{ 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" \
-d "{
\"deployment\": {
\"revision\": \"${{ github.sha }}\",
\"changelog\": \"${CHANGELOG}\",
\"description\": \"${DESCRIPTION}\",
\"user\": \"${{ github.actor }}\"
}
}"
echo "βœ… NewRelic deployment marker created with status: ${{ steps.deployment.outcome }}"
- 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)"
echo " - Endpoint: $([ -n "$CST_ENDPOINT" ] && echo "βœ… configured" || echo "❌ missing")"
echo " - Project Key: $([ -n "$CST_PROJECT_KEY" ] && echo "βœ… configured" || echo "❌ missing")"
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"
fi