All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 1m4s
50 lines
1.7 KiB
JavaScript
50 lines
1.7 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { publicationPlan, publishImage } from "../scripts/publish-image.js";
|
|
const base = {
|
|
CI_EVENT: "push",
|
|
REPOSITORY: "Elijah/Calio",
|
|
COMMIT_SHA: "a".repeat(40),
|
|
TARGET_REF: "refs/heads/main",
|
|
MAIN_BRANCH: "main",
|
|
};
|
|
test("each push publishes a commit image; only main promotes latest", () => {
|
|
const main = publicationPlan(base);
|
|
assert.equal(main.image, "git.elijahkuntz.com/elijah/calio");
|
|
assert.deepEqual(main.tags, [base.COMMIT_SHA]);
|
|
assert.equal(main.latest, true);
|
|
const branch = publicationPlan({
|
|
...base,
|
|
TARGET_REF: "refs/heads/codex/new-ui",
|
|
});
|
|
assert.equal(branch.latest, false);
|
|
assert.deepEqual(branch.tags, [base.COMMIT_SHA]);
|
|
});
|
|
test("release tags add a version without overwriting main latest", () => {
|
|
assert.deepEqual(
|
|
publicationPlan({ ...base, TARGET_REF: "refs/tags/v0.1.0" }).tags,
|
|
[base.COMMIT_SHA, "v0.1.0"],
|
|
);
|
|
assert.equal(
|
|
publicationPlan({ ...base, TARGET_REF: "refs/tags/v0.1.0" }).latest,
|
|
false,
|
|
);
|
|
assert.deepEqual(
|
|
publicationPlan({ ...base, TARGET_REF: "refs/tags/test/snapshot" }).tags,
|
|
[base.COMMIT_SHA],
|
|
);
|
|
});
|
|
test("PRs never publish or require registry secrets; missing publishing credentials fail clearly", () => {
|
|
assert.equal(publicationPlan({ ...base, CI_EVENT: "pull_request" }), null);
|
|
assert.throws(() => publishImage(base), /FORGEJO_PAT/);
|
|
});
|
|
test("invalid image names and commit identifiers cannot enter Docker command arguments", () => {
|
|
assert.throws(
|
|
() => publicationPlan({ ...base, REPOSITORY: "bad/name;command" }),
|
|
/REPOSITORY/,
|
|
);
|
|
assert.throws(
|
|
() => publicationPlan({ ...base, COMMIT_SHA: "--help" }),
|
|
/commit ID/,
|
|
);
|
|
});
|