Removed validation and drift detection #20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: ποΈ Magento Cloud Deployment | ||
|
Check failure on line 1 in .github/workflows/magento-cloud-deploy.yml
|
||
| 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 | ||