diff --git a/.github/workflows/openclaw-npm-release.yml b/.github/workflows/openclaw-npm-release.yml index f9426853fbc..f4fcc08f709 100644 --- a/.github/workflows/openclaw-npm-release.yml +++ b/.github/workflows/openclaw-npm-release.yml @@ -429,12 +429,13 @@ jobs: echo "Direct OpenClaw npm publish; relying on this workflow's npm-release environment approval." exit 0 fi + direct_recovery=false if [[ "${GITHUB_ACTOR}" != "github-actions[bot]" ]]; then - echo "OpenClaw npm publish must be dispatched by the OpenClaw Release Publish workflow, not directly by ${GITHUB_ACTOR}." >&2 - exit 1 + direct_recovery=true + echo "Direct OpenClaw npm recovery with release_publish_run_id; relying on this workflow's npm-release environment approval." fi RUN_JSON="$(gh run view "$RELEASE_PUBLISH_RUN_ID" --repo "$GITHUB_REPOSITORY" --json workflowName,headBranch,event,status,conclusion,url)" - printf '%s' "$RUN_JSON" | node -e 'const fs = require("node:fs"); const run = JSON.parse(fs.readFileSync(0, "utf8")); const checks = [["workflowName", "OpenClaw Release Publish"], ["headBranch", process.env.EXPECTED_WORKFLOW_BRANCH], ["event", "workflow_dispatch"]]; for (const [key, expected] of checks) { if (run[key] !== expected) { console.error(`Referenced release publish run ${process.env.RELEASE_PUBLISH_RUN_ID} must have ${key}=${expected}, got ${run[key] ?? ""}.`); process.exit(1); } } if (run.status !== "in_progress") { console.error(`Referenced release publish run ${process.env.RELEASE_PUBLISH_RUN_ID} must still be in_progress, got ${run.status ?? ""}.`); process.exit(1); } if (run.conclusion) { console.error(`Referenced release publish run ${process.env.RELEASE_PUBLISH_RUN_ID} already concluded ${run.conclusion}.`); process.exit(1); } console.log(`Using release publish approval run ${process.env.RELEASE_PUBLISH_RUN_ID}: ${run.url}`);' + printf '%s' "$RUN_JSON" | DIRECT_RELEASE_RECOVERY="${direct_recovery}" node scripts/validate-release-publish-approval.mjs publish_openclaw_npm: # KEEP THE REAL RELEASE/PUBLISH PATH ON A GITHUB-HOSTED RUNNER. diff --git a/.github/workflows/plugin-clawhub-release.yml b/.github/workflows/plugin-clawhub-release.yml index 44127618174..5623da2ced3 100644 --- a/.github/workflows/plugin-clawhub-release.yml +++ b/.github/workflows/plugin-clawhub-release.yml @@ -222,12 +222,13 @@ jobs: echo "Direct Plugin ClawHub Release dispatch; relying on this workflow's clawhub-plugin-release environment approval." exit 0 fi + direct_recovery=false if [[ "${GITHUB_ACTOR}" != "github-actions[bot]" ]]; then - echo "Plugin ClawHub publish must be dispatched by the OpenClaw Release Publish workflow, not directly by ${GITHUB_ACTOR}." >&2 - exit 1 + direct_recovery=true + echo "Direct Plugin ClawHub Release recovery with release_publish_run_id; relying on this workflow's clawhub-plugin-release environment approval." fi RUN_JSON="$(gh run view "$RELEASE_PUBLISH_RUN_ID" --repo "$GITHUB_REPOSITORY" --json workflowName,headBranch,event,status,conclusion,url)" - printf '%s' "$RUN_JSON" | node -e 'const fs = require("node:fs"); const run = JSON.parse(fs.readFileSync(0, "utf8")); const checks = [["workflowName", "OpenClaw Release Publish"], ["headBranch", process.env.EXPECTED_WORKFLOW_BRANCH], ["event", "workflow_dispatch"]]; for (const [key, expected] of checks) { if (run[key] !== expected) { console.error(`Referenced release publish run ${process.env.RELEASE_PUBLISH_RUN_ID} must have ${key}=${expected}, got ${run[key] ?? ""}.`); process.exit(1); } } if (run.status !== "in_progress") { console.error(`Referenced release publish run ${process.env.RELEASE_PUBLISH_RUN_ID} must still be in_progress, got ${run.status ?? ""}.`); process.exit(1); } if (run.conclusion) { console.error(`Referenced release publish run ${process.env.RELEASE_PUBLISH_RUN_ID} already concluded ${run.conclusion}.`); process.exit(1); } console.log(`Using release publish approval run ${process.env.RELEASE_PUBLISH_RUN_ID}: ${run.url}`);' + printf '%s' "$RUN_JSON" | DIRECT_RELEASE_RECOVERY="${direct_recovery}" node scripts/validate-release-publish-approval.mjs preview_plugin_pack: needs: preview_plugins_clawhub diff --git a/.github/workflows/plugin-npm-release.yml b/.github/workflows/plugin-npm-release.yml index 2e380083430..07c4fd56edc 100644 --- a/.github/workflows/plugin-npm-release.yml +++ b/.github/workflows/plugin-npm-release.yml @@ -199,12 +199,13 @@ jobs: echo "Direct Plugin NPM Release dispatch; relying on this workflow's npm-release environment approval." exit 0 fi + direct_recovery=false if [[ "${GITHUB_ACTOR}" != "github-actions[bot]" ]]; then - echo "Plugin npm publish must be dispatched by the OpenClaw Release Publish workflow, not directly by ${GITHUB_ACTOR}." >&2 - exit 1 + direct_recovery=true + echo "Direct Plugin NPM Release recovery with release_publish_run_id; relying on this workflow's npm-release environment approval." fi RUN_JSON="$(gh run view "$RELEASE_PUBLISH_RUN_ID" --repo "$GITHUB_REPOSITORY" --json workflowName,headBranch,event,status,conclusion,url)" - printf '%s' "$RUN_JSON" | node -e 'const fs = require("node:fs"); const run = JSON.parse(fs.readFileSync(0, "utf8")); const checks = [["workflowName", "OpenClaw Release Publish"], ["headBranch", process.env.EXPECTED_WORKFLOW_BRANCH], ["event", "workflow_dispatch"]]; for (const [key, expected] of checks) { if (run[key] !== expected) { console.error(`Referenced release publish run ${process.env.RELEASE_PUBLISH_RUN_ID} must have ${key}=${expected}, got ${run[key] ?? ""}.`); process.exit(1); } } if (run.status !== "in_progress") { console.error(`Referenced release publish run ${process.env.RELEASE_PUBLISH_RUN_ID} must still be in_progress, got ${run.status ?? ""}.`); process.exit(1); } if (run.conclusion) { console.error(`Referenced release publish run ${process.env.RELEASE_PUBLISH_RUN_ID} already concluded ${run.conclusion}.`); process.exit(1); } console.log(`Using release publish approval run ${process.env.RELEASE_PUBLISH_RUN_ID}: ${run.url}`);' + printf '%s' "$RUN_JSON" | DIRECT_RELEASE_RECOVERY="${direct_recovery}" node scripts/validate-release-publish-approval.mjs preview_plugin_pack: needs: preview_plugins_npm diff --git a/scripts/validate-release-publish-approval.mjs b/scripts/validate-release-publish-approval.mjs new file mode 100644 index 00000000000..c0f5ff35345 --- /dev/null +++ b/scripts/validate-release-publish-approval.mjs @@ -0,0 +1,57 @@ +#!/usr/bin/env node +import fs from "node:fs"; + +const run = JSON.parse(fs.readFileSync(0, "utf8")); + +const releasePublishRunId = process.env.RELEASE_PUBLISH_RUN_ID ?? ""; +const expectedBranch = process.env.EXPECTED_WORKFLOW_BRANCH ?? ""; +const directRecovery = process.env.DIRECT_RELEASE_RECOVERY === "true"; + +const checks = [ + ["workflowName", "OpenClaw Release Publish"], + ["headBranch", expectedBranch], + ["event", "workflow_dispatch"], +]; + +for (const [key, expected] of checks) { + if (run[key] !== expected) { + console.error( + `Referenced release publish run ${releasePublishRunId} must have ${key}=${expected}, got ${run[key] ?? ""}.`, + ); + process.exit(1); + } +} + +if (!directRecovery) { + if (run.status !== "in_progress") { + console.error( + `Referenced release publish run ${releasePublishRunId} must still be in_progress, got ${run.status ?? ""}.`, + ); + process.exit(1); + } + if (run.conclusion) { + console.error( + `Referenced release publish run ${releasePublishRunId} already concluded ${run.conclusion}.`, + ); + process.exit(1); + } + console.log(`Using release publish approval run ${releasePublishRunId}: ${run.url}`); + process.exit(0); +} + +if (run.status === "in_progress" && !run.conclusion) { + console.log(`Using active release publish run ${releasePublishRunId}: ${run.url}`); + process.exit(0); +} + +if (run.status === "completed" && ["success", "failure"].includes(run.conclusion)) { + console.log( + `Using completed release publish run ${releasePublishRunId} (${run.conclusion}) for direct recovery: ${run.url}`, + ); + process.exit(0); +} + +console.error( + `Direct release recovery run ${releasePublishRunId} must be in_progress or completed with success/failure, got status=${run.status ?? ""} conclusion=${run.conclusion ?? ""}.`, +); +process.exit(1); diff --git a/test/scripts/package-acceptance-workflow.test.ts b/test/scripts/package-acceptance-workflow.test.ts index dacc41d5443..465e540d480 100644 --- a/test/scripts/package-acceptance-workflow.test.ts +++ b/test/scripts/package-acceptance-workflow.test.ts @@ -1365,6 +1365,7 @@ describe("package artifact reuse", () => { const clawHubWorkflow = readFileSync(".github/workflows/plugin-clawhub-release.yml", "utf8"); const pluginNpmWorkflow = readFileSync(".github/workflows/plugin-npm-release.yml", "utf8"); const openclawNpmWorkflow = readFileSync(".github/workflows/openclaw-npm-release.yml", "utf8"); + const approvalScript = readFileSync("scripts/validate-release-publish-approval.mjs", "utf8"); expect(packageJson.scripts?.["release:verify-beta"]).toBe( "node --import tsx scripts/release-verify-beta.ts", @@ -1422,9 +1423,14 @@ describe("package artifact reuse", () => { expect(pluginNpmWorkflow).toContain('GITHUB_ACTOR}" != "github-actions[bot]"'); expect(clawHubWorkflow).toContain('GITHUB_ACTOR}" != "github-actions[bot]"'); expect(openclawNpmWorkflow).toContain('GITHUB_ACTOR}" != "github-actions[bot]"'); - expect(pluginNpmWorkflow).toContain("must still be in_progress"); - expect(clawHubWorkflow).toContain("must still be in_progress"); - expect(openclawNpmWorkflow).toContain("must still be in_progress"); + expect(pluginNpmWorkflow).toContain("Direct Plugin NPM Release recovery"); + expect(clawHubWorkflow).toContain("Direct Plugin ClawHub Release recovery"); + expect(openclawNpmWorkflow).toContain("Direct OpenClaw npm recovery"); + expect(pluginNpmWorkflow).toContain("validate-release-publish-approval.mjs"); + expect(clawHubWorkflow).toContain("validate-release-publish-approval.mjs"); + expect(openclawNpmWorkflow).toContain("validate-release-publish-approval.mjs"); + expect(approvalScript).toContain("must still be in_progress"); + expect(approvalScript).toContain("completed with success/failure"); expect(pluginNpmWorkflow).toContain("environment: npm-release"); expect(clawHubWorkflow).toContain("environment: clawhub-plugin-release"); expect(openclawNpmWorkflow).toContain("environment: npm-release");