Skip to content

Commit 68a4a6c

Browse files
committed
Tighten production promotion review fixes
1 parent a7a1005 commit 68a4a6c

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

.github/workflows/cpflow-promote-staging-to-production.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ jobs:
245245
selected_version=""
246246
rollback_state='{}'
247247
248+
# Validate all workloads have images, then promote the primary workload's
249+
# image as the canonical image for this GVC.
248250
while IFS= read -r workload_name; do
249251
[[ -n "${workload_name}" ]] || continue
250252
@@ -372,7 +374,7 @@ jobs:
372374
accepted_statuses: ${{ env.HEALTH_CHECK_ACCEPTED_STATUSES }}
373375

374376
- name: Roll back on failure
375-
if: failure() && steps.capture-current.outputs.rollback_state != '' && steps.capture-current.outputs.rollback_state != '{}'
377+
if: failure() && steps.capture-current.outcome == 'success'
376378
env:
377379
ROLLBACK_STATE: ${{ steps.capture-current.outputs.rollback_state }}
378380
PRODUCTION_APP_NAME: ${{ vars.PRODUCTION_APP_NAME }}
@@ -439,7 +441,7 @@ jobs:
439441
fi
440442
441443
- name: Wait for rollback readiness
442-
if: failure() && steps.capture-current.outputs.rollback_state != '' && steps.capture-current.outputs.rollback_state != '{}'
444+
if: failure() && steps.capture-current.outcome == 'success'
443445
env:
444446
ROLLBACK_STATE: ${{ steps.capture-current.outputs.rollback_state }}
445447
PRODUCTION_APP_NAME: ${{ vars.PRODUCTION_APP_NAME }}
@@ -462,6 +464,7 @@ jobs:
462464
pids=()
463465
for workload_name in "${workloads[@]}"; do
464466
[[ -n "${workload_name}" ]] || continue
467+
status_name="${workload_name//\//_}"
465468
466469
echo "Polling rollback readiness for workload '${workload_name}'..."
467470
(
@@ -480,9 +483,9 @@ jobs:
480483
done
481484
482485
if [[ "${ready}" == "true" ]]; then
483-
printf 'ready\n' > "${status_dir}/${workload_name}"
486+
printf 'ready\n' > "${status_dir}/${status_name}"
484487
else
485-
printf 'not_ready\n' > "${status_dir}/${workload_name}"
488+
printf 'not_ready\n' > "${status_dir}/${status_name}"
486489
fi
487490
) &
488491
pids+=("$!")
@@ -498,7 +501,8 @@ jobs:
498501
499502
for workload_name in "${workloads[@]}"; do
500503
[[ -n "${workload_name}" ]] || continue
501-
status_file="${status_dir}/${workload_name}"
504+
status_name="${workload_name//\//_}"
505+
status_file="${status_dir}/${status_name}"
502506
if [[ ! -f "${status_file}" ]] || [[ "$(<"${status_file}")" != "ready" ]]; then
503507
echo "::warning::Workload '${workload_name}' did not report ready after rollback."
504508
fi
@@ -510,6 +514,7 @@ jobs:
510514
HEALTHY: ${{ steps.health-check.outputs.healthy }}
511515
PREVIOUS_IMAGE: ${{ steps.capture-current.outputs.current_image }}
512516
PREVIOUS_VERSION: ${{ steps.capture-current.outputs.current_version }}
517+
DEPLOYED_IMAGE: ${{ steps.staging-image.outputs.image }}
513518
shell: bash
514519
run: |
515520
{
@@ -523,6 +528,7 @@ jobs:
523528
echo
524529
echo "Previous image: \`${PREVIOUS_IMAGE}\`"
525530
echo "Previous version: ${PREVIOUS_VERSION}"
531+
echo "Deployed image: \`${DEPLOYED_IMAGE}\`"
526532
} >> "$GITHUB_STEP_SUMMARY"
527533
528534
create-github-release:

bin/test-cpflow-github-flow

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ruby <<'RUBY'
4343
require "yaml"
4444
4545
CONTROL_PLANE_FLOW_WORKFLOW = %r{\Ashakacode/control-plane-flow/\.github/workflows/[^@\s]+@([^\s]+)\z}
46-
PROMOTE_WORKFLOW = %r{\Ashakacode/control-plane-flow/\.github/workflows/cpflow-promote-staging-to-production\.yml@[^\s]+\z}
46+
PROMOTE_WORKFLOW = %r{\Ashakacode/control-plane-flow/\.github/workflows/cpflow-promote-staging-to-production\.yml@([^\s]+)\z}
4747
EXPECTED_CPFLOW_CHECKOUT_ACTION = "actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd"
4848
EXPECTED_CPFLOW_CHECKOUT_REPOSITORY = "shakacode/control-plane-flow"
4949
@@ -82,7 +82,11 @@ end
8282
8383
promote_path = ".github/workflows/cpflow-promote-staging-to-production.yml"
8484
promote_doc = YAML.load_file(promote_path, aliases: true)
85-
promote_job = promote_doc.fetch("jobs", {}).fetch("promote-to-production")
85+
promote_job = promote_doc.fetch("jobs", {})["promote-to-production"]
86+
87+
unless promote_job
88+
abort "#{promote_path}:promote-to-production job is missing"
89+
end
8690
8791
if promote_job.key?("uses")
8892
abort "#{promote_path}:promote-to-production must run as a normal caller-repo job, not a reusable workflow, so GitHub can expose production environment secrets"
@@ -116,6 +120,21 @@ end
116120
117121
refs[checkout_ref] << "#{promote_path}:promote-to-production"
118122
123+
setup_step = Array(promote_job["steps"]).find { |step| step["name"] == "Setup production environment" }
124+
125+
unless setup_step
126+
abort "#{promote_path}:promote-to-production must include a Setup production environment step"
127+
end
128+
129+
setup_ref = setup_step.fetch("with", {})["control_plane_flow_ref"]
130+
setup_match = setup_ref.to_s.match(PROMOTE_WORKFLOW)
131+
132+
unless setup_match
133+
abort "#{promote_path}:promote-to-production must pass a pinned production control_plane_flow_ref to setup"
134+
end
135+
136+
refs[setup_match[1]] << "#{promote_path}:promote-to-production setup"
137+
119138
if refs.empty?
120139
puts "no upstream cpflow reusable workflow refs found"
121140
elsif refs.length > 1

0 commit comments

Comments
 (0)