Skip to content

Commit 60888c3

Browse files
authored
Merge pull request #44 from echohello-dev/codex/issue-16-build-matrix-checksums
feat(ci): add build matrix and checksums
2 parents 3135093 + 7961ef0 commit 60888c3

4 files changed

Lines changed: 198 additions & 2 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Build Matrix
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
include:
16+
- os: ubuntu-latest
17+
targets: linux-x64-gnu,linux-x64-musl,linux-arm64-gnu,linux-arm64-musl
18+
- os: macos-latest
19+
targets: darwin-arm64,darwin-x64
20+
- os: windows-latest
21+
targets: windows-x64
22+
23+
runs-on: ${{ matrix.os }}
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
28+
29+
- name: Setup mise
30+
uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac
31+
32+
- name: Build targets
33+
run: mise run build -- --targets=${{ matrix.targets }}
34+
35+
- name: Smoke test host artifact
36+
run: bun scripts/smoke-artifact.ts
37+
38+
- name: Write checksums
39+
run: bun scripts/write-checksums.ts
40+
41+
- name: Upload build artifacts
42+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
43+
with:
44+
name: skillet-${{ matrix.os }}
45+
path: dist/*
46+
47+
checksums:
48+
needs: build
49+
runs-on: ubuntu-latest
50+
51+
steps:
52+
- name: Checkout
53+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
54+
55+
- name: Setup mise
56+
uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac
57+
58+
- name: Download artifacts
59+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
60+
with:
61+
path: .artifacts
62+
merge-multiple: true
63+
64+
- name: Assemble combined SHA256SUMS
65+
shell: bash
66+
run: |
67+
set -euo pipefail
68+
mkdir -p dist
69+
cp .artifacts/skillet-* dist/ || true
70+
cp .artifacts/*.exe dist/ || true
71+
cp .artifacts/build-manifest.json dist/ || true
72+
bun scripts/write-checksums.ts
73+
74+
- name: Upload combined checksums
75+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
76+
with:
77+
name: skillet-checksums
78+
path: dist/SHA256SUMS

‎scripts/build-release.ts‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type BuildResult = {
1313
function main(): void {
1414
const repoRoot = process.cwd();
1515
const distDir = path.join(repoRoot, "dist");
16+
const selectedTargets = resolveSelectedTargets(process.argv.slice(2));
1617

1718
const packageJson = JSON.parse(fs.readFileSync(path.join(repoRoot, "package.json"), "utf8")) as {
1819
version: string;
@@ -27,7 +28,7 @@ function main(): void {
2728

2829
const results: BuildResult[] = [];
2930

30-
for (const target of RELEASE_TARGETS) {
31+
for (const target of selectedTargets) {
3132
const artifactPath = path.join(distDir, target.artifactName);
3233
const metadata = [`commit=${commit}`, `builtAt=${builtAt}`, `target=${target.id}`].join(",");
3334

@@ -96,7 +97,8 @@ function verifyHostArtifact(results: BuildResult[]): void {
9697

9798
const hostResult = results.find((result) => result.id === hostId);
9899
if (!hostResult) {
99-
throw new Error(`Missing host artifact for ${hostId}`);
100+
console.log(`Skipped host smoke verification: ${hostId} not in selected target set`);
101+
return;
100102
}
101103

102104
const output = execFileSync(hostResult.artifactPath, ["--version"], {
@@ -115,6 +117,49 @@ function verifyHostArtifact(results: BuildResult[]): void {
115117
console.log(`Verified host artifact ${hostId} reports version and metadata`);
116118
}
117119

120+
function resolveSelectedTargets(argv: string[]) {
121+
const selectedIds = new Set<string>();
122+
123+
for (let i = 0; i < argv.length; i += 1) {
124+
const token = argv[i];
125+
if (token.startsWith("--targets=")) {
126+
for (const id of token.slice("--targets=".length).split(",")) {
127+
if (id.trim().length > 0) {
128+
selectedIds.add(id.trim());
129+
}
130+
}
131+
continue;
132+
}
133+
134+
if (token === "--targets") {
135+
const value = argv[i + 1];
136+
if (!value) {
137+
throw new Error("Missing value for --targets");
138+
}
139+
for (const id of value.split(",")) {
140+
if (id.trim().length > 0) {
141+
selectedIds.add(id.trim());
142+
}
143+
}
144+
i += 1;
145+
continue;
146+
}
147+
}
148+
149+
if (selectedIds.size === 0) {
150+
return RELEASE_TARGETS;
151+
}
152+
153+
const filtered = RELEASE_TARGETS.filter((target) => selectedIds.has(target.id));
154+
if (filtered.length !== selectedIds.size) {
155+
const known = new Set(RELEASE_TARGETS.map((target) => target.id));
156+
const unknown = [...selectedIds].filter((id) => !known.has(id));
157+
throw new Error(`Unknown target id(s): ${unknown.join(", ")}`);
158+
}
159+
160+
return filtered;
161+
}
162+
118163
function gitShortCommit(cwd: string): string {
119164
try {
120165
return execFileSync("git", ["rev-parse", "--short", "HEAD"], {

‎scripts/smoke-artifact.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
import { execFileSync } from "node:child_process";
4+
import { RELEASE_TARGETS, getHostBuildTargetId } from "../src/build/targets";
5+
6+
function main(): void {
7+
const hostId = getHostBuildTargetId(process.platform, process.arch);
8+
if (!hostId) {
9+
console.log(`No smoke target mapping for ${process.platform}/${process.arch}`);
10+
return;
11+
}
12+
13+
const hostTarget = RELEASE_TARGETS.find((target) => target.id === hostId);
14+
if (!hostTarget) {
15+
throw new Error(`Host target not found in RELEASE_TARGETS: ${hostId}`);
16+
}
17+
18+
const artifactPath = path.join(process.cwd(), "dist", hostTarget.artifactName);
19+
if (!fs.existsSync(artifactPath)) {
20+
throw new Error(`Host artifact missing: ${artifactPath}`);
21+
}
22+
23+
const output = execFileSync(artifactPath, ["--version"], {
24+
encoding: "utf8",
25+
stdio: ["ignore", "pipe", "pipe"],
26+
});
27+
28+
if (!output.includes("skillet/")) {
29+
throw new Error(`Unexpected smoke output: ${output}`);
30+
}
31+
32+
console.log(`Smoke test passed for ${hostId}: ${output.trim()}`);
33+
}
34+
35+
main();

‎scripts/write-checksums.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
import crypto from "node:crypto";
4+
5+
function main(): void {
6+
const distDir = path.join(process.cwd(), "dist");
7+
if (!fs.existsSync(distDir)) {
8+
throw new Error("dist/ does not exist");
9+
}
10+
11+
const artifactNames = fs
12+
.readdirSync(distDir)
13+
.filter((name) => {
14+
if (name === "build-manifest.json" || name === "SHA256SUMS") {
15+
return false;
16+
}
17+
18+
const fullPath = path.join(distDir, name);
19+
return fs.statSync(fullPath).isFile();
20+
})
21+
.sort((a, b) => a.localeCompare(b));
22+
23+
if (artifactNames.length === 0) {
24+
throw new Error("No build artifacts found in dist/");
25+
}
26+
27+
const lines = artifactNames.map((name) => {
28+
const data = fs.readFileSync(path.join(distDir, name));
29+
const hash = crypto.createHash("sha256").update(data).digest("hex");
30+
return `${hash} ${name}`;
31+
});
32+
33+
const outputPath = path.join(distDir, "SHA256SUMS");
34+
fs.writeFileSync(outputPath, `${lines.join("\n")}\n`);
35+
console.log(`Wrote ${outputPath}`);
36+
}
37+
38+
main();

0 commit comments

Comments
 (0)