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
4 changes: 4 additions & 0 deletions .github/workflows/codra-cli-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ jobs:
- name: Validate npm pack contents
working-directory: packages/codra-npm-cli
env:
CODRA_USE_ARTIFACTS: '1'
CODRA_ARTIFACTS_DIR: ${{ github.workspace }}/packages/codra-npm-cli/artifacts
CODRA_ALLOW_PARTIAL_BINARIES: ${{ needs.resolve-matrix.outputs.allow_partial }}
CODRA_EXPECT_PLATFORMS: ${{ needs.resolve-matrix.outputs.expect_all_pack == '1' && needs.resolve-matrix.outputs.expected_platforms || '' }}
run: npm run pack:dry

Expand All @@ -152,6 +155,7 @@ jobs:
CODRA_USE_ARTIFACTS: '1'
CODRA_ARTIFACTS_DIR: ${{ github.workspace }}/packages/codra-npm-cli/artifacts
CODRA_ALLOW_PARTIAL_BINARIES: ${{ needs.resolve-matrix.outputs.allow_partial }}
CODRA_EXPECT_PLATFORMS: ${{ needs.resolve-matrix.outputs.expect_all_pack == '1' && needs.resolve-matrix.outputs.expected_platforms || '' }}
run: npm pack

- name: Upload npm tarball artifact
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ node_modules
.DS_Store
*.log

# Local secrets (never commit)
.env
.env.*
!.env.example

# Rust
target/
**/*.rs.bk
Expand Down
27 changes: 21 additions & 6 deletions packages/codra-npm-cli/scripts/pack-dry-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ function expectedNativePaths() {
return [];
}

function packagingEnv(expectedNative) {
const env = { ...process.env };
const passthrough = [
'CODRA_USE_ARTIFACTS',
'CODRA_ARTIFACTS_DIR',
'CODRA_ALLOW_PARTIAL_BINARIES',
'CODRA_EXPECT_PLATFORMS',
'CODRA_EXPECT_ALL_PLATFORMS',
];
for (const key of passthrough) {
if (process.env[key] !== undefined) {
env[key] = process.env[key];
}
}
if (!env.CODRA_USE_ARTIFACTS && expectedNative.length > 0) {
env.CODRA_USE_ARTIFACTS = '1';
}
return env;
}

function main() {
const expectedNative = expectedNativePaths();

Expand All @@ -39,12 +59,7 @@ function main() {
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'pipe'],
shell: true,
env: {
...process.env,
CODRA_USE_ARTIFACTS:
process.env.CODRA_USE_ARTIFACTS ||
(expectedNative.length > 0 ? '1' : process.env.CODRA_USE_ARTIFACTS),
},
env: packagingEnv(expectedNative),
});

const lines = output.split('\n');
Expand Down
56 changes: 55 additions & 1 deletion packages/codra-npm-cli/scripts/prepack.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,67 @@ function shouldUseArtifacts() {
return TARGET_ARTIFACTS.some((name) => fs.existsSync(path.join(dir, name)));
}

function installedNativePlatformKeys() {
const nativeRoot = path.join(packageRoot, 'bin', 'native');
if (!fs.existsSync(nativeRoot)) {
return [];
}

return fs.readdirSync(nativeRoot).filter((key) => {
const name = key.startsWith('win32') ? 'codra.exe' : 'codra';
return fs.existsSync(path.join(nativeRoot, key, name));
});
}

function shouldSkipArtifactRebuild() {
if (!shouldUseArtifacts()) {
return false;
}

const installed = installedNativePlatformKeys();
if (installed.length === 0) {
return false;
}

// CI already ran build:from-artifacts; avoid a strict second pass during partial dry runs.
if (process.env.CODRA_ALLOW_PARTIAL_BINARIES === '1') {
return true;
Comment on lines +59 to +60
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not skip the artifact rebuild after wrapper tests

In the default dry-run release path (publish=false, so CODRA_ALLOW_PARTIAL_BINARIES=1), the workflow runs npm test between build:from-artifacts and both npm pack steps; scripts/test.js then removes bin/native in its finally block and reruns build.js, leaving only the package runner's host binary. Because these lines return as soon as any installed binary exists, prepack skips rebuilding from the downloaded artifacts and the uploaded tarball can contain only linux-x64 instead of the partial release matrix (linux/darwin-arm64/windows). The pack dry-run also won't catch this when CODRA_EXPECT_PLATFORMS is empty for dry runs.

Useful? React with 👍 / 👎.

}

return false;
}

function packagingEnv() {
const env = { ...process.env };
const keys = [
'CODRA_USE_ARTIFACTS',
'CODRA_ARTIFACTS_DIR',
'CODRA_ALLOW_PARTIAL_BINARIES',
'CODRA_EXPECT_PLATFORMS',
'CODRA_EXPECT_ALL_PLATFORMS',
];
for (const key of keys) {
if (process.env[key] !== undefined) {
env[key] = process.env[key];
}
}
return env;
}

function main() {
if (shouldSkipArtifactRebuild()) {
console.log(
`[prepack] skip rebuild (${installedNativePlatformKeys().join(', ')} already in bin/native/)`,
);
return;
}

const script = shouldUseArtifacts()
? path.join(__dirname, 'build-platform-binaries.js')
: path.join(__dirname, 'build.js');

console.log(`[prepack] running ${path.basename(script)}`);
execSync(`node "${script}"`, { cwd: packageRoot, stdio: 'inherit' });
execSync(`node "${script}"`, { cwd: packageRoot, stdio: 'inherit', env: packagingEnv() });
}

main();
Loading