fix(ci): package locally verified source without remote tests
This commit is contained in:
1 parent
1a1b1e0693
commit
def83dcb32
5 files changed
+136
-7
No files matched your search
@@ -0,0 +1,110 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync, existsSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { test } from "node:test";
|
||||
|
||||
// Execute the actual checked-in run blocks against strict external build-tool ports.
|
||||
// Real Gradle packaging is verified separately on the final candidate; these ports prove wiring.
|
||||
function buildCommands(workflow: string): string[] {
|
||||
const lines = readFileSync(`.gitea/workflows/${workflow}`, "utf8").split("\n");
|
||||
const commands: string[] = [];
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const match = /^ {8}run: (.+)$/.exec(lines[i]!);
|
||||
if (!match) continue;
|
||||
let command = match[1]!;
|
||||
if (command === "|") {
|
||||
const body: string[] = [];
|
||||
while (i + 1 < lines.length && /^ {10}/.test(lines[i + 1]!)) body.push(lines[++i]!.slice(10));
|
||||
command = body.join("\n");
|
||||
}
|
||||
if (command.includes("./gradlew")) commands.push(command);
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
function fixture() {
|
||||
const root = mkdtempSync(join(tmpdir(), "fantasy-packaging-port-"));
|
||||
mkdirSync(join(root, "bin"));
|
||||
writeFileSync(join(root, "gradlew"), `#!/bin/sh
|
||||
set -eu
|
||||
version=0.1.0-SNAPSHOT
|
||||
printf 'gradle %s\\n' "$*" >> "$CALLS"
|
||||
if [ "$FAIL_PACKAGE" = true ]; then exit 87; fi
|
||||
for arg do
|
||||
case "$arg" in
|
||||
clean|jar) ;;
|
||||
-PreleaseVersion=*) version="\${arg#-PreleaseVersion=}" ;;
|
||||
*) printf 'Unexpected task: %s\\n' "$arg" >&2; exit 91 ;;
|
||||
esac
|
||||
done
|
||||
mkdir -p build/libs build/distributions
|
||||
printf 'external packaging port\\n' > "build/libs/purpur-fantasy-stick-$version.jar"
|
||||
printf 'external resource-pack port\\n' > "build/distributions/purpur-fantasy-stick-$version-resource-pack.zip"
|
||||
`, { mode: 0o700 });
|
||||
writeFileSync(join(root, "bin/npm"), `#!/bin/sh
|
||||
set -eu
|
||||
printf 'npm %s\\n' "$*" >> "$CALLS"
|
||||
case "$*" in
|
||||
'ci --ignore-scripts --no-audit --no-fund') ;;
|
||||
'run build')
|
||||
[ "$BUILD_SCRIPT" = tsc ] || { printf 'Missing compile-only release-tool script\\n' >&2; exit 92; }
|
||||
mkdir -p build/release-tools
|
||||
printf 'external TypeScript compiler port\\n' > build/release-tools/publish-release.js
|
||||
;;
|
||||
*) printf 'Unexpected npm command: %s\\n' "$*" >&2; exit 93 ;;
|
||||
esac
|
||||
`, { mode: 0o700 });
|
||||
const metadata = JSON.parse(readFileSync("package.json", "utf8")) as { scripts: Record<string, string> };
|
||||
return {
|
||||
root,
|
||||
run(command: string, failPackage = false) {
|
||||
return spawnSync("/bin/sh", ["-eu", "-c", command], {
|
||||
cwd: root, encoding: "utf8", timeout: 10_000,
|
||||
env: { PATH: `${join(root, "bin")}:/usr/bin:/bin`, CALLS: join(root, "calls"), VERSION: "3.2.1",
|
||||
BUILD_SCRIPT: metadata.scripts.build ?? "", FAIL_PACKAGE: String(failPackage) },
|
||||
});
|
||||
},
|
||||
close() { rmSync(root, { recursive: true, force: true }); },
|
||||
};
|
||||
}
|
||||
|
||||
test("CI packages its development artifact without dispatching verification tasks", () => {
|
||||
const commands = buildCommands("ci.yml");
|
||||
assert.equal(commands.length, 1);
|
||||
const port = fixture();
|
||||
try {
|
||||
const result = port.run(commands[0]!);
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.ok(existsSync(join(port.root, "build/libs/purpur-fantasy-stick-0.1.0-SNAPSHOT.jar")));
|
||||
assert.equal(readFileSync(join(port.root, "calls"), "utf8"), "gradle clean jar\n");
|
||||
} finally { port.close(); }
|
||||
});
|
||||
|
||||
test("release packages its exact version and compiles publication tools without running suites", () => {
|
||||
const commands = buildCommands("release.yml");
|
||||
assert.equal(commands.length, 2);
|
||||
const port = fixture();
|
||||
try {
|
||||
for (const command of commands) {
|
||||
const result = port.run(command);
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
}
|
||||
assert.ok(existsSync(join(port.root, "build/libs/purpur-fantasy-stick-3.2.1.jar")));
|
||||
assert.ok(existsSync(join(port.root, "build/distributions/purpur-fantasy-stick-3.2.1-resource-pack.zip")));
|
||||
assert.ok(existsSync(join(port.root, "build/release-tools/publish-release.js")));
|
||||
assert.equal(readFileSync(join(port.root, "calls"), "utf8"),
|
||||
"gradle clean jar\ngradle clean jar -PreleaseVersion=3.2.1\nnpm ci --ignore-scripts --no-audit --no-fund\nnpm run build\n");
|
||||
} finally { port.close(); }
|
||||
});
|
||||
|
||||
test("failed versioned packaging stops before preparing publication tools", () => {
|
||||
const port = fixture();
|
||||
try {
|
||||
const result = port.run(buildCommands("release.yml")[1]!, true);
|
||||
assert.equal(result.status, 87);
|
||||
assert.equal(readFileSync(join(port.root, "calls"), "utf8"), "gradle clean jar -PreleaseVersion=3.2.1\n");
|
||||
assert.ok(!existsSync(join(port.root, "build/release-tools/publish-release.js")));
|
||||
} finally { port.close(); }
|
||||
});
|
||||
Reference in new issue
Block a user