Skip to content

Commit f809f32

Browse files
author
root
committed
fix(release): include all selected platform binaries in npm tarball
1 parent 20a7ff2 commit f809f32

5 files changed

Lines changed: 100 additions & 11 deletions

File tree

.github/workflows/codra-cli-release.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,29 @@ jobs:
134134
CODRA_USE_ARTIFACTS: '1'
135135
CODRA_ARTIFACTS_DIR: ${{ github.workspace }}/packages/codra-npm-cli/artifacts
136136
CODRA_ALLOW_PARTIAL_BINARIES: ${{ needs.resolve-matrix.outputs.allow_partial }}
137+
CODRA_EXPECT_PLATFORMS: ${{ needs.resolve-matrix.outputs.expected_platforms }}
137138
run: npm run build:from-artifacts
138139

139140
- name: Test npm wrapper
140141
working-directory: packages/codra-npm-cli
142+
env:
143+
CODRA_USE_ARTIFACTS: '1'
141144
run: npm test
142145

146+
- name: List release packaging inputs
147+
run: |
148+
echo "artifacts download path:"
149+
find packages/codra-npm-cli/artifacts -maxdepth 3 -type f -print || true
150+
echo "bin/native before pack:"
151+
find packages/codra-npm-cli/bin/native -maxdepth 3 -type f -print || true
152+
143153
- name: Validate npm pack contents
144154
working-directory: packages/codra-npm-cli
145155
env:
146156
CODRA_USE_ARTIFACTS: '1'
147157
CODRA_ARTIFACTS_DIR: ${{ github.workspace }}/packages/codra-npm-cli/artifacts
148158
CODRA_ALLOW_PARTIAL_BINARIES: ${{ needs.resolve-matrix.outputs.allow_partial }}
149-
CODRA_EXPECT_PLATFORMS: ${{ needs.resolve-matrix.outputs.expect_all_pack == '1' && needs.resolve-matrix.outputs.expected_platforms || '' }}
159+
CODRA_EXPECT_PLATFORMS: ${{ needs.resolve-matrix.outputs.expected_platforms }}
150160
run: npm run pack:dry
151161

152162
- name: Build npm tarball (no publish)
@@ -155,7 +165,7 @@ jobs:
155165
CODRA_USE_ARTIFACTS: '1'
156166
CODRA_ARTIFACTS_DIR: ${{ github.workspace }}/packages/codra-npm-cli/artifacts
157167
CODRA_ALLOW_PARTIAL_BINARIES: ${{ needs.resolve-matrix.outputs.allow_partial }}
158-
CODRA_EXPECT_PLATFORMS: ${{ needs.resolve-matrix.outputs.expect_all_pack == '1' && needs.resolve-matrix.outputs.expected_platforms || '' }}
168+
CODRA_EXPECT_PLATFORMS: ${{ needs.resolve-matrix.outputs.expected_platforms }}
159169
run: npm pack
160170

161171
- name: Upload npm tarball artifact

packages/codra-npm-cli/.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
artifacts/
2+
scripts/

packages/codra-npm-cli/scripts/build-platform-binaries.js

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,70 @@ function allowPartial() {
2323
return process.env.CODRA_ALLOW_PARTIAL_BINARIES === '1';
2424
}
2525

26+
function selectedTargets() {
27+
const expect = process.env.CODRA_EXPECT_PLATFORMS;
28+
if (!expect) {
29+
return TARGETS;
30+
}
31+
32+
const keys = expect
33+
.split(',')
34+
.map((key) => key.trim())
35+
.filter(Boolean);
36+
const selected = TARGETS.filter((target) => keys.includes(target.key));
37+
if (selected.length === 0) {
38+
console.error('[build:from-artifacts] CODRA_EXPECT_PLATFORMS did not match any known targets');
39+
process.exit(1);
40+
}
41+
return selected;
42+
}
43+
44+
function resolveArtifactPath(srcDir, artifactName) {
45+
const direct = path.join(srcDir, artifactName);
46+
if (fs.existsSync(direct)) {
47+
const stat = fs.statSync(direct);
48+
if (stat.isFile()) {
49+
return direct;
50+
}
51+
if (stat.isDirectory()) {
52+
const nested = path.join(direct, artifactName);
53+
if (fs.existsSync(nested) && fs.statSync(nested).isFile()) {
54+
return nested;
55+
}
56+
const nestedBin = path.join(direct, path.basename(artifactName, path.extname(artifactName)));
57+
if (fs.existsSync(nestedBin) && fs.statSync(nestedBin).isFile()) {
58+
return nestedBin;
59+
}
60+
}
61+
}
62+
63+
return null;
64+
}
65+
2666
function main() {
2767
const srcDir = artifactsDir();
2868
const partial = allowPartial();
69+
const targets = selectedTargets();
2970
const missing = [];
3071
const packaged = [];
3172

3273
console.log(`[build:from-artifacts] artifacts dir: ${srcDir}`);
3374
console.log(`[build:from-artifacts] partial packaging: ${partial ? 'yes' : 'no'}`);
75+
console.log(
76+
`[build:from-artifacts] selected targets: ${targets.map((target) => target.key).join(', ')}`,
77+
);
3478

3579
if (!fs.existsSync(srcDir)) {
3680
console.error(`[build:from-artifacts] artifacts directory not found: ${srcDir}`);
3781
process.exit(1);
3882
}
3983

40-
for (const target of TARGETS) {
41-
const src = path.join(srcDir, target.artifact);
84+
for (const target of targets) {
85+
const src = resolveArtifactPath(srcDir, target.artifact);
4286
const destDir = path.join(packageRoot, 'bin', 'native', target.key);
4387
const dest = path.join(destDir, target.destName);
4488

45-
if (!fs.existsSync(src)) {
89+
if (!src) {
4690
missing.push(target.artifact);
4791
continue;
4892
}
@@ -64,7 +108,7 @@ function main() {
64108
if (missing.length > 0) {
65109
console.error('[build:from-artifacts] missing artifacts:');
66110
for (const name of missing) {
67-
console.error(` - ${path.join(srcDir, name)}`);
111+
console.error(` - ${name}`);
68112
}
69113

70114
if (!partial) {
@@ -80,7 +124,17 @@ function main() {
80124
process.exit(1);
81125
}
82126

83-
console.log(`[build:from-artifacts] packaged ${packaged.length}/${TARGETS.length} targets`);
127+
const requiredCount = partial ? packaged.length : targets.length;
128+
if (!partial && packaged.length !== targets.length) {
129+
console.error(
130+
`[build:from-artifacts] expected ${targets.length} binaries, packaged ${packaged.length}`,
131+
);
132+
process.exit(1);
133+
}
134+
135+
console.log(
136+
`[build:from-artifacts] packaged ${packaged.length}/${targets.length} selected targets (required ${requiredCount})`,
137+
);
84138
}
85139

86140
main();

packages/codra-npm-cli/scripts/prepack.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,36 @@ function installedNativePlatformKeys() {
4545
});
4646
}
4747

48+
function expectedPlatformKeys() {
49+
if (!process.env.CODRA_EXPECT_PLATFORMS) {
50+
return [];
51+
}
52+
53+
return process.env.CODRA_EXPECT_PLATFORMS.split(',')
54+
.map((key) => key.trim())
55+
.filter(Boolean);
56+
}
57+
58+
function hasExpectedNativeBinaries() {
59+
const expected = expectedPlatformKeys();
60+
const installed = installedNativePlatformKeys();
61+
if (expected.length === 0) {
62+
return installed.length > 0;
63+
}
64+
return expected.every((key) => installed.includes(key));
65+
}
66+
4867
function shouldSkipArtifactRebuild() {
4968
if (!shouldUseArtifacts()) {
5069
return false;
5170
}
5271

53-
const installed = installedNativePlatformKeys();
54-
if (installed.length === 0) {
72+
if (installedNativePlatformKeys().length === 0) {
5573
return false;
5674
}
5775

58-
// CI already ran build:from-artifacts; avoid a strict second pass during partial dry runs.
59-
if (process.env.CODRA_ALLOW_PARTIAL_BINARIES === '1') {
76+
// CI already ran build:from-artifacts; skip only when every expected selected platform is present.
77+
if (process.env.CODRA_ALLOW_PARTIAL_BINARIES === '1' && hasExpectedNativeBinaries()) {
6078
return true;
6179
}
6280

packages/codra-npm-cli/scripts/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ function testPlatformHelpers() {
8282
}
8383

8484
function testArtifactPackaging() {
85+
if (process.env.CODRA_USE_ARTIFACTS === '1') {
86+
console.log('[test] skip artifact packaging layout test (release artifact mode)');
87+
return;
88+
}
89+
8590
const tmpArtifacts = fs.mkdtempSync(path.join(os.tmpdir(), 'codra-artifacts-'));
8691
const hostBinary = lib.resolveNativeBinary();
8792

0 commit comments

Comments
 (0)