1+ # ===============================================
2+ # CD Pipeline: Production Environment
3+ # ===============================================
4+ # Description:
5+ # This workflow deploys the register-ticket-api service to the production environment.
6+ # It ensures that the latest deployment in staging was successful before running.
7+ #
8+ # Features:
9+ # 1. Triggered manually via workflow_dispatch.
10+ # 2. Can also be triggered automatically after the "CD pipeline for staging environment" completes.
11+ # 3. Checks the last successful run of staging before deploying to production.
12+ # 4. Deploys using the base CD workflow with secrets inheritance.
13+ #
14+ # Jobs:
15+ # - check-stg-last-run:
16+ # Validates that the last staging deployment succeeded.
17+ # - deploy-to-prd:
18+ # Deploys the application to production only if staging deployment was successful.
19+ # ===============================================
20+
21+ name : CD pipeline for prod environment
22+
23+ on :
24+ workflow_dispatch :
25+
26+ workflow_run :
27+ workflows : ["CD pipeline for staging environment"]
28+ types :
29+ - completed
30+
31+ jobs :
32+ check-stg-last-run :
33+ runs-on : ubunt-latest
34+ outputs :
35+ stg-success : ${{ steps.check.outputs.success }}
36+ steps :
37+ - name : Check staging last deployment was successful
38+ id : check
39+ uses : actions/github-script@v7
40+ with :
41+ script : |
42+ const runs = await github.rest.actions.listWorkflowRuns({
43+ owner: context.repo.owner,
44+ repo: context.repo.repo,
45+ workflow_id: 'staging-deploy.yml', // nombre de tu workflow de staging
46+ branch: 'main',
47+ per_page: 1
48+ });
49+ const lastRun = runs.data.workflow_runs[0];
50+ const isSuccess = lastRun.conclusion === 'success';
51+
52+ core.setOutput('success', isSuccess);
53+
54+ console.log(`Last staging run: ${lastRun.conclusion}`);
55+
56+ if (!isSuccess) {
57+ core.setFailed('El último deployment de staging no fue exitoso');
58+ }
59+
60+ deploy-to-prd :
61+ needs : check-stg-last-run
62+ if : needs.check-stg-last-run.outputs.stg-success == 'true' # only execute if staging last run completed successfully
63+ uses : ./.github/workflows/cd-base.yml
64+ secrets : inherit # pragma: allowlist secret
65+ with :
66+ deployment_env : prd
67+ image_uri : ghcr.io/${{ github.repository_owner }}/register-ticket-api:latest
0 commit comments