|
| 1 | +name: Test CPFlow 500 promotion preview |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: [jg-codex/test-cpflow-500-preview] |
| 7 | + paths: [.github/workflows/cpflow-500-preview-test.yml] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: cpflow-500-preview-test |
| 14 | + cancel-in-progress: false |
| 15 | + |
| 16 | +jobs: |
| 17 | + preview: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + timeout-minutes: 15 |
| 20 | + outputs: |
| 21 | + staging_image: ${{ steps.preview.outputs.staging_image }} |
| 22 | + production_commit: ${{ steps.preview.outputs.production_commit }} |
| 23 | + steps: |
| 24 | + - name: Checkout tutorial |
| 25 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 26 | + with: |
| 27 | + persist-credentials: false |
| 28 | + - name: Checkout PR 500 candidate |
| 29 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 30 | + with: |
| 31 | + repository: shakacode/control-plane-flow |
| 32 | + ref: f99fb40af3de92cb2d434d414fafecdcd4dbdab2 |
| 33 | + path: .cpflow |
| 34 | + persist-credentials: false |
| 35 | + - name: Normalize staging org |
| 36 | + id: org |
| 37 | + shell: bash |
| 38 | + env: |
| 39 | + STAGING_ORG: ${{ vars.CPLN_ORG_STAGING }} |
| 40 | + run: | |
| 41 | + set -euo pipefail |
| 42 | + org="${STAGING_ORG#"${STAGING_ORG%%[![:space:]]*}"}" |
| 43 | + org="${org%"${org##*[![:space:]]}"}" |
| 44 | + [[ "$org" =~ ^[a-z0-9]([a-z0-9-]*[a-z0-9])?$ ]] || exit 1 |
| 45 | + echo "org=$org" >> "$GITHUB_OUTPUT" |
| 46 | + - name: Setup staging client from candidate source |
| 47 | + uses: ./.cpflow/.github/actions/cpflow-setup-environment |
| 48 | + with: |
| 49 | + token: ${{ secrets.CPLN_TOKEN_STAGING }} |
| 50 | + org: ${{ steps.org.outputs.org }} |
| 51 | + working_directory: .cpflow |
| 52 | + cpflow_source_directory: .cpflow |
| 53 | + cpflow_version: "" |
| 54 | + cpln_cli_version: ${{ vars.CPLN_CLI_VERSION }} |
| 55 | + control_plane_flow_ref: shakacode/control-plane-flow/.github/workflows/cpflow-promote-staging-to-production.yml@f99fb40af3de92cb2d434d414fafecdcd4dbdab2 |
| 56 | + - name: Preview real staging commits |
| 57 | + id: preview |
| 58 | + uses: ./.cpflow/.github/actions/cpflow-preview-promotion |
| 59 | + env: |
| 60 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + GH_REPO: ${{ github.repository }} |
| 62 | + CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }} |
| 63 | + with: |
| 64 | + staging_app_name: ${{ vars.STAGING_APP_NAME }} |
| 65 | + staging_org: ${{ steps.org.outputs.org }} |
| 66 | + primary_workload: ${{ vars.PRIMARY_WORKLOAD }} |
| 67 | + - name: Verify live comparison independently |
| 68 | + shell: bash |
| 69 | + env: |
| 70 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + GH_REPO: ${{ github.repository }} |
| 72 | + STAGING_IMAGE: ${{ steps.preview.outputs.staging_image }} |
| 73 | + PRODUCTION_COMMIT: ${{ steps.preview.outputs.production_commit }} |
| 74 | + run: | |
| 75 | + set -euo pipefail |
| 76 | + [[ "$PRODUCTION_COMMIT" =~ ^[0-9a-f]{40}$ ]] || { |
| 77 | + echo "::error::Test requires a resolvable recorded production release." |
| 78 | + exit 1 |
| 79 | + } |
| 80 | + staging_tag="${STAGING_IMAGE%%@*}" |
| 81 | + staging_commit="${staging_tag##*_}" |
| 82 | + [[ "$staging_commit" =~ ^[0-9a-f]{40}$ ]] || exit 1 |
| 83 | + comparison="$(gh api "repos/$GH_REPO/compare/$PRODUCTION_COMMIT...$staging_commit?per_page=100&page=1")" |
| 84 | + jq -e '.ahead_by >= 0 and (.commits | type == "array")' <<< "$comparison" >/dev/null |
| 85 | + echo "Recorded production: $PRODUCTION_COMMIT" |
| 86 | + echo "Deployed staging: $staging_commit" |
| 87 | + jq '{status, ahead_by, behind_by, total_commits}' <<< "$comparison" |
| 88 | + echo "Compare: https://github.com/$GH_REPO/compare/$PRODUCTION_COMMIT...$staging_commit" |
| 89 | +
|
| 90 | + approval-proof: |
| 91 | + needs: preview |
| 92 | + runs-on: ubuntu-latest |
| 93 | + timeout-minutes: 2 |
| 94 | + environment: cpflow-500-test-approval |
| 95 | + steps: |
| 96 | + - name: Confirm approval without deployment |
| 97 | + shell: bash |
| 98 | + env: |
| 99 | + STAGING_IMAGE: ${{ needs.preview.outputs.staging_image }} |
| 100 | + PRODUCTION_COMMIT: ${{ needs.preview.outputs.production_commit }} |
| 101 | + run: | |
| 102 | + set -euo pipefail |
| 103 | + { |
| 104 | + echo "## Test approval completed" |
| 105 | + echo "The preview finished before this protected job could start." |
| 106 | + echo "Staging image: $STAGING_IMAGE" |
| 107 | + echo "Recorded production commit: $PRODUCTION_COMMIT" |
| 108 | + echo "This test has no production credential, image copy, or deployment step." |
| 109 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments