Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,14 @@ jobs:
merge:
name: Merge multi-arch manifest
runs-on: ubuntu-24.04
if: github.event_name != 'pull_request'
# A skipped job anywhere upstream (the off-schedule approval on every
# scheduled tag) makes GitHub skip every job below it whose condition
# leaves the implicit success() in place. Each job after `build` therefore
# states its own condition on the results it depends on.
if: >-
!cancelled() &&
github.event_name != 'pull_request' &&
needs.build.result == 'success'
needs: [build]
timeout-minutes: 10
outputs:
Expand Down Expand Up @@ -483,6 +490,7 @@ jobs:
verify-published-image:
name: Verify exact published image
needs: merge
if: "!cancelled() && needs.merge.result == 'success'"
permissions:
contents: read
packages: read
Expand Down Expand Up @@ -511,7 +519,11 @@ jobs:
release-manifest:
name: Sign release manifest
needs: [merge, verify-published-image]
if: startsWith(github.ref, 'refs/tags/v')
if: >-
!cancelled() &&
startsWith(github.ref, 'refs/tags/v') &&
needs.merge.result == 'success' &&
needs.verify-published-image.result == 'success'
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
Expand Down Expand Up @@ -602,6 +614,7 @@ jobs:
release-provenance:
name: SLSA provenance for the release manifest
needs: [release-manifest]
if: "!cancelled() && needs.release-manifest.result == 'success'"
permissions:
actions: read
id-token: write
Expand All @@ -619,6 +632,10 @@ jobs:
release-assets:
name: Attach signed manifest to the GitHub release
needs: [release-manifest, release-provenance]
if: >-
!cancelled() &&
needs.release-manifest.result == 'success' &&
needs.release-provenance.result == 'success'
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
Expand Down Expand Up @@ -667,6 +684,10 @@ jobs:
promote:
name: Promote verified image to Coolify
needs: [merge, verify-published-image]
if: >-
!cancelled() &&
needs.merge.result == 'success' &&
needs.verify-published-image.result == 'success'
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
Expand Down
60 changes: 59 additions & 1 deletion scripts/__tests__/release-workflows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@ describe("signed release assets", () => {
const workflow = loadWorkflow("docker-publish.yml");
const manifest = workflow.jobs["release-manifest"];

expect(manifest?.if).toBe("startsWith(github.ref, 'refs/tags/v')");
const manifestIf = (manifest?.if ?? "").replace(/\s+/g, " ");
expect(manifestIf).toContain("startsWith(github.ref, 'refs/tags/v')");
expect(manifest?.needs).toEqual(["merge", "verify-published-image"]);
expect(workflow.jobs["release-provenance"]?.needs).toEqual([
"release-manifest",
Expand Down Expand Up @@ -855,3 +856,60 @@ describe("signed release assets", () => {
expect(script).not.toMatch(/release edit|--draft=false|--latest/);
});
});

describe("skipped jobs do not silently end a chain", () => {
// GitHub skips a job when ANY job in its dependency chain was skipped,
// unless the job's own condition replaces the implicit success(). The
// off-schedule approval is skipped on every scheduled tag, so before this
// guard every job after `build` was skipped on the first real release:
// no manifest, no signature, no provenance, no release assets, all green.
const files = readdirSync(
join(
dirname(new URL(import.meta.url).pathname),
"../..",
".github/workflows",
),
).filter((f) => /\.ya?ml$/.test(f));

it("finds the workflows and the conditional jobs it reasons about", () => {
expect(files).toContain("docker-publish.yml");
const jobs = loadWorkflow("docker-publish.yml").jobs;
expect(jobs["off-schedule-approval"]?.if).toBeTruthy();
});

for (const file of files) {
it(`${file}: every job below a skippable job states its own condition`, () => {
const jobs = (loadWorkflow(file).jobs ?? {}) as Record<
string,
{ needs?: string | string[]; if?: string; steps?: unknown }
>;
const needsOf = (id: string): string[] => {
const n = jobs[id]?.needs;
return n === undefined ? [] : Array.isArray(n) ? n : [n];
};
const skippable = new Map<string, boolean>();
const canSkip = (id: string): boolean => {
const known = skippable.get(id);
if (known !== undefined) return known;
const value =
Boolean(jobs[id]?.if) || needsOf(id).some((need) => canSkip(need));
skippable.set(id, value);
return value;
};
const offenders: string[] = [];
for (const id of Object.keys(jobs)) {
const upstream = needsOf(id);
if (!upstream.some((need) => canSkip(need))) continue;
const condition = (jobs[id]?.if ?? "").replace(/\s+/g, " ");
// The results may be checked in the condition or, for an aggregate
// job that runs under always(), in its own steps.
const body = JSON.stringify(jobs[id]);
const explicit =
/!cancelled\(\)|always\(\)/.test(condition) &&
upstream.every((need) => body.includes(`needs.${need}.result`));
if (!explicit) offenders.push(id);
}
expect(offenders).toEqual([]);
});
}
});
Loading