Skip to content

Commit 1d3ff96

Browse files
committed
make npm executable - try1
1 parent b3a4ff0 commit 1d3ff96

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,46 @@ jobs:
393393
pattern: artifacts-*
394394
path: npm/
395395
merge-multiple: true
396+
397+
# Patch npm packages to fix executable permissions
398+
# cargo-dist's binary-install.js does NOT set executable permissions after extracting binaries.
399+
# GitHub Actions artifact upload/download loses Unix permissions, so we patch the installer.
400+
- name: Patch npm packages for executable permissions
401+
run: |
402+
for pkg in npm/*-npm-package.tar.gz; do
403+
[ -f "$pkg" ] || continue
404+
echo "Patching $pkg for executable permissions..."
405+
406+
WORKDIR=$(mktemp -d)
407+
tar -xzf "$pkg" -C "$WORKDIR"
408+
409+
# Patch binary-install.js to chmod binary after extraction
410+
BINARY_INSTALL="$WORKDIR/package/binary-install.js"
411+
if [ -f "$BINARY_INSTALL" ]; then
412+
cat >> "$BINARY_INSTALL" << 'CHMOD_PATCH'
413+
414+
// Patch: Set executable permissions after binary extraction
415+
const _originalInstall = Binary.prototype.install;
416+
Binary.prototype.install = async function(proxy, suppressLogs) {
417+
await _originalInstall.call(this, proxy, suppressLogs);
418+
const fs = require('fs');
419+
const path = require('path');
420+
try {
421+
const binPath = path.join(this.installDirectory, this.binaryName);
422+
if (fs.existsSync(binPath)) {
423+
fs.chmodSync(binPath, 0o755);
424+
}
425+
} catch (e) { /* ignore chmod errors on Windows */ }
426+
};
427+
CHMOD_PATCH
428+
fi
429+
430+
# Repack the tarball
431+
rm "$pkg"
432+
tar -czf "$pkg" -C "$WORKDIR" package
433+
rm -rf "$WORKDIR"
434+
done
435+
396436
- uses: actions/setup-node@v4
397437
with:
398438
node-version: "20.x"

0 commit comments

Comments
 (0)