Skip to content

Commit fdda08d

Browse files
committed
Address latest cpflow flow review updates
1 parent dbcb1c8 commit fdda08d

6 files changed

Lines changed: 50 additions & 11 deletions

File tree

.github/actions/cpflow-delete-control-plane-app/delete-app.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ if [[ "$APP_NAME" != "${expected_prefix}"* ]]; then
1414
exit 1
1515
fi
1616

17-
# Guard against a misconfigured REVIEW_APP_PREFIX that would otherwise match
18-
# a well-known shared environment.
17+
# Guard against a misconfigured REVIEW_APP_PREFIX that would otherwise match a
18+
# well-known shared environment. This intentionally rejects review-app prefixes
19+
# containing these word segments; failing closed is safer for deletion.
1920
if echo "$APP_NAME" | grep -iqE '(^|-)(production|staging)(-|$)'; then
2021
echo "❌ ERROR: refusing to delete an app whose name contains 'production' or 'staging'" >&2
2122
echo "App name: $APP_NAME" >&2

.github/actions/cpflow-validate-config/action.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ description: >-
44
proceeds. Pass each value via `env:` with the same NAME as the secret or variable,
55
then list the required entries in `required` as `type:NAME` pairs (type is `secret`
66
or `variable`). When `pull_request_friendly: true` and the current event is a
7-
`pull_request`, missing config writes a step summary and exits 0 with `ready=false`
8-
instead of failing the job.
7+
pull request event, missing config writes a step summary and exits 0 with
8+
`ready=false` instead of failing the job.
99
1010
inputs:
1111
required:
@@ -14,7 +14,7 @@ inputs:
1414
caller MUST export the matching values via `env:` using the same NAME.
1515
required: true
1616
pull_request_friendly:
17-
description: When "true" and event is pull_request, write summary and exit 0 with ready=false.
17+
description: When "true" and event is pull_request/pull_request_target, write summary and exit 0 with ready=false.
1818
required: false
1919
default: "false"
2020

@@ -58,7 +58,7 @@ runs:
5858
exit 0
5959
fi
6060
61-
if [[ "${CPFLOW_PR_FRIENDLY}" == "true" && "${CPFLOW_EVENT_NAME}" == "pull_request" ]]; then
61+
if [[ "${CPFLOW_PR_FRIENDLY}" == "true" && ( "${CPFLOW_EVENT_NAME}" == "pull_request" || "${CPFLOW_EVENT_NAME}" == "pull_request_target" ) ]]; then
6262
echo "ready=false" >> "$GITHUB_OUTPUT"
6363
{
6464
echo "Control Plane review app automation is not configured yet."

.github/workflows/cpflow-cleanup-stale-review-apps.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ jobs:
5252
run: |
5353
set -euo pipefail
5454
cpflow cleanup-stale-apps -a "${REVIEW_APP_PREFIX}" --org "${CPLN_ORG_STAGING}" --yes
55+
echo "Stale review apps under prefix '${REVIEW_APP_PREFIX}' have been cleaned up." >> "$GITHUB_STEP_SUMMARY"

.github/workflows/cpflow-delete-review-app.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414

1515
permissions:
1616
contents: read
17+
deployments: write
1718
issues: write
1819
pull-requests: write
1920

@@ -46,7 +47,8 @@ jobs:
4647
# comments. This checkout is safe because it does not set `ref:`; GitHub checks
4748
# out the base branch's trusted workflow code, not the fork head. Do not add
4849
# `ref: ${{ github.event.pull_request.head.sha }}` here without re-evaluating
49-
# the trust boundary.
50+
# the trust boundary. All local composite actions below are therefore loaded from
51+
# trusted base-branch code; keep them that way when changing this workflow.
5052
- name: Checkout repository
5153
uses: actions/checkout@v4
5254

@@ -61,6 +63,7 @@ jobs:
6163
secret:CPLN_TOKEN_STAGING
6264
variable:CPLN_ORG_STAGING
6365
variable:REVIEW_APP_PREFIX
66+
pull_request_friendly: "true"
6467

6568
- name: Setup environment
6669
uses: ./.github/actions/cpflow-setup-environment
@@ -101,6 +104,33 @@ jobs:
101104
cpln_org: ${{ vars.CPLN_ORG_STAGING }}
102105
review_app_prefix: ${{ vars.REVIEW_APP_PREFIX }}
103106

107+
- name: Mark GitHub deployment inactive
108+
uses: actions/github-script@v7
109+
with:
110+
script: |
111+
const environment = `review/${process.env.APP_NAME}`;
112+
const deployments = await github.paginate(github.rest.repos.listDeployments, {
113+
owner: context.repo.owner,
114+
repo: context.repo.repo,
115+
environment,
116+
per_page: 100
117+
});
118+
119+
if (deployments.length === 0) {
120+
core.info(`No GitHub deployments found for ${environment}.`);
121+
return;
122+
}
123+
124+
for (const deployment of deployments) {
125+
await github.rest.repos.createDeploymentStatus({
126+
owner: context.repo.owner,
127+
repo: context.repo.repo,
128+
deployment_id: deployment.id,
129+
state: "inactive",
130+
description: `Review app ${process.env.APP_NAME} was deleted`
131+
});
132+
}
133+
104134
- name: Finalize delete status
105135
if: always()
106136
uses: actions/github-script@v7

.github/workflows/cpflow-deploy-staging.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292

9393
deploy:
9494
needs: [validate-branch, build]
95-
if: needs.validate-branch.outputs.is_deployable == 'true'
95+
if: needs.validate-branch.outputs.is_deployable == 'true' && needs.build.result == 'success'
9696
runs-on: ubuntu-latest
9797
timeout-minutes: 30
9898
steps:

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ jobs:
148148
staging_vars="$(CPLN_TOKEN="${CPLN_TOKEN_STAGING}" cpln gvc get "${STAGING_APP_NAME}" --org "${CPLN_ORG_STAGING}" -o json | jq -r '.spec.env // [] | .[].name' | sort)"
149149
production_vars="$(CPLN_TOKEN="${CPLN_TOKEN_PRODUCTION}" cpln gvc get "${PRODUCTION_APP_NAME}" --org "${CPLN_ORG_PRODUCTION}" -o json | jq -r '.spec.env // [] | .[].name' | sort)"
150150
151+
{
152+
echo "### Environment parity scope"
153+
echo "This check compares GVC-level environment variable names only."
154+
echo "Workload-level env vars and cpln:// secret references are not compared."
155+
echo
156+
} >> "$GITHUB_STEP_SUMMARY"
157+
151158
if [[ -z "${staging_vars}" ]]; then
152159
echo "Staging GVC exposes no environment variables; skipping parity check."
153160
exit 0
@@ -191,9 +198,9 @@ jobs:
191198
[[ -n "${workload_name}" ]] || continue
192199
193200
workload_json="$(cpln workload get "${workload_name}" --gvc "${PRODUCTION_APP_NAME}" --org "${CPLN_ORG_PRODUCTION}" -o json)"
194-
# current_image/current_version are summary fields for the first container
195-
# of the selected workload; rollback_state below captures all containers.
196-
workload_image="$(echo "${workload_json}" | jq -r '.spec.containers[0].image')"
201+
# current_image/current_version are summary fields for the first container
202+
# of the selected workload; rollback_state below captures all containers.
203+
workload_image="$(echo "${workload_json}" | jq -r '.spec.containers[0].image')"
197204
workload_containers="$(echo "${workload_json}" | jq -c '.spec.containers | map({name, image})')"
198205
workload_version="$(echo "${workload_json}" | jq -r '.version')"
199206

0 commit comments

Comments
 (0)