|
| 1 | +# End-to-end test for the AUTOMATIC native-CI planfile flow on `deploy`. |
| 2 | +# |
| 3 | +# Distinct from planfile-artifacts-e2e.yml (which exercises the *manual* CLI: |
| 4 | +# `planfile download` + `apply --planfile`). This workflow exercises the |
| 5 | +# hook-driven automatic path: |
| 6 | +# |
| 7 | +# plan job -> `atmos terraform plan` auto-uploads the planfile, then |
| 8 | +# `atmos terraform planfile list` asserts it landed. |
| 9 | +# deploy-verify job -> `atmos terraform deploy` auto-downloads the stored plan, |
| 10 | +# runs the plan-diff, and applies the verified plan |
| 11 | +# (verification is on by default under CI). |
| 12 | +# deploy-drift job -> mutates the component so the fresh plan differs, then |
| 13 | +# asserts `deploy` FAILS on drift (verify mode fail). |
| 14 | +# |
| 15 | +# CI is auto-detected (CI/GITHUB_ACTIONS) and the fixture sets `ci.enabled: true`, |
| 16 | +# so the `--ci` flag is unnecessary — the commands behave natively and assert via |
| 17 | +# their own exit codes and structured output rather than grepping logs. |
| 18 | +# |
| 19 | +# The warn/off mode decisions are covered by unit tests (finalizeVerification, |
| 20 | +# ResolveVerifyMode); this workflow covers the real runner integration. |
| 21 | +# |
| 22 | +# Like the upload, the automatic download talks to the GitHub Artifacts runtime |
| 23 | +# API, so every job surfaces ACTIONS_RUNTIME_TOKEN/RESULTS_URL via the in-repo |
| 24 | +# github-runtime action. OpenTofu is dogfooded through the Atmos toolchain (the |
| 25 | +# fixture declares dependencies.tools.opentofu), so there is no setup-terraform. |
| 26 | +name: Planfile Verify E2E |
| 27 | + |
| 28 | +on: |
| 29 | + workflow_dispatch: |
| 30 | + pull_request: |
| 31 | + types: [opened, synchronize, reopened] |
| 32 | + paths: |
| 33 | + - 'pkg/ci/artifact/**' |
| 34 | + - 'cmd/terraform/**' |
| 35 | + - 'internal/exec/terraform_verify_plan.go' |
| 36 | + - 'internal/exec/terraform_plan_diff*.go' |
| 37 | + - 'pkg/ci/plugins/terraform/**' |
| 38 | + - 'actions/github-runtime/**' |
| 39 | + - 'tests/fixtures/scenarios/planfile-artifacts-e2e/**' |
| 40 | + - '.github/workflows/planfile-verify-e2e.yml' |
| 41 | + |
| 42 | +permissions: |
| 43 | + contents: read |
| 44 | + actions: read # GITHUB_TOKEN reads artifacts via the REST API (fallback path). |
| 45 | + |
| 46 | +concurrency: |
| 47 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 48 | + cancel-in-progress: true |
| 49 | + |
| 50 | +env: |
| 51 | + # Pin the SHA so the plan upload and the deploy download derive the identical |
| 52 | + # planfile key across jobs. |
| 53 | + ATMOS_CI_SHA: ${{ github.sha }} |
| 54 | + GITHUB_TOKEN: ${{ github.token }} |
| 55 | + FIXTURE_DIR: tests/fixtures/scenarios/planfile-artifacts-e2e |
| 56 | + |
| 57 | +jobs: |
| 58 | + plan: |
| 59 | + name: plan (upload planfile) |
| 60 | + runs-on: ubuntu-latest |
| 61 | + steps: |
| 62 | + - name: Checkout |
| 63 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 64 | + with: |
| 65 | + persist-credentials: false |
| 66 | + - name: Set up Go |
| 67 | + uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 |
| 68 | + with: |
| 69 | + go-version-file: "go.mod" |
| 70 | + - name: Build atmos |
| 71 | + run: | |
| 72 | + make build |
| 73 | + echo "$PWD/build" >> "$GITHUB_PATH" |
| 74 | + - name: Expose GitHub Actions runtime credentials |
| 75 | + uses: ./actions/github-runtime |
| 76 | + with: |
| 77 | + mode: env |
| 78 | + - name: Plan and upload the planfile |
| 79 | + working-directory: tests/fixtures/scenarios/planfile-artifacts-e2e |
| 80 | + # No --ci: GitHub Actions is auto-detected (CI/GITHUB_ACTIONS) and the |
| 81 | + # fixture sets ci.enabled, so the upload hook runs natively. |
| 82 | + run: atmos terraform plan mycomponent -s prod |
| 83 | + - name: List the uploaded planfile |
| 84 | + working-directory: tests/fixtures/scenarios/planfile-artifacts-e2e |
| 85 | + # Exercises the github/artifacts List() against the real runner API and |
| 86 | + # proves the upload landed, asserting the command's structured JSON output |
| 87 | + # (not grepping log prose). The command already filters by component+stack |
| 88 | + # +SHA, so a non-empty array means the planfile is there; an absent one |
| 89 | + # renders `null`, which `length > 0` fails on. |
| 90 | + run: | |
| 91 | + set -euo pipefail |
| 92 | + atmos terraform planfile list mycomponent -s prod --format=json \ |
| 93 | + | jq -e 'length > 0' > /dev/null |
| 94 | +
|
| 95 | + deploy-verify: |
| 96 | + name: deploy (auto verify + apply) |
| 97 | + needs: plan |
| 98 | + runs-on: ubuntu-latest |
| 99 | + steps: |
| 100 | + - name: Checkout |
| 101 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 102 | + with: |
| 103 | + persist-credentials: false |
| 104 | + - name: Set up Go |
| 105 | + uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 |
| 106 | + with: |
| 107 | + go-version-file: "go.mod" |
| 108 | + - name: Build atmos |
| 109 | + run: | |
| 110 | + make build |
| 111 | + echo "$PWD/build" >> "$GITHUB_PATH" |
| 112 | + - name: Expose GitHub Actions runtime credentials |
| 113 | + uses: ./actions/github-runtime |
| 114 | + with: |
| 115 | + mode: env |
| 116 | + - name: Deploy with automatic verification |
| 117 | + working-directory: tests/fixtures/scenarios/planfile-artifacts-e2e |
| 118 | + # No drift: the deploy re-plans the unchanged component, the plan-diff matches |
| 119 | + # the stored plan, and the verified plan is applied. No --ci, no log grep: a |
| 120 | + # green deploy *proves* verification ran, because a missing stored plan now |
| 121 | + # fails loudly (planfiles.required defaults to tracking the verify mode, |
| 122 | + # which is fail under CI). |
| 123 | + run: atmos terraform deploy mycomponent -s prod |
| 124 | + |
| 125 | + deploy-drift: |
| 126 | + name: deploy (drift fails) |
| 127 | + needs: plan |
| 128 | + runs-on: ubuntu-latest |
| 129 | + steps: |
| 130 | + - name: Checkout |
| 131 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 132 | + with: |
| 133 | + persist-credentials: false |
| 134 | + - name: Set up Go |
| 135 | + uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 |
| 136 | + with: |
| 137 | + go-version-file: "go.mod" |
| 138 | + - name: Build atmos |
| 139 | + run: | |
| 140 | + make build |
| 141 | + echo "$PWD/build" >> "$GITHUB_PATH" |
| 142 | + - name: Expose GitHub Actions runtime credentials |
| 143 | + uses: ./actions/github-runtime |
| 144 | + with: |
| 145 | + mode: env |
| 146 | + - name: Induce drift and expect deploy to fail |
| 147 | + working-directory: tests/fixtures/scenarios/planfile-artifacts-e2e |
| 148 | + # Native exit code is the contract: deploy exits non-zero on drift |
| 149 | + # (ErrPlanVerificationFailed), so an inverted check needs no --ci, no |
| 150 | + # captured `$?`, and no log grep. |
| 151 | + run: | |
| 152 | + set -euo pipefail |
| 153 | + # Mutate the component so the fresh plan differs from the stored plan. |
| 154 | + sed -i 's/test = "test"/test = "drifted"/' components/terraform/mock/main.tf |
| 155 | +
|
| 156 | + if atmos terraform deploy mycomponent -s prod; then |
| 157 | + echo "ERROR: expected drift to block the deploy, but it succeeded." |
| 158 | + exit 1 |
| 159 | + fi |
| 160 | + echo "Drift correctly blocked the deploy." |
0 commit comments