Skip to content

Commit d3aec26

Browse files
committed
v0.4.4
1 parent 21439d2 commit d3aec26

File tree

1 file changed

+246
-0
lines changed

1 file changed

+246
-0
lines changed

.github/workflows/npm-publish.yml

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
name: Publish NPM Package
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
build-and-publish:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: '1.22'
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: '18'
26+
registry-url: 'https://registry.npmjs.org'
27+
28+
- name: Create npm package directory
29+
run: mkdir -p npm-package/bin
30+
31+
- name: Build binaries for all platforms
32+
run: |
33+
echo "Building ProofOfAccess binaries..."
34+
35+
# Build for macOS AMD64
36+
GOOS=darwin GOARCH=amd64 go build -o npm-package/bin/proofofaccess-darwin-amd64 main.go
37+
38+
# Build for macOS ARM64 (Apple Silicon)
39+
GOOS=darwin GOARCH=arm64 go build -o npm-package/bin/proofofaccess-darwin-arm64 main.go
40+
41+
# Build for Linux AMD64
42+
GOOS=linux GOARCH=amd64 go build -o npm-package/bin/proofofaccess-linux-amd64 main.go
43+
44+
# Build for Linux ARM64
45+
GOOS=linux GOARCH=arm64 go build -o npm-package/bin/proofofaccess-linux-arm64 main.go
46+
47+
# Build for Windows AMD64
48+
GOOS=windows GOARCH=amd64 go build -o npm-package/bin/proofofaccess-windows-amd64.exe main.go
49+
50+
# Generate checksums
51+
cd npm-package/bin
52+
sha256sum proofofaccess-* > checksums.txt
53+
cd ../..
54+
55+
# Make Unix binaries executable
56+
chmod +x npm-package/bin/proofofaccess-darwin-*
57+
chmod +x npm-package/bin/proofofaccess-linux-*
58+
59+
- name: Create npm package files
60+
run: |
61+
# Create package.json
62+
cat > npm-package/package.json << 'EOF'
63+
{
64+
"name": "@disregardfiat/proofofaccess",
65+
"version": "${GITHUB_REF#refs/tags/v}",
66+
"description": "ProofOfAccess binary for SPK Network storage validation",
67+
"main": "index.js",
68+
"bin": {
69+
"proofofaccess": "./install.js"
70+
},
71+
"scripts": {
72+
"postinstall": "node postinstall.js"
73+
},
74+
"keywords": ["spk", "proofofaccess", "storage", "validation", "ipfs"],
75+
"author": "SPK Network",
76+
"license": "MIT",
77+
"repository": {
78+
"type": "git",
79+
"url": "https://github.com/spknetwork/proofofaccess.git"
80+
},
81+
"files": [
82+
"index.js",
83+
"install.js",
84+
"postinstall.js",
85+
"bin/**/*",
86+
"README.md"
87+
],
88+
"os": ["darwin", "linux", "win32"],
89+
"cpu": ["x64", "arm64"]
90+
}
91+
EOF
92+
93+
# Update version in package.json
94+
VERSION=${GITHUB_REF#refs/tags/v}
95+
sed -i "s/\${GITHUB_REF#refs\/tags\/v}/$VERSION/g" npm-package/package.json
96+
97+
# Create index.js
98+
cat > npm-package/index.js << 'EOF'
99+
const path = require('path');
100+
const fs = require('fs');
101+
102+
function getBinaryPath() {
103+
const platform = process.platform;
104+
const arch = process.arch;
105+
106+
let binaryName;
107+
108+
if (platform === 'win32') {
109+
if (arch === 'x64') {
110+
binaryName = 'proofofaccess-windows-amd64.exe';
111+
} else {
112+
throw new Error(`Unsupported Windows architecture: ${arch}`);
113+
}
114+
} else if (platform === 'darwin') {
115+
if (arch === 'x64') {
116+
binaryName = 'proofofaccess-darwin-amd64';
117+
} else if (arch === 'arm64') {
118+
binaryName = 'proofofaccess-darwin-arm64';
119+
} else {
120+
throw new Error(`Unsupported macOS architecture: ${arch}`);
121+
}
122+
} else if (platform === 'linux') {
123+
if (arch === 'x64') {
124+
binaryName = 'proofofaccess-linux-amd64';
125+
} else if (arch === 'arm64') {
126+
binaryName = 'proofofaccess-linux-arm64';
127+
} else {
128+
throw new Error(`Unsupported Linux architecture: ${arch}`);
129+
}
130+
} else {
131+
throw new Error(`Unsupported platform: ${platform}`);
132+
}
133+
134+
const binaryPath = path.join(__dirname, 'bin', binaryName);
135+
136+
if (!fs.existsSync(binaryPath)) {
137+
throw new Error(`Binary not found at ${binaryPath}`);
138+
}
139+
140+
return binaryPath;
141+
}
142+
143+
module.exports = {
144+
getBinaryPath,
145+
146+
run: function(args = []) {
147+
const { spawn } = require('child_process');
148+
const binaryPath = getBinaryPath();
149+
150+
if (process.platform !== 'win32') {
151+
try {
152+
fs.chmodSync(binaryPath, 0o755);
153+
} catch (err) {
154+
// Ignore chmod errors
155+
}
156+
}
157+
158+
return spawn(binaryPath, args, {
159+
stdio: 'inherit'
160+
});
161+
}
162+
};
163+
EOF
164+
165+
# Create install.js with the fix
166+
cat > npm-package/install.js << 'EOF'
167+
#!/usr/bin/env node
168+
const fs = require('fs');
169+
const path = require('path');
170+
const { getBinaryPath } = require('./index');
171+
172+
if (require.main === module) {
173+
const { spawn } = require('child_process');
174+
try {
175+
const binaryPath = getBinaryPath();
176+
177+
// CRITICAL FIX: Make binary executable BEFORE trying to spawn it
178+
if (process.platform !== 'win32') {
179+
try {
180+
fs.chmodSync(binaryPath, 0o755);
181+
} catch (chmodError) {
182+
console.error(`Warning: Could not set execute permissions: ${chmodError.message}`);
183+
}
184+
}
185+
186+
const proc = spawn(binaryPath, process.argv.slice(2), {
187+
stdio: 'inherit'
188+
});
189+
190+
proc.on('error', (error) => {
191+
if (error.code === 'EACCES') {
192+
console.error(`Error: Binary at ${binaryPath} is not executable.`);
193+
console.error('Try running: chmod +x ' + binaryPath);
194+
} else {
195+
console.error('Error spawning process:', error.message);
196+
}
197+
process.exit(1);
198+
});
199+
200+
proc.on('exit', (code) => {
201+
process.exit(code || 0);
202+
});
203+
} catch (error) {
204+
console.error('Error:', error.message);
205+
process.exit(1);
206+
}
207+
}
208+
EOF
209+
210+
# Create postinstall.js
211+
cat > npm-package/postinstall.js << 'EOF'
212+
#!/usr/bin/env node
213+
const fs = require('fs');
214+
const path = require('path');
215+
216+
try {
217+
const { getBinaryPath } = require('./index');
218+
const binaryPath = getBinaryPath();
219+
220+
if (process.platform !== 'win32') {
221+
try {
222+
fs.chmodSync(binaryPath, 0o755);
223+
console.log(`✓ ProofOfAccess binary made executable: ${binaryPath}`);
224+
} catch (chmodError) {
225+
console.error(`⚠ Warning: Could not set execute permissions: ${chmodError.message}`);
226+
console.error(' You may need to manually run: chmod +x ' + binaryPath);
227+
}
228+
} else {
229+
console.log(`✓ ProofOfAccess binary installed: ${binaryPath}`);
230+
}
231+
} catch (error) {
232+
console.error('⚠ Warning: Could not find binary for your platform');
233+
console.error(' ' + error.message);
234+
process.exit(0);
235+
}
236+
EOF
237+
238+
# Copy README if it exists
239+
[ -f README.md ] && cp README.md npm-package/README.md || echo "No README.md found"
240+
241+
- name: Publish to NPM
242+
run: |
243+
cd npm-package
244+
npm publish --access public
245+
env:
246+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)