Multiplayer agent harness for work.
Notify deployments when main goes green (#2049)
Regan Bellfa061d3dfd25
diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.ymlindex ec9ba13cb..9bc6577dc 100644--- a/.github/workflows/cicd.yml+++ b/.github/workflows/cicd.yml@@ -460,3 +460,36 @@ jobs:run: |test "$(git rev-parse HEAD)" = "$GITHUB_SHA"printf 'QM_CI_TREE={"sha":"%s","tree":"%s","runId":%s,"attempt":%s,"pr":%s}\n' "$GITHUB_SHA" "$(git rev-parse HEAD^{tree})" "$GITHUB_RUN_ID" "$GITHUB_RUN_ATTEMPT" "$PR_NUMBER"++ notify-deployments:+ name: Notify deployments of green main+ timeout-minutes: 3+ continue-on-error: true+ if: always() && !cancelled() && github.event_name == 'push' && github.ref == 'refs/heads/main'+ needs: [core, cli, lint, core-postgres, admin-plugin, web-ui-plugin, auth-plugin, portal-plugin]+ runs-on: ubuntu-latest+ permissions: {}+ steps:+ - name: Deliver the signed green-main receipt+ env:+ CHECKS: ${{ toJSON(needs) }}+ WEBHOOK_URL: ${{ secrets.QM_GREEN_MAIN_WEBHOOK_URL }}+ WEBHOOK_SECRET: ${{ secrets.QM_GREEN_MAIN_WEBHOOK_SECRET }}+ run: |+ test "$(jq -r '[.[] | .result] | all(. == "success")' <<<"$CHECKS")" = true+ if test -z "$WEBHOOK_URL" || test -z "$WEBHOOK_SECRET"; then+ echo "no deployment webhook configured"+ exit 0+ fi+ body="$(jq -cn --arg sha "$GITHUB_SHA" --argjson run "$GITHUB_RUN_ID" --argjson attempt "$GITHUB_RUN_ATTEMPT" \+ '{event: "main_green", repository: "yc-software/qm", sha: $sha, run_id: $run, attempt: $attempt}')"+ signature="$(printf '%s' "$body" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" -r | cut -d' ' -f1)"+ status="$(curl -s -o /dev/null -w '%{http_code}' --max-time 20 \+ -H 'content-type: application/json' \+ -H 'x-github-event: push' \+ -H "x-hub-signature-256: sha256=$signature" \+ --data "$body" "$WEBHOOK_URL" || true)"+ case "$status" in+ 2*) echo "deployment webhook responded $status" ;;+ *) echo "::warning::deployment webhook responded ${status:-000}; downstream will fall back to polling" ;;+ esacdiff --git a/test/ci-reuse.test.ts b/test/ci-reuse.test.tsindex 863ae1bff..afe1fe0ce 100644--- a/test/ci-reuse.test.ts+++ b/test/ci-reuse.test.ts@@ -295,7 +295,7 @@ test("all quality jobs keep successful names and missing proof runs full checks"assert.ok(jobs.core!.includes('test "$TYPECHECK" = success && test "$TESTS" = success'));const names: string[] = [];for (const [id, block] of Object.entries(jobs)) {- if (["reuse", "certify"].includes(id)) continue;+ if (["reuse", "certify", "notify-deployments"].includes(id)) continue;const name = block.match(/^ {4}name: (.+)$/m)![1]!;if (id === "core-tests") names.push(...[1, 2, 3, 4, 5].map((n) => name.replace("${{ matrix.shard }}", String(n))));else names.push(name);@@ -311,6 +311,22 @@ test("all quality jobs keep successful names and missing proof runs full checks"assert.ok(jobs.reuse!.includes("if: github.event_name == 'push' && github.ref == 'refs/heads/main'"));});+test("deployment notice fires only for a fully green main push and holds no repository access", () => {+ const job = jobs["notify-deployments"]!;+ assert.ok(+ job.includes("if: always() && !cancelled() && github.event_name == 'push' && github.ref == 'refs/heads/main'"),+ );+ assert.ok(+ job.includes("needs: [core, cli, lint, core-postgres, admin-plugin, web-ui-plugin, auth-plugin, portal-plugin]"),+ );+ assert.ok(job.includes("permissions: {}"));+ assert.ok(job.includes("continue-on-error: true"));+ assert.ok(!job.includes("exit 1"));+ assert.ok(job.includes(`all(. == "success")`));+ assert.equal([...job.matchAll(/^ {6}- /gm)].length, 1);+ assert.ok(!job.includes("uses: actions/checkout"));+});+test("receipt is an isolated immutable checkout with no secrets, artifacts, caches or repository scripts", () => {const job = jobs.certify!;assert.ok(job.includes("continue-on-error: true"));