From 38a46de56fa23c13210cbb9c297f380b8012addc Mon Sep 17 00:00:00 2001 From: Lucas Koontz Date: Mon, 2 Nov 2026 01:15:53 -0800 Subject: [PATCH] fix(argocd-pr-env-deploy): leave customer-labeled PRs to an admin (ENG-3919) --- argocd-pr-env-deploy/action.yml | 11 +++++++++++ tests/test_argocd_pr_env_deploy.py | 31 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/argocd-pr-env-deploy/action.yml b/argocd-pr-env-deploy/action.yml index feeedbf..ba8eae8 100644 --- a/argocd-pr-env-deploy/action.yml +++ b/argocd-pr-env-deploy/action.yml @@ -32,6 +32,9 @@ # fetches the parent chart from. `--revision` is passed on every # deploy, defaulting to `main`, so dropping the line resets the parent # (the AppSet's ignoreApplicationDifferences no longer reverts it). +# - A PR labeled `customer:` deploys nothing. An admin deploys +# customer envs, and the Argo CD token this action holds can only read +# their parents. # # Linked-PR image tags resolve in order: # 1. `development-head-` — pushed by build-push-ecr's PR @@ -247,6 +250,14 @@ runs: PR_BODY="$(jq -r '.body // ""' <<<"$PR_JSON" | tr -d '\r')" LABEL_HOST="$(jq -r '[.labels[].name | select(startswith("customer:")) | ltrimstr("customer:")] | first // ""' <<<"$PR_JSON")" + # An admin deploys a customer env, pinning its parent to a reviewed + # argocd-envs commit. This action's token can read that parent but not + # change it, so a customer-labeled PR sets nothing here. + if [ -n "$LABEL_HOST" ]; then + echo "::notice::This PR carries customer:${LABEL_HOST}. An admin deploys customer envs, so this job changes nothing in Argo CD." + exit 0 + fi + # Lint: `Deploys:`-looking lines that don't match the strict form # would otherwise be silently ignored and the env would quietly run # defaults — the classic offender is a pasted PR URL. Warn per line. diff --git a/tests/test_argocd_pr_env_deploy.py b/tests/test_argocd_pr_env_deploy.py index 4b8fcde..c53ef5e 100644 --- a/tests/test_argocd_pr_env_deploy.py +++ b/tests/test_argocd_pr_env_deploy.py @@ -208,3 +208,34 @@ def test_does_nothing_before_the_parent_exists(self, tmp_path): def test_the_switch_off_runs_after_reading_the_parent_and_before_app_set(): assert RUN.index(PARENT_GET_CALL) < RUN.index(STAFF_OFF_START) < RUN.index(APP_SET_CALL) + + +CUSTOMER_SKIP_START = 'LABEL_HOST="$(jq' +CUSTOMER_SKIP_END = "\n\n# Lint: `Deploys:`-looking lines" + + +def run_customer_skip(labels): + """Run the action from reading the PR's labels through the customer check.""" + segment = RUN[RUN.index(CUSTOMER_SKIP_START):RUN.index(CUSTOMER_SKIP_END)] + pr_json = '{"labels": [' + ", ".join(f'{{"name": "{name}"}}' for name in labels) + "]}" + script = f'PR_JSON="$1"\n{segment}\necho "went on to argocd"' + return subprocess.run(["bash", "-c", script, "_", pr_json], capture_output=True, text=True) + + +class TestCustomerEnvs: + def test_a_customer_labeled_pr_stops_before_argocd(self): + result = run_customer_skip(["deploy", "customer:acme"]) + assert result.returncode == 0 + assert "::notice::This PR carries customer:acme. An admin deploys customer envs" in result.stdout + assert "went on to argocd" not in result.stdout + + def test_an_ordinary_pr_goes_on(self): + result = run_customer_skip(["deploy"]) + assert result.returncode == 0 + assert "went on to argocd" in result.stdout + + +def test_the_customer_check_runs_before_any_argocd_call(): + skip = RUN.index('if [ -n "$LABEL_HOST" ]; then') + assert skip < RUN.index(PARENT_GET_CALL) < RUN.index(APP_SET_CALL) + assert skip < RUN.index('"$ARGOCD_BIN"')