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