A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
skip superseded push builds in the release workflow (#2567)
kt6f413ac9e644
diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.ymlindex e168268e07..456eab08a0 100644--- a/.github/workflows/build-binaries.yml+++ b/.github/workflows/build-binaries.yml@@ -52,6 +52,7 @@ jobs:production_version: ${{ steps.context.outputs.production_version }}publish_beta: ${{ steps.context.outputs.publish_beta }}publish_production: ${{ steps.context.outputs.publish_production }}+ stale: ${{ steps.staleness.outputs.stale }}steps:- name: Checkoutuses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0@@ -142,8 +143,35 @@ jobs:echo "Production: $publish_production ${production_version:+v${production_version}}"echo "Beta: $publish_beta ${beta_version:+v${beta_version}}"+ - name: Skip superseded push builds+ id: staleness+ env:+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ PUBLISH_PRODUCTION: ${{ steps.context.outputs.publish_production }}+ run: |+ if [ "${GITHUB_EVENT_NAME}" != "push" ] || [ "${GITHUB_REF_TYPE}" = "tag" ]; then+ echo "Event is ${GITHUB_EVENT_NAME} on ${GITHUB_REF_TYPE} ${GITHUB_REF_NAME}; building as usual."+ echo "stale=false" >> "${GITHUB_OUTPUT}"+ exit 0+ fi+ if [ "${PUBLISH_PRODUCTION}" = "true" ]; then+ echo "This run can publish production; building even though a newer commit may exist."+ echo "stale=false" >> "${GITHUB_OUTPUT}"+ exit 0+ fi+ # Fail open: a tip-check hiccup must never skip a real release build.+ latest_sha="$(gh api "repos/${GITHUB_REPOSITORY}/commits/${GITHUB_REF_NAME}" --jq .sha 2>/dev/null || echo "${GITHUB_SHA}")"+ if [ "${latest_sha}" = "${GITHUB_SHA}" ]; then+ echo "This commit is the tip of ${GITHUB_REF_NAME}; building."+ echo "stale=false" >> "${GITHUB_OUTPUT}"+ else+ echo "${GITHUB_SHA} is superseded by ${latest_sha} on ${GITHUB_REF_NAME}; skipping the superseded beta build."+ echo "stale=true" >> "${GITHUB_OUTPUT}"+ fi+standalone:needs: release-context+ if: needs.release-context.result == 'success' && needs.release-context.outputs.stale != 'true'uses: ./.github/workflows/standalone-binaries.ymlwith:build_ref: ${{ needs.release-context.outputs.build_ref }}@@ -152,6 +180,7 @@ jobs:build:runs-on: ubuntu-latestneeds: [release-context, standalone]+ if: needs.release-context.result == 'success' && needs.release-context.outputs.stale != 'true'permissions:contents: readenv:@@ -293,6 +322,7 @@ jobs:validate-macos:name: Final release (${{ matrix.platform }})needs: [release-context, build]+ if: needs.release-context.result == 'success' && needs.release-context.outputs.stale != 'true'runs-on: ${{ matrix.runner }}timeout-minutes: 30strategy:@@ -378,7 +408,7 @@ jobs:if-no-files-found: errorpublish:- if: github.event_name != 'pull_request'+ if: github.event_name != 'pull_request' && needs.release-context.result == 'success' && needs.release-context.outputs.stale != 'true'runs-on: ubuntu-latestneeds: [release-context, build, validate-macos]permissions:diff --git a/packages/coding-agent/test/release-workflow.test.ts b/packages/coding-agent/test/release-workflow.test.tsindex dba83727bc..b02e4017b9 100644--- a/packages/coding-agent/test/release-workflow.test.ts+++ b/packages/coding-agent/test/release-workflow.test.ts@@ -1,5 +1,5 @@import { spawnSync } from "node:child_process";-import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";+import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join, resolve } from "node:path";import { describe, expect, it } from "vitest";@@ -8,6 +8,7 @@ import { NATIVE_PLATFORMS } from "../src/utils/native-installation.js";interface Step {name?: string;+ id?: string;run?: string;uses?: string;if?: string;@@ -17,6 +18,7 @@ interface Step {interface Job {needs?: string | string[];if?: string;+ outputs?: Record<string, string>;"continue-on-error"?: boolean;"runs-on"?: string;strategy?: { matrix: { include: { platform: string; runner: string }[] } };@@ -37,6 +39,8 @@ const releasePlatforms = spawnSync(process.execPath, [join(repository, "scripts/.split("\n");const release: Workflow = parse(readFileSync(join(repository, ".github/workflows/build-binaries.yml"), "utf8"));const standalone: Workflow = parse(readFileSync(join(repository, ".github/workflows/standalone-binaries.yml"), "utf8"));+// The skip-superseded gate: dependent jobs build only when release-context succeeded on a current tip.+const staleGate = "needs.release-context.result == 'success' && needs.release-context.outputs.stale != 'true'";function step(job: Job, name: string): Step {const found = job.steps.find((entry) => entry.name === name);@@ -65,7 +69,7 @@ describe("release workflow signature gates", () => {]);const publish = release.jobs.publish!;expect(publish.needs).toEqual(expect.arrayContaining(["build", "validate-macos"]));- expect(publish.if).toBe("github.event_name != 'pull_request'");+ expect(publish.if).toBe(`github.event_name != 'pull_request' && ${staleGate}`);requiresSuccess(validation);requiresSuccess(publish);});@@ -238,12 +242,72 @@ ${step(validation, "Verify and exercise exact final Mac archives").run}`,expect(pack.run).toContain(`--channel ${channel}`);expect(pack.run).toContain("--binary-dir packages/coding-agent/binaries");}- expect(release.jobs.publish!.if).toBe("github.event_name != 'pull_request'");+ expect(release.jobs.publish!.if).toBe(`github.event_name != 'pull_request' && ${staleGate}`);} finally {rmSync(directory, { recursive: true, force: true });}},);++ it("wires the staleness check into the standalone, build, validation, and publish gates", () => {+ const context = release.jobs["release-context"]!;+ const staleness = step(context, "Skip superseded push builds");+ expect(staleness.id).toBe("staleness");+ expect(context.outputs?.stale).toBe(`\${{ steps.staleness.outputs.stale }}`);+ for (const name of ["standalone", "build", "validate-macos", "publish"]) {+ const job = release.jobs[name]!;+ expect([job.needs ?? []].flat()).toContain("release-context");+ expect(job.if).toContain(staleGate);+ }+ });++ // test-policy: allow conditional-or-disabled-test -- the step script is POSIX bash, matching the packer-paths guard+ it.skipIf(process.platform === "win32")(+ "marks only superseded beta pushes stale and fails open when the tip check breaks",+ () => {+ const staleness = step(release.jobs["release-context"]!, "Skip superseded push builds");+ for (const scenario of [+ { event: "pull_request", refType: "branch", production: "false", gh: undefined, stale: "false" },+ { event: "push", refType: "tag", production: "false", gh: undefined, stale: "false" },+ { event: "push", refType: "branch", production: "true", gh: "tip", stale: "false" },+ { event: "push", refType: "branch", production: "false", gh: "broken", stale: "false" },+ { event: "push", refType: "branch", production: "false", gh: "tip", stale: "true" },+ ]) {+ const directory = mkdtempSync(join(tmpdir(), "prime-release-staleness-"));+ try {+ if (scenario.gh) {+ const bin = join(directory, "bin");+ mkdirSync(bin);+ writeFileSync(+ join(bin, "gh"),+ scenario.gh === "tip" ? "#!/bin/sh\necho tip-sha\n" : "#!/bin/sh\nexit 1\n",+ );+ chmodSync(join(bin, "gh"), 0o755);+ }+ const output = join(directory, "output");+ const result = spawnSync("bash", ["-e", "-o", "pipefail", "-c", staleness.run!], {+ cwd: repository,+ env: {+ ...process.env,+ ...(scenario.gh ? { PATH: `${join(directory, "bin")}:${process.env.PATH}` } : {}),+ GITHUB_EVENT_NAME: scenario.event,+ GITHUB_REF_TYPE: scenario.refType,+ GITHUB_REF_NAME: "main",+ GITHUB_REPOSITORY: "PrimeIntellect-ai/prime-agent",+ GITHUB_SHA: "run-sha",+ GITHUB_OUTPUT: output,+ PUBLISH_PRODUCTION: scenario.production,+ },+ encoding: "utf8",+ });+ expect(result.status, result.stderr).toBe(0);+ expect(readFileSync(output, "utf8")).toBe(`stale=${scenario.stale}\n`);+ } finally {+ rmSync(directory, { recursive: true, force: true });+ }+ }+ },+ );});describe("release manifest schemas", () => {