grada-run 0.42.0 → 0.43.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/bin/cli.js +1 -1
  2. package/package.json +1 -1
  3. package/src/commands/add.js +93 -11
  4. package/src/commands/alerts.js +66 -30
  5. package/src/commands/apply.js +65 -10
  6. package/src/commands/db/backup.js +1 -2
  7. package/src/commands/db/connect.js +10 -4
  8. package/src/commands/db/enable-vector.js +19 -6
  9. package/src/commands/db/import.js +114 -22
  10. package/src/commands/db/migrate.js +82 -74
  11. package/src/commands/db/restore.js +38 -6
  12. package/src/commands/destroy.js +20 -3
  13. package/src/commands/diagnose.js +40 -21
  14. package/src/commands/doctor.js +27 -2
  15. package/src/commands/domain.js +20 -2
  16. package/src/commands/drift.js +2 -1
  17. package/src/commands/eject.js +13 -2
  18. package/src/commands/gc.js +100 -3
  19. package/src/commands/init.js +75 -9
  20. package/src/commands/logs.js +3 -1
  21. package/src/commands/mcp.js +2 -1
  22. package/src/commands/rollback.js +54 -5
  23. package/src/commands/secrets.js +260 -64
  24. package/src/commands/status.js +4 -1
  25. package/src/commands/sync-ai.js +4 -3
  26. package/src/commands/wake.js +45 -1
  27. package/src/data/action-pins.js +26 -0
  28. package/src/utils/addons.js +9 -6
  29. package/src/utils/ai-rules.js +3 -2
  30. package/src/utils/backup.js +16 -2
  31. package/src/utils/command.js +20 -0
  32. package/src/utils/db-tunnel.js +15 -5
  33. package/src/utils/detector.js +8 -0
  34. package/src/utils/ecs-runner.js +16 -3
  35. package/src/utils/frameworks.js +14 -2
  36. package/src/utils/generator.js +21 -13
  37. package/src/utils/prompts.js +20 -4
  38. package/src/utils/resolvers.js +9 -7
  39. package/src/utils/revision-discovery.js +19 -7
  40. package/templates/docker/django.Dockerfile +2 -2
  41. package/templates/docker/go.Dockerfile +2 -2
  42. package/templates/docker/nestjs.Dockerfile +2 -2
  43. package/templates/docker/nextjs.Dockerfile +3 -3
  44. package/templates/docker/node.Dockerfile +2 -2
  45. package/templates/docker/nuxt.Dockerfile +2 -2
  46. package/templates/docker/python.Dockerfile +2 -2
  47. package/templates/docker/rails.Dockerfile +2 -2
  48. package/templates/docker/static.Dockerfile +2 -2
  49. package/templates/docker/svelte.Dockerfile +2 -2
  50. package/templates/github/deploy-lambda.yml +55 -12
  51. package/templates/github/deploy-static.yml +24 -6
  52. package/templates/github/deploy.yml +96 -13
  53. package/templates/github/drift.yml +68 -5
  54. package/templates/github/preview-lambda.yml +137 -13
  55. package/templates/github/preview.yml +135 -13
  56. package/templates/github/teardown.yml +71 -12
  57. package/templates/terraform/addons/s3.tf +35 -0
  58. package/templates/terraform/backend.tf +7 -0
  59. package/templates/terraform/database-mysql.tf +9 -1
  60. package/templates/terraform/database.tf +9 -1
  61. package/templates/terraform/oidc.tf +3 -2
  62. package/templates/terraform/secrets.tf +6 -4
  63. package/templates/terraform/worker.tf +7 -0
@@ -1,5 +1,5 @@
1
1
  # Stage 1: Build the Rails application
2
- FROM ruby:3.3.5-alpine AS builder
2
+ FROM ruby:3.3.5-alpine@sha256:b4c321a99b9f21b7bb24f22e558bf1477630fb55d692aba4e25b2fe5deb7eaf1 AS builder
3
3
  WORKDIR /app
4
4
 
5
5
  # Install native build tools required to compile C extensions (like pg or nokogiri)
@@ -21,7 +21,7 @@ COPY . .
21
21
  RUN SECRET_KEY_BASE=dummy bundle exec rails assets:precompile || true
22
22
 
23
23
  # Stage 2: Production runner
24
- FROM ruby:3.3.5-alpine AS runner
24
+ FROM ruby:3.3.5-alpine@sha256:b4c321a99b9f21b7bb24f22e558bf1477630fb55d692aba4e25b2fe5deb7eaf1 AS runner
25
25
  WORKDIR /app
26
26
 
27
27
  ENV RAILS_ENV=production \
@@ -1,5 +1,5 @@
1
1
  # STAGE 1: Build the static assets
2
- FROM node:22-alpine AS builder
2
+ FROM node:22-alpine@sha256:fe4f6d74e20370acb04ad889077d14d0f64a9c8ea6a42bc60cddf1e844699914 AS builder
3
3
  WORKDIR /app
4
4
 
5
5
  COPY package*.json ./
@@ -11,7 +11,7 @@ COPY . .
11
11
  RUN npm run build
12
12
 
13
13
  # STAGE 2: Serve with Hardened Nginx
14
- FROM nginxinc/nginx-unprivileged:alpine
14
+ FROM nginxinc/nginx-unprivileged:alpine@sha256:b5047b9b76845eac124358373c6852377c52e4b05834a47647e955dd91cb8f1e
15
15
  USER root
16
16
  RUN apk upgrade --no-cache
17
17
  USER nginx
@@ -1,7 +1,7 @@
1
1
  # ==========================================
2
2
  # Stage 1: Builder
3
3
  # ==========================================
4
- FROM node:22-alpine AS builder
4
+ FROM node:22-alpine@sha256:fe4f6d74e20370acb04ad889077d14d0f64a9c8ea6a42bc60cddf1e844699914 AS builder
5
5
  WORKDIR /app
6
6
 
7
7
  # Install all dependencies (including devDependencies)
@@ -24,7 +24,7 @@ RUN GRADA_BYPASS=true npm run build
24
24
  # ==========================================
25
25
  # Stage 2: Production (Zero-CVE)
26
26
  # ==========================================
27
- FROM node:22-alpine
27
+ FROM node:22-alpine@sha256:fe4f6d74e20370acb04ad889077d14d0f64a9c8ea6a42bc60cddf1e844699914
28
28
 
29
29
  # 1. DevSecOps: Patch underlying Alpine OS vulnerabilities
30
30
  RUN apk update && apk upgrade --no-cache
@@ -26,10 +26,11 @@ jobs:
26
26
  deploy:
27
27
  name: Build & Deploy
28
28
  runs-on: ubuntu-latest
29
+ timeout-minutes: 60
29
30
 
30
31
  steps:
31
32
  - name: Checkout Code
32
- uses: actions/checkout@v4
33
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
33
34
 
34
35
  # --- 1. IaC SECURITY SCAN ---
35
36
  - name: Scan Terraform for Misconfigurations
@@ -53,18 +54,39 @@ jobs:
53
54
  echo '```' >> $GITHUB_STEP_SUMMARY
54
55
  fi
55
56
 
56
- # --- 2. INFRASTRUCTURE SYNC (The New Marketplace Action) ---
57
- - name: Apply Infrastructure Changes
58
- uses: grada-run/grada-action@v1
57
+ # --- 2. AWS AUTH (job-level credentials for every step below) ---
58
+ - name: Configure AWS credentials
59
+ id: aws-creds
60
+ uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4
61
+ continue-on-error: true
59
62
  with:
60
- aws-region: ${{ env.AWS_REGION }}
61
63
  role-to-assume: arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role
62
- terraform-dir: 'terraform'
64
+ aws-region: ${{ env.AWS_REGION }}
63
65
 
64
- # --- 3. BUILD & PUSH ---
66
+ # Deploy never skips: a failed assume fails the run with the
67
+ # bootstrap pointer (BUG-138).
68
+ - name: Interpret credential failure
69
+ if: steps.aws-creds.outcome == 'failure'
70
+ run: |
71
+ echo "::error::AWS credential assumption failed — if the stack was never provisioned, bootstrap it first (npx grada-run apply); otherwise check terraform/oidc.tf trust."
72
+ exit 1
73
+
74
+ # --- 3. ECR BOOTSTRAP ---
75
+ # The image is pushed BEFORE the full apply (the function must never
76
+ # point at an unpushed tag), but the repository itself is
77
+ # Terraform-managed — so it is bootstrapped with a targeted apply
78
+ # first. Idempotent on existing stacks.
79
+ - name: Bootstrap ECR repository
80
+ working-directory: ./terraform
81
+ run: |
82
+ terraform init -input=false
83
+ terraform workspace select default
84
+ terraform apply -target=aws_ecr_repository.app -auto-approve -input=false
85
+
86
+ # --- 4. BUILD ---
65
87
  - name: Login to Amazon ECR
66
88
  id: login-ecr
67
- uses: aws-actions/amazon-ecr-login@v2
89
+ uses: aws-actions/amazon-ecr-login@03f1aad4c6c7ffd436567f42f9384779290529bd # v2
68
90
 
69
91
  - name: Build Docker image
70
92
  id: build-image
@@ -78,8 +100,8 @@ jobs:
78
100
  docker build --platform linux/amd64 -t $ECR_REGISTRY/$ECR_REPOSITORY:$SHA_TAG .
79
101
  docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$SHA_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
80
102
 
81
- # --- 4. CONTAINER SECURITY SCAN ---
82
- - name: Scan Container for Vulnerabilities (SARIF Output)
103
+ # --- 5. CONTAINER SECURITY SCAN ---
104
+ - name: Scan Container for Vulnerabilities (table summary)
83
105
  uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
84
106
  with:
85
107
  image-ref: '${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest'
@@ -100,8 +122,9 @@ jobs:
100
122
  echo '```' >> $GITHUB_STEP_SUMMARY
101
123
  fi
102
124
 
103
- # --- 5. DEPLOY ---
125
+ # --- 6. PUSH ---
104
126
  - name: Push image to Amazon ECR
127
+ id: push
105
128
  env:
106
129
  ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
107
130
  IMAGE_TAG: latest
@@ -111,6 +134,17 @@ jobs:
111
134
  docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
112
135
  echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$SHA_TAG" >> $GITHUB_OUTPUT
113
136
 
137
+ # --- 7. INFRASTRUCTURE SYNC (The New Marketplace Action) ---
138
+ # Runs AFTER the push: the function image tags exist by the time the
139
+ # function is created or updated.
140
+ - name: Apply Infrastructure Changes
141
+ uses: grada-run/grada-action@12227808ae4caafaec1041319645586a1132fc57 # v1
142
+ with:
143
+ aws-region: ${{ env.AWS_REGION }}
144
+ role-to-assume: arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role
145
+ terraform-dir: 'terraform'
146
+
147
+ # --- 8. DEPLOY ---
114
148
  # Each code push deploys the immutable SHA-tagged image to the Lambda
115
149
  # function, so every ECR tag stays a redeployable rollback point (and
116
150
  # `latest` is never the deploy artifact of record).
@@ -125,7 +159,7 @@ jobs:
125
159
  --function-name ${{ env.LAMBDA_FUNCTION }} \
126
160
  --region ${{ env.AWS_REGION }}
127
161
 
128
- # --- 6. CACHE INVALIDATION ---
162
+ # --- 9. CACHE INVALIDATION ---
129
163
  # New code means new HTML: clear the CDN so deploys go live
130
164
  # immediately instead of serving stale pages until TTL expiry.
131
165
  - name: Invalidate CloudFront
@@ -142,3 +176,12 @@ jobs:
142
176
  --distribution-id "$DIST_ID" \
143
177
  --paths "/*" \
144
178
  --region ${{ env.AWS_REGION }}
179
+
180
+ # A cancelled apply/destroy can strand the S3 state lockfile: point
181
+ # at recovery instead of leaving the next run to fail obscurely
182
+ # (BUG-194). Generic by necessity — the lock ID only exists in the
183
+ # follow-up run's own error.
184
+ - name: Cancellation recovery note
185
+ if: cancelled()
186
+ run: |
187
+ echo "::warning::This run was cancelled while Terraform may have held the state lock. If the next run fails with 'Error acquiring the state lock', run terraform force-unlock <LOCK_ID> (the ID is printed in that error) inside ./terraform — or delete the .tflock object beside the state file in S3 — then re-run."
@@ -26,10 +26,11 @@ jobs:
26
26
  deploy:
27
27
  name: Build & Deploy
28
28
  runs-on: ubuntu-latest
29
+ timeout-minutes: 30
29
30
 
30
31
  steps:
31
32
  - name: Checkout Code
32
- uses: actions/checkout@v4
33
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
33
34
 
34
35
  # --- 1. IaC SECURITY SCAN ---
35
36
  - name: Scan Terraform for Misconfigurations
@@ -53,17 +54,34 @@ jobs:
53
54
  echo '```' >> $GITHUB_STEP_SUMMARY
54
55
  fi
55
56
 
56
- # --- 2. INFRASTRUCTURE SYNC (The New Marketplace Action) ---
57
+ # --- 2. AWS AUTH (job-level credentials for every step below) ---
58
+ - name: Configure AWS credentials
59
+ id: aws-creds
60
+ uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4
61
+ continue-on-error: true
62
+ with:
63
+ role-to-assume: arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role
64
+ aws-region: ${{ env.AWS_REGION }}
65
+
66
+ # Deploy never skips: a failed assume fails the run with the
67
+ # bootstrap pointer (BUG-201).
68
+ - name: Interpret credential failure
69
+ if: steps.aws-creds.outcome == 'failure'
70
+ run: |
71
+ echo "::error::AWS credential assumption failed — if the stack was never provisioned, bootstrap it first (npx grada-run apply); otherwise check terraform/oidc.tf trust."
72
+ exit 1
73
+
74
+ # --- 3. INFRASTRUCTURE SYNC (The New Marketplace Action) ---
57
75
  - name: Apply Infrastructure Changes
58
- uses: grada-run/grada-action@v1
76
+ uses: grada-run/grada-action@12227808ae4caafaec1041319645586a1132fc57 # v1
59
77
  with:
60
78
  aws-region: ${{ env.AWS_REGION }}
61
79
  role-to-assume: arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role
62
80
  terraform-dir: 'terraform'
63
81
 
64
- # --- 3. BUILD ---
82
+ # --- 4. BUILD ---
65
83
  - name: Setup Node.js
66
- uses: actions/setup-node@v4
84
+ uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
67
85
  with:
68
86
  node-version: '22'
69
87
  cache: 'npm'
@@ -73,7 +91,7 @@ jobs:
73
91
  npm ci
74
92
  npm run build
75
93
 
76
- # --- 4. DEPLOY ---
94
+ # --- 5. DEPLOY ---
77
95
  - name: Sync to S3
78
96
  run: |
79
97
  aws s3 sync "${{ env.BUILD_DIR }}/" "s3://${{ env.S3_BUCKET }}" --delete \
@@ -30,10 +30,11 @@ jobs:
30
30
  deploy:
31
31
  name: Build & Deploy
32
32
  runs-on: ubuntu-latest
33
+ timeout-minutes: 60
33
34
 
34
35
  steps:
35
36
  - name: Checkout Code
36
- uses: actions/checkout@v4
37
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
37
38
 
38
39
  # --- 1. IaC SECURITY SCAN ---
39
40
  - name: Scan Terraform for Misconfigurations
@@ -57,18 +58,39 @@ jobs:
57
58
  echo '```' >> $GITHUB_STEP_SUMMARY
58
59
  fi
59
60
 
60
- # --- 2. INFRASTRUCTURE SYNC (The New Marketplace Action) ---
61
- - name: Apply Infrastructure Changes
62
- uses: grada-run/grada-action@v1
61
+ # --- 2. AWS AUTH (job-level credentials for every step below) ---
62
+ - name: Configure AWS credentials
63
+ id: aws-creds
64
+ uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4
65
+ continue-on-error: true
63
66
  with:
64
- aws-region: ${{ env.AWS_REGION }}
65
67
  role-to-assume: arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role
66
- terraform-dir: 'terraform'
68
+ aws-region: ${{ env.AWS_REGION }}
67
69
 
68
- # --- 3. BUILD & PUSH ---
70
+ # Deploy never skips: a failed assume fails the run with the
71
+ # bootstrap pointer (BUG-138).
72
+ - name: Interpret credential failure
73
+ if: steps.aws-creds.outcome == 'failure'
74
+ run: |
75
+ echo "::error::AWS credential assumption failed — if the stack was never provisioned, bootstrap it first (npx grada-run apply); otherwise check terraform/oidc.tf trust."
76
+ exit 1
77
+
78
+ # --- 3. ECR BOOTSTRAP ---
79
+ # The image is pushed BEFORE the full apply (fresh stacks must never
80
+ # start tasks on an unpushed tag), but the repository itself is
81
+ # Terraform-managed — so it is bootstrapped with a targeted apply
82
+ # first. Idempotent on existing stacks.
83
+ - name: Bootstrap ECR repository
84
+ working-directory: ./terraform
85
+ run: |
86
+ terraform init -input=false
87
+ terraform workspace select default
88
+ terraform apply -target=aws_ecr_repository.app -auto-approve -input=false
89
+
90
+ # --- 4. BUILD ---
69
91
  - name: Login to Amazon ECR
70
92
  id: login-ecr
71
- uses: aws-actions/amazon-ecr-login@v2
93
+ uses: aws-actions/amazon-ecr-login@03f1aad4c6c7ffd436567f42f9384779290529bd # v2
72
94
 
73
95
  - name: Build Docker image
74
96
  id: build-image
@@ -80,8 +102,8 @@ jobs:
80
102
  docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$SHA_TAG .
81
103
  docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$SHA_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
82
104
 
83
- # --- 4. CONTAINER SECURITY SCAN ---
84
- - name: Scan Container for Vulnerabilities (SARIF Output)
105
+ # --- 5. CONTAINER SECURITY SCAN ---
106
+ - name: Scan Container for Vulnerabilities (table summary)
85
107
  uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
86
108
  with:
87
109
  image-ref: '${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest'
@@ -102,8 +124,9 @@ jobs:
102
124
  echo '```' >> $GITHUB_STEP_SUMMARY
103
125
  fi
104
126
 
105
- # --- 5. DEPLOY ---
127
+ # --- 6. PUSH ---
106
128
  - name: Push image to Amazon ECR
129
+ id: push
107
130
  env:
108
131
  ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
109
132
  IMAGE_TAG: latest
@@ -113,6 +136,18 @@ jobs:
113
136
  docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
114
137
  echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$SHA_TAG" >> $GITHUB_OUTPUT
115
138
 
139
+ # --- 7. INFRASTRUCTURE SYNC (The New Marketplace Action) ---
140
+ # Runs AFTER the push: by the time apply moves tasks onto `:latest`,
141
+ # the tag exists. A gate failure below can therefore never strand
142
+ # the service on an unpullable revision.
143
+ - name: Apply Infrastructure Changes
144
+ uses: grada-run/grada-action@12227808ae4caafaec1041319645586a1132fc57 # v1
145
+ with:
146
+ aws-region: ${{ env.AWS_REGION }}
147
+ role-to-assume: arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role
148
+ terraform-dir: 'terraform'
149
+
150
+ # --- 8. DEPLOY ---
116
151
  # Each code push registers a new task definition revision pinned to the
117
152
  # immutable SHA-tagged image, so `rollback` always has history to
118
153
  # return to (and `latest` is never overwritten in place as the deploy
@@ -145,6 +180,27 @@ jobs:
145
180
  --force-new-deployment \
146
181
  --region ${{ env.AWS_REGION }}
147
182
 
183
+ # update-service returns before the rollout finishes: wait for
184
+ # stability, then verify PRIMARY actually runs the registered
185
+ # revision — a circuit-breaker rollback re-stabilizes on the OLD
186
+ # revision, which the wait alone would report green.
187
+ - name: Wait for web rollout
188
+ run: |
189
+ aws ecs wait services-stable \
190
+ --cluster ${{ env.ECS_CLUSTER }} \
191
+ --services ${{ env.ECS_SERVICE }} \
192
+ --region ${{ env.AWS_REGION }}
193
+ PRIMARY_TD=$(aws ecs describe-services \
194
+ --cluster ${{ env.ECS_CLUSTER }} \
195
+ --services ${{ env.ECS_SERVICE }} \
196
+ --query 'services[0].deployments[?status==`PRIMARY`].taskDefinition' \
197
+ --output text \
198
+ --region ${{ env.AWS_REGION }})
199
+ if [ "$PRIMARY_TD" != "${{ steps.register-task-def.outputs.task-arn }}" ]; then
200
+ echo "Web rollout of ${{ steps.register-task-def.outputs.task-arn }} did not stick (PRIMARY runs $PRIMARY_TD) — the deployment failed or rolled back." >&2
201
+ exit 1
202
+ fi
203
+
148
204
  # The background worker ships the same image as web, so it gets the
149
205
  # same SHA-pinned revision treatment — otherwise it would run stale
150
206
  # code forever while web moves on. Skipped on workerless projects.
@@ -178,7 +234,25 @@ jobs:
178
234
  --force-new-deployment \
179
235
  --region ${{ env.AWS_REGION }}
180
236
 
181
- # --- 6. CACHE INVALIDATION ---
237
+ - name: Wait for worker rollout
238
+ if: hashFiles('terraform/worker.tf') != ''
239
+ run: |
240
+ aws ecs wait services-stable \
241
+ --cluster ${{ env.ECS_CLUSTER }} \
242
+ --services ${{ env.ECS_WORKER_SERVICE }} \
243
+ --region ${{ env.AWS_REGION }}
244
+ PRIMARY_TD=$(aws ecs describe-services \
245
+ --cluster ${{ env.ECS_CLUSTER }} \
246
+ --services ${{ env.ECS_WORKER_SERVICE }} \
247
+ --query 'services[0].deployments[?status==`PRIMARY`].taskDefinition' \
248
+ --output text \
249
+ --region ${{ env.AWS_REGION }})
250
+ if [ "$PRIMARY_TD" != "${{ steps.register-worker-task-def.outputs.task-arn }}" ]; then
251
+ echo "Worker rollout of ${{ steps.register-worker-task-def.outputs.task-arn }} did not stick (PRIMARY runs $PRIMARY_TD) — the deployment failed or rolled back." >&2
252
+ exit 1
253
+ fi
254
+
255
+ # --- 9. CACHE INVALIDATION ---
182
256
  # New code means new HTML: clear the CDN so deploys go live
183
257
  # immediately instead of serving stale pages until TTL expiry.
184
258
  - name: Invalidate CloudFront
@@ -194,4 +268,13 @@ jobs:
194
268
  aws cloudfront create-invalidation \
195
269
  --distribution-id "$DIST_ID" \
196
270
  --paths "/*" \
197
- --region ${{ env.AWS_REGION }}
271
+ --region ${{ env.AWS_REGION }}
272
+
273
+ # A cancelled apply/destroy can strand the S3 state lockfile: point
274
+ # at recovery instead of leaving the next run to fail obscurely
275
+ # (BUG-194). Generic by necessity — the lock ID only exists in the
276
+ # follow-up run's own error.
277
+ - name: Cancellation recovery note
278
+ if: cancelled()
279
+ run: |
280
+ echo "::warning::This run was cancelled while Terraform may have held the state lock. If the next run fails with 'Error acquiring the state lock', run terraform force-unlock <LOCK_ID> (the ID is printed in that error) inside ./terraform — or delete the .tflock object beside the state file in S3 — then re-run."
@@ -17,19 +17,32 @@ jobs:
17
17
  drift:
18
18
  name: Detect Terraform drift
19
19
  runs-on: ubuntu-latest
20
+ timeout-minutes: 30
20
21
 
21
22
  steps:
22
23
  - name: Checkout Code
23
- uses: actions/checkout@v4
24
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
24
25
 
25
26
  - name: Configure AWS Credentials
26
- uses: aws-actions/configure-aws-credentials@v4
27
+ id: aws-creds
28
+ uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4
29
+ continue-on-error: true
27
30
  with:
28
31
  role-to-assume: {{ROLE_ARN}}
29
32
  aws-region: ${{ env.AWS_REGION }}
30
33
 
34
+ # STS denies a missing role and a trust mismatch with the same
35
+ # message, so the API won't support distinguishing them: every
36
+ # assume failure skips loud (green) with both cases + pointers
37
+ # named (BUG-199).
38
+ - name: Interpret credential failure
39
+ if: steps.aws-creds.outcome == 'failure'
40
+ run: |
41
+ ROLE_ARN="{{ROLE_ARN}}"
42
+ echo "::notice::AWS credential assumption failed for $ROLE_ARN — skipping this run. Either the stack is absent (never provisioned or destroyed — re-bootstrap with: npx grada-run apply) or the OIDC trust does not cover this run (check terraform/oidc.tf)."
43
+
31
44
  - name: Setup Terraform
32
- uses: hashicorp/setup-terraform@v3
45
+ uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
33
46
  with:
34
47
  # The wrapper mangles -detailed-exitcode; raw codes (0/1/2) are the signal.
35
48
  terraform_wrapper: false
@@ -41,10 +54,11 @@ jobs:
41
54
  # -detailed-exitcode: 0 = no changes, 1 = error, 2 = drift detected.
42
55
  - name: Terraform Plan
43
56
  id: plan
57
+ if: steps.aws-creds.outcome == 'success'
44
58
  working-directory: ./terraform
45
59
  run: |
46
60
  set +e
47
- terraform plan -detailed-exitcode -no-color -out=tfplan > plan-full.txt 2>&1
61
+ terraform plan -input=false -detailed-exitcode -no-color -out=tfplan > plan-full.txt 2>&1
48
62
  EXITCODE=$?
49
63
  echo "exitcode=$EXITCODE" >> "$GITHUB_OUTPUT"
50
64
  if [ "$EXITCODE" != "1" ]; then
@@ -54,6 +68,9 @@ jobs:
54
68
  fi
55
69
  echo "### Drift plan (exit $EXITCODE)" >> "$GITHUB_STEP_SUMMARY"
56
70
  head -50 plan.txt >> "$GITHUB_STEP_SUMMARY"
71
+ # Exit 2 (drift) stays green — the issue below tracks it. Exit 1
72
+ # (plan ERROR) must fail the run instead of going green-silent.
73
+ if [ "$EXITCODE" = "1" ]; then exit 1; fi
57
74
 
58
75
  # A plan on never-applied infrastructure also exits 2 (everything
59
76
  # "to add") — that is not drift. Skip the issue/Slack alarm when
@@ -73,7 +90,7 @@ jobs:
73
90
 
74
91
  - name: Report drift as GitHub Issue
75
92
  if: (steps.plan.outputs.exitcode == '2' || steps.plan.outputs.exitcode == '0') && steps.state.outputs.empty != 'true'
76
- uses: actions/github-script@v7
93
+ uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
77
94
  with:
78
95
  script: |
79
96
  const fs = require('fs');
@@ -113,6 +130,52 @@ jobs:
113
130
  await github.rest.issues.createComment({ owner, repo, issue_number: existing.number, body: `✅ Drift resolved on \`${new Date().toISOString()}\` ([run](${runUrl})).` });
114
131
  await github.rest.issues.update({ owner, repo, issue_number: existing.number, state: 'closed' });
115
132
  }
133
+ // A 0/2 verdict means the check itself works: close any stale
134
+ // check-failure issue left by an earlier red run.
135
+ const { data: failed } = await github.rest.issues.listForRepo({ owner, repo, state: 'open', labels: 'iac-drift-check-failed' });
136
+ if (failed[0]) {
137
+ await github.rest.issues.createComment({ owner, repo, issue_number: failed[0].number, body: `✅ Drift check healthy again on \`${new Date().toISOString()}\` ([run](${runUrl})); closing.` });
138
+ await github.rest.issues.update({ owner, repo, issue_number: failed[0].number, state: 'closed' });
139
+ }
140
+
141
+ # Plan errors (exit 1) fail the run (see the plan step) AND leave a
142
+ # trackable issue under their own label — never green-silent.
143
+ - name: Report drift check failure as GitHub Issue
144
+ if: failure() && steps.plan.outputs.exitcode == '1'
145
+ uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
146
+ with:
147
+ script: |
148
+ const fs = require('fs');
149
+ const { owner, repo } = context.repo;
150
+ const label = 'iac-drift-check-failed';
151
+ const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${context.runId}`;
152
+ let diff = '';
153
+ try {
154
+ diff = fs.readFileSync('terraform/plan.txt', 'utf8');
155
+ } catch (error) {
156
+ diff = '(plan output unavailable)';
157
+ }
158
+ if (diff.length > 30000) {
159
+ diff = `${diff.slice(0, 30000)}\n... (truncated, see ${runUrl})`;
160
+ }
161
+ try {
162
+ await github.rest.issues.getLabel({ owner, repo, name: label });
163
+ } catch (error) {
164
+ if (error.status === 404) {
165
+ await github.rest.issues.createLabel({ owner, repo, name: label, color: 'd93f0b', description: 'Terraform drift check itself errored (plan exit 1)' });
166
+ } else {
167
+ throw error;
168
+ }
169
+ }
170
+ const { data: open } = await github.rest.issues.listForRepo({ owner, repo, state: 'open', labels: label });
171
+ const existing = open[0];
172
+ const body = `## ❌ Drift Check Failed\n\nThe scheduled drift check errored on \`${new Date().toISOString()}\` ([workflow run](${runUrl})) — this is a check failure, not drift.\n\n\`\`\`terraform\n${diff}\n\`\`\`\n\nFix the check (credentials, backend, syntax) and the issue closes on the next green run.`;
173
+ if (existing) {
174
+ await github.rest.issues.createComment({ owner, repo, issue_number: existing.number, body: `Check still failing on \`${new Date().toISOString()}\` ([run](${runUrl})).\n\n\`\`\`terraform\n${diff}\n\`\`\`` });
175
+ await github.rest.issues.update({ owner, repo, issue_number: existing.number, body });
176
+ } else {
177
+ await github.rest.issues.create({ owner, repo, title: '❌ IaC Drift Check Failed', labels: [label], body });
178
+ }
116
179
 
117
180
  - name: Notify Slack
118
181
  if: steps.plan.outputs.exitcode == '2' && steps.state.outputs.empty != 'true'