1+ name : Build and Release (Alternative)
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*'
7+ workflow_dispatch :
8+ inputs :
9+ version :
10+ description : ' Release version (e.g., 0.2.0)'
11+ required : true
12+ type : string
13+
14+ permissions :
15+ contents : write
16+ packages : write
17+
18+ jobs :
19+ build-and-release :
20+ runs-on : ubuntu-latest
21+ outputs :
22+ version : ${{ steps.version.outputs.VERSION }}
23+ upload_url : ${{ steps.create_release.outputs.upload_url }}
24+ steps :
25+ - name : Checkout code
26+ uses : actions/checkout@v4
27+ with :
28+ fetch-depth : 0
29+
30+ - name : Set up Go
31+ uses : actions/setup-go@v5
32+ with :
33+ go-version : ' 1.21'
34+
35+ - name : Determine version
36+ id : version
37+ run : |
38+ if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
39+ VERSION="${{ github.event.inputs.version }}"
40+ elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
41+ VERSION="${{ github.ref_name }}"
42+ VERSION="${VERSION#v}"
43+ else
44+ LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
45+ VERSION=$(echo $LATEST_TAG | sed 's/v//' | awk -F. '{print $1"."$2"."$3+1}')
46+ fi
47+ echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
48+ echo "Building version: $VERSION"
49+
50+ - name : Build all binaries
51+ run : |
52+ VERSION="${{ steps.version.outputs.VERSION }}"
53+ BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
54+ COMMIT_ID=$(git rev-parse --short HEAD)
55+ LDFLAGS="-X main.Version=$VERSION -X main.BuildTime=$BUILD_TIME -X main.CommitID=$COMMIT_ID"
56+
57+ mkdir -p dist
58+
59+ # Build for all platforms
60+ GOOS=linux GOARCH=amd64 go build -ldflags "$LDFLAGS" -o dist/proofofaccess-linux-amd64 .
61+ GOOS=linux GOARCH=arm64 go build -ldflags "$LDFLAGS" -o dist/proofofaccess-linux-arm64 .
62+ GOOS=darwin GOARCH=amd64 go build -ldflags "$LDFLAGS" -o dist/proofofaccess-darwin-amd64 .
63+ GOOS=darwin GOARCH=arm64 go build -ldflags "$LDFLAGS" -o dist/proofofaccess-darwin-arm64 .
64+ GOOS=windows GOARCH=amd64 go build -ldflags "$LDFLAGS" -o dist/proofofaccess-windows-amd64.exe .
65+
66+ # Create checksums
67+ cd dist && sha256sum * > checksums.txt
68+
69+ # Create compressed archives for each platform
70+ tar -czf proofofaccess-linux-amd64.tar.gz proofofaccess-linux-amd64
71+ tar -czf proofofaccess-linux-arm64.tar.gz proofofaccess-linux-arm64
72+ tar -czf proofofaccess-darwin-amd64.tar.gz proofofaccess-darwin-amd64
73+ tar -czf proofofaccess-darwin-arm64.tar.gz proofofaccess-darwin-arm64
74+ zip proofofaccess-windows-amd64.zip proofofaccess-windows-amd64.exe
75+
76+ echo "Files created:"
77+ ls -la
78+
79+ - name : Create Release
80+ id : create_release
81+ uses : actions/create-release@v1
82+ env :
83+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
84+ with :
85+ tag_name : ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || format('v{0}', steps.version.outputs.VERSION) }}
86+ release_name : Release v${{ steps.version.outputs.VERSION }}
87+ body : |
88+ ## ProofOfAccess v${{ steps.version.outputs.VERSION }}
89+
90+ ### Installation
91+ 1. Download the appropriate archive for your platform
92+ 2. Extract: `tar -xzf proofofaccess-*.tar.gz` (or unzip for Windows)
93+ 3. Make executable: `chmod +x proofofaccess-*`
94+ 4. Run with `-version` flag to verify: `./proofofaccess -version`
95+
96+ ### Usage
97+ ```bash
98+ # Storage node
99+ ./proofofaccess -node 2 -username YOUR_USERNAME -IPFS_PORT=5001 -useWS -url=https://spktest.dlux.io
100+
101+ # Validator node
102+ ./proofofaccess -node 1 -username YOUR_USERNAME -IPFS_PORT=5001
103+ ```
104+
105+ ### Checksums
106+ SHA256 checksums are provided in `checksums.txt`
107+ draft : false
108+ prerelease : false
109+
110+ - name : Upload Linux AMD64
111+ uses : actions/upload-release-asset@v1
112+ env :
113+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
114+ with :
115+ upload_url : ${{ steps.create_release.outputs.upload_url }}
116+ asset_path : ./dist/proofofaccess-linux-amd64.tar.gz
117+ asset_name : proofofaccess-linux-amd64.tar.gz
118+ asset_content_type : application/gzip
119+
120+ - name : Upload Linux ARM64
121+ uses : actions/upload-release-asset@v1
122+ env :
123+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
124+ with :
125+ upload_url : ${{ steps.create_release.outputs.upload_url }}
126+ asset_path : ./dist/proofofaccess-linux-arm64.tar.gz
127+ asset_name : proofofaccess-linux-arm64.tar.gz
128+ asset_content_type : application/gzip
129+
130+ - name : Upload Darwin AMD64
131+ uses : actions/upload-release-asset@v1
132+ env :
133+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
134+ with :
135+ upload_url : ${{ steps.create_release.outputs.upload_url }}
136+ asset_path : ./dist/proofofaccess-darwin-amd64.tar.gz
137+ asset_name : proofofaccess-darwin-amd64.tar.gz
138+ asset_content_type : application/gzip
139+
140+ - name : Upload Darwin ARM64
141+ uses : actions/upload-release-asset@v1
142+ env :
143+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
144+ with :
145+ upload_url : ${{ steps.create_release.outputs.upload_url }}
146+ asset_path : ./dist/proofofaccess-darwin-arm64.tar.gz
147+ asset_name : proofofaccess-darwin-arm64.tar.gz
148+ asset_content_type : application/gzip
149+
150+ - name : Upload Windows AMD64
151+ uses : actions/upload-release-asset@v1
152+ env :
153+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
154+ with :
155+ upload_url : ${{ steps.create_release.outputs.upload_url }}
156+ asset_path : ./dist/proofofaccess-windows-amd64.zip
157+ asset_name : proofofaccess-windows-amd64.zip
158+ asset_content_type : application/zip
159+
160+ - name : Upload Checksums
161+ uses : actions/upload-release-asset@v1
162+ env :
163+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
164+ with :
165+ upload_url : ${{ steps.create_release.outputs.upload_url }}
166+ asset_path : ./dist/checksums.txt
167+ asset_name : checksums.txt
168+ asset_content_type : text/plain
169+
170+ - name : Upload artifacts for NPM
171+ uses : actions/upload-artifact@v4
172+ with :
173+ name : proofofaccess-binaries
174+ path : |
175+ dist/proofofaccess-*
176+ !dist/*.tar.gz
177+ !dist/*.zip
178+ retention-days : 7
179+
180+ publish-npm :
181+ needs : build-and-release
182+ runs-on : ubuntu-latest
183+ steps :
184+ - name : Setup Node.js
185+ uses : actions/setup-node@v4
186+ with :
187+ node-version : ' 18'
188+ registry-url : ' https://registry.npmjs.org'
189+
190+ - name : Download binaries
191+ uses : actions/download-artifact@v4
192+ with :
193+ name : proofofaccess-binaries
194+ path : npm-binaries
195+
196+ - name : Create NPM package
197+ run : |
198+ VERSION="${{ needs.build-and-release.outputs.version }}"
199+
200+ # Create package structure
201+ mkdir -p npm-package/bin
202+ cp npm-binaries/* npm-package/bin/ || true
203+
204+ # Create package.json
205+ cat > npm-package/package.json << EOF
206+ {
207+ "name": "@disregardfiat/proofofaccess",
208+ "version": "${VERSION}",
209+ "description": "ProofOfAccess binary for SPK Network storage validation",
210+ "main": "index.js",
211+ "bin": {
212+ "proofofaccess": "./install.js"
213+ },
214+ "scripts": {
215+ "postinstall": "node install.js"
216+ },
217+ "keywords": ["spk", "proofofaccess", "storage", "validation", "ipfs"],
218+ "author": "SPK Network",
219+ "license": "MIT",
220+ "repository": {
221+ "type": "git",
222+ "url": "https://github.com/spknetwork/proofofaccess.git"
223+ },
224+ "files": [
225+ "index.js",
226+ "install.js",
227+ "bin/**/*"
228+ ],
229+ "os": ["darwin", "linux", "win32"],
230+ "cpu": ["x64", "arm64"]
231+ }
232+ EOF
233+
234+ # Create index.js
235+ cat > npm-package/index.js << 'EOF'
236+ const path = require('path');
237+ const os = require('os');
238+ const fs = require('fs');
239+
240+ function getBinaryName() {
241+ const platform = os.platform();
242+ const arch = os.arch();
243+
244+ let platformName = platform === 'darwin' ? 'darwin' :
245+ platform === 'win32' ? 'windows' : 'linux';
246+ let archName = arch === 'x64' ? 'amd64' : 'arm64';
247+
248+ const ext = platform === 'win32' ? '.exe' : '';
249+ return `proofofaccess-${platformName}-${archName}${ext}`;
250+ }
251+
252+ function getBinaryPath() {
253+ const binaryName = getBinaryName();
254+ const binPath = path.join(__dirname, 'bin', binaryName);
255+
256+ if (!fs.existsSync(binPath)) {
257+ throw new Error(`Binary not found: ${binPath}`);
258+ }
259+
260+ return binPath;
261+ }
262+
263+ module.exports = {
264+ path: getBinaryPath(),
265+ getBinaryPath,
266+ getBinaryName
267+ };
268+ EOF
269+
270+ # Create install.js
271+ cat > npm-package/install.js << 'EOF'
272+ #!/usr/bin/env node
273+ const fs = require('fs');
274+ const path = require('path');
275+ const { getBinaryPath } = require('./index');
276+
277+ if (require.main === module) {
278+ const { spawn } = require('child_process');
279+ try {
280+ const binaryPath = getBinaryPath();
281+ const proc = spawn(binaryPath, process.argv.slice(2), {
282+ stdio: 'inherit'
283+ });
284+
285+ proc.on('exit', (code) => {
286+ process.exit(code);
287+ });
288+ } catch (error) {
289+ console.error('Error:', error.message);
290+ process.exit(1);
291+ }
292+ } else {
293+ try {
294+ const binaryPath = getBinaryPath();
295+
296+ if (process.platform !== 'win32') {
297+ fs.chmodSync(binaryPath, 0o755);
298+ }
299+
300+ console.log(`ProofOfAccess binary installed: ${binaryPath}`);
301+ } catch (error) {
302+ console.error('Warning: Could not find binary for your platform');
303+ console.error(error.message);
304+ }
305+ }
306+ EOF
307+
308+ chmod +x npm-package/install.js
309+
310+ - name : Publish to NPM
311+ env :
312+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
313+ working-directory : npm-package
314+ run : |
315+ npm publish --access public
0 commit comments