@@ -17,10 +17,13 @@ permissions:
1717 pull-requests : read
1818
1919jobs :
20+ # Workflow design note:
21+ # - Non-Dependabot PRs run standard quality gates directly.
22+ # - Dependabot PRs may receive an auto-fix commit first (locks/docs/dependabot config),
23+ # then quality gates run on the refreshed commit in the next workflow run.
2024 # Dependabot PRs should run core validation checks (metadata, coding standards, validation tests).
2125 # Only advisory commit-message style checks remain human-focused.
2226 metadata :
23- if : github.event.pull_request.draft == false
2427 name : " Set Metadata"
2528 runs-on : ubuntu-latest
2629 timeout-minutes : 1
5659 dependabot-auto-fix-terraform :
5760 name : " Dependabot auto-fix Terraform docs/locks"
5861 needs : [metadata]
62+ # Restrict auto-fix writes to Dependabot branches in the same repository.
63+ # Fork PRs are excluded to avoid unsafe write operations.
5964 if : >-
6065 github.event.pull_request.draft == false &&
6166 github.actor == 'dependabot[bot]' &&
@@ -85,18 +90,21 @@ jobs:
8590 - name : " Upgrade Terraform locks and run regeneration hooks"
8691 shell : bash
8792 run : |
93+ # Compare PR head against base to find modules with provider constraint changes.
8894 base_sha="${{ github.event.pull_request.base.sha }}"
8995
9096 mapfile -t modules_to_upgrade < <(
9197 git diff --name-only "$base_sha...HEAD" \
9298 | grep '^infrastructure/modules/.*/versions\.tf$' \
99+ # -r avoids calling dirname with empty stdin when grep finds no matches.
93100 | xargs -r -n1 dirname \
94101 | sort -u
95102 )
96103
97104 if [[ ${#modules_to_upgrade[@]} -gt 0 ]]; then
98105 for module_path in "${modules_to_upgrade[@]}"; do
99106 echo "Upgrading Terraform lock file for $module_path"
107+ # init -upgrade refreshes provider selection; providers lock writes platform hashes.
100108 terraform -chdir="$module_path" init -upgrade -no-color
101109 terraform -chdir="$module_path" providers lock \
102110 -platform=linux_arm64 \
@@ -109,6 +117,8 @@ jobs:
109117 echo "No module versions.tf changes detected; skipping explicit lock upgrade loop."
110118 fi
111119
120+ # terraform_docs intentionally exits non-zero when it rewrites docs.
121+ # Keep running so changes can be detected and committed in this job.
112122 mise x -- pre-commit run --all-files generate-terraform-providers
113123 mise x -- pre-commit run --all-files terraform_providers_lock
114124 mise x -- pre-commit run --all-files terraform_docs || true
@@ -118,13 +128,15 @@ jobs:
118128 id : detect
119129 shell : bash
120130 run : |
131+ # Expose whether any auto-fix output changed tracked files.
121132 if git diff --quiet; then
122133 echo "changed=false" >> "$GITHUB_OUTPUT"
123134 else
124135 echo "changed=true" >> "$GITHUB_OUTPUT"
125136 fi
126137
127138 - name : " Commit and push auto-fixes"
139+ # Push an auto-fix commit so the next PR workflow run validates the refreshed content.
128140 if : steps.detect.outputs.changed == 'true'
129141 shell : bash
130142 run : |
@@ -184,7 +196,21 @@ jobs:
184196 coding-standards : # Recommended maximum execution time is 5 minutes
185197 name : " Enforce Coding Standards"
186198 needs : [metadata, dependabot-auto-fix-terraform]
187- if : github.event.pull_request.draft == false && needs.dependabot-auto-fix-terraform.outputs.changed != 'true'
199+ # Condition intent:
200+ # - Always require successful metadata.
201+ # - For non-Dependabot PRs: run normally.
202+ # - For Dependabot PRs: run only when auto-fix ran successfully and produced no new commit
203+ # (if it produced changes, this run is skipped and the next run validates the new commit).
204+ if : >-
205+ always() &&
206+ needs.metadata.result == 'success' &&
207+ (
208+ github.actor != 'dependabot[bot]' ||
209+ (
210+ needs.dependabot-auto-fix-terraform.result == 'success' &&
211+ needs.dependabot-auto-fix-terraform.outputs.changed != 'true'
212+ )
213+ )
188214 uses : ./.github/workflows/stage-1-coding-standards.yaml
189215 with :
190216 build_datetime : " ${{ needs.metadata.outputs.build_datetime }}"
@@ -199,7 +225,7 @@ jobs:
199225 conventional-commit-advisory :
200226 name : " Conventional Commit Advisory"
201227 # Bot PR commit formats are tool-generated and non-blocking by design.
202- if : github.event.pull_request.draft == false && github. actor != 'dependabot[bot]'
228+ if : github.actor != 'dependabot[bot]'
203229 runs-on : ubuntu-latest
204230 timeout-minutes : 2
205231 steps :
@@ -259,7 +285,17 @@ jobs:
259285 validation-tests :
260286 name : " Validation Tests"
261287 needs : [metadata, dependabot-auto-fix-terraform]
262- if : github.event.pull_request.draft == false && needs.dependabot-auto-fix-terraform.outputs.changed != 'true'
288+ # Mirrors coding-standards gating to avoid validating stale pre-auto-fix content.
289+ if : >-
290+ always() &&
291+ needs.metadata.result == 'success' &&
292+ (
293+ github.actor != 'dependabot[bot]' ||
294+ (
295+ needs.dependabot-auto-fix-terraform.result == 'success' &&
296+ needs.dependabot-auto-fix-terraform.outputs.changed != 'true'
297+ )
298+ )
263299 runs-on : ubuntu-latest
264300 timeout-minutes : 5
265301 steps :
0 commit comments