-
Notifications
You must be signed in to change notification settings - Fork 6
367 lines (312 loc) · 11.4 KB
/
ci.yml
File metadata and controls
367 lines (312 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
name: CI for OPNet Node
on:
push:
branches: [ '**' ]
tags:
- 'v*'
pull_request:
branches: [ main ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
node-version: [ 24.x, 25.x ]
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Update npm
run: npm install -g npm@latest
- name: Install dependencies
run: npm install
- name: Setup test config
run: cp src/config/btc.sample.conf src/config/btc.conf
- name: Build
run: npm run build
- name: Run tests
run: npm test
docker-build:
runs-on: ubuntu-latest
needs: build
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build Docker image (test)
uses: docker/build-push-action@v7
with:
context: .
file: ./docker/Dockerfile
push: false
tags: opnet-node:test
cache-from: type=gha
cache-to: type=gha,mode=max
release:
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
packages: write
id-token: write
attestations: write
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Resolve version strings
id: version
run: |
GIT_TAG="${{ github.ref_name }}"
# Map git tag to semver display version:
# Git tags use '-' as separator (git rejects '+'), but semver uses '+' for build metadata.
# Convention: the LAST '-' separated segment that is a known network name gets promoted to build metadata.
# e.g. v1.0.0-rc.0-testnet -> v1.0.0-rc.0+testnet
DISPLAY_VERSION="$GIT_TAG"
for NETWORK in testnet mainnet regtest; do
if [[ "$GIT_TAG" == *"-${NETWORK}" ]]; then
BASE="${GIT_TAG%-${NETWORK}}"
DISPLAY_VERSION="${BASE}+${NETWORK}"
break
fi
done
# Bare semver without the 'v' prefix (for Docker tags, tarballs, etc.)
SEMVER="${DISPLAY_VERSION#v}"
echo "git_tag=${GIT_TAG}" >> $GITHUB_OUTPUT
echo "display_version=${DISPLAY_VERSION}" >> $GITHUB_OUTPUT
echo "semver=${SEMVER}" >> $GITHUB_OUTPUT
echo "Resolved: git_tag=${GIT_TAG} -> display_version=${DISPLAY_VERSION} (semver=${SEMVER})"
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Install dependencies
run: npm install
- name: Setup config
run: cp src/config/btc.sample.conf src/config/btc.conf
- name: Build
run: npm run build
- name: Create release tarball
run: |
VERSION="${{ steps.version.outputs.git_tag }}"
RELEASE_DIR="opnet-node-${VERSION}"
mkdir -p "${RELEASE_DIR}"
# Copy built source and necessary files
cp -r build/src "${RELEASE_DIR}/"
cp build/index.js "${RELEASE_DIR}/"
cp build/index.d.ts "${RELEASE_DIR}/" 2>/dev/null || true
cp package.json "${RELEASE_DIR}/"
cp package-lock.json "${RELEASE_DIR}/"
cp README.md "${RELEASE_DIR}/"
cp LICENSE "${RELEASE_DIR}/" 2>/dev/null || true
cp -r config "${RELEASE_DIR}/" 2>/dev/null || true
# Create tarball and zip
tar -czvf "opnet-node-${VERSION}.tar.gz" "${RELEASE_DIR}"
zip -r "opnet-node-${VERSION}.zip" "${RELEASE_DIR}"
# Generate checksums
sha256sum "opnet-node-${VERSION}.tar.gz" > "opnet-node-${VERSION}.tar.gz.sha256"
sha256sum "opnet-node-${VERSION}.zip" > "opnet-node-${VERSION}.zip.sha256"
- name: Attest build provenance
uses: actions/attest-build-provenance@v4
with:
subject-path: |
opnet-node-${{ steps.version.outputs.git_tag }}.tar.gz
opnet-node-${{ steps.version.outputs.git_tag }}.zip
- name: Generate changelog
id: changelog
uses: mikepenz/release-changelog-builder-action@v6
with:
configurationJson: |
{
"categories": [
{
"title": "### Breaking Changes",
"labels": ["breaking", "breaking-change", "BREAKING-CHANGE"]
},
{
"title": "### Features",
"labels": ["feature", "feat", "enhancement"]
},
{
"title": "### Bug Fixes",
"labels": ["bug", "fix", "bugfix"]
},
{
"title": "### Performance",
"labels": ["performance", "perf"]
},
{
"title": "### Security",
"labels": ["security"]
},
{
"title": "### Consensus",
"labels": ["consensus"]
},
{
"title": "### Documentation",
"labels": ["documentation", "docs"]
},
{
"title": "### Dependencies",
"labels": ["dependencies", "deps"]
},
{
"title": "### Other Changes",
"labels": []
}
],
"sort": {
"order": "ASC",
"on_property": "mergedAt"
},
"template": "#{{CHANGELOG}}",
"pr_template": "- #{{TITLE}} ([#{{NUMBER}}](#{{URL}})) by @#{{AUTHOR}}",
"empty_template": "- No changes",
"max_tags_to_fetch": 200,
"max_pull_requests": 200,
"max_back_track_time_days": 365,
"tag_resolver": {
"method": "semver"
}
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update CHANGELOG.md
env:
CHANGELOG_CONTENT: ${{ steps.changelog.outputs.changelog }}
run: |
# Use display version (with +) in the changelog, not the git tag
TAG="${{ steps.version.outputs.display_version }}"
DATE=$(date +%Y-%m-%d)
NEW_HEADER="## [$TAG] - $DATE"
printf '%s\n' "$CHANGELOG_CONTENT" > /tmp/new_entry.md
if [ -f CHANGELOG.md ]; then
{
head -n 1 CHANGELOG.md
echo ""
echo "$NEW_HEADER"
echo ""
cat /tmp/new_entry.md
echo ""
tail -n +2 CHANGELOG.md
} > /tmp/CHANGELOG_NEW.md
mv /tmp/CHANGELOG_NEW.md CHANGELOG.md
else
{
echo "# Changelog"
echo ""
echo "All notable changes to this project will be documented in this file."
echo ""
echo "This changelog is automatically generated from merged pull requests."
echo ""
echo "$NEW_HEADER"
echo ""
cat /tmp/new_entry.md
} > CHANGELOG.md
fi
rm -f /tmp/new_entry.md
- name: Commit changelog
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin main
git checkout main
git add CHANGELOG.md
git diff --staged --quiet || git commit -m "docs: update CHANGELOG.md for ${{ steps.version.outputs.display_version }}"
git push origin main || echo "No changes to push or push failed"
- name: Determine if prerelease
id: prerelease
run: |
VERSION="${{ steps.version.outputs.git_tag }}"
if [[ "$VERSION" == *"-alpha"* ]] || [[ "$VERSION" == *"-beta"* ]] || [[ "$VERSION" == *"-rc"* ]]; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.version.outputs.git_tag }}
name: Release ${{ steps.version.outputs.display_version }}
body: |
${{ steps.changelog.outputs.changelog }}
## Installation
### From source tarball
```bash
tar -xzf opnet-node-${{ steps.version.outputs.git_tag }}.tar.gz
cd opnet-node-${{ steps.version.outputs.git_tag }}
npm install --production
npm start
```
### From Docker
```bash
docker pull ghcr.io/${{ github.repository }}:${{ steps.version.outputs.git_tag }}
# Copy and configure
cp docker/config/btc.conf.example docker/config/btc.conf
# Edit docker/config/btc.conf with your settings
# Run with docker-compose
cd docker && docker compose up -d
# Or run standalone
docker run -p 9000:9000 -p 9805:9805 -v $(pwd)/docker/config/btc.conf:/app/config/btc.conf ghcr.io/${{ github.repository }}:${{ steps.version.outputs.git_tag }}
```
## Checksums
See `.sha256` files for verification.
prerelease: ${{ steps.prerelease.outputs.is_prerelease == 'true' }}
generate_release_notes: false
files: |
opnet-node-${{ steps.version.outputs.git_tag }}.tar.gz
opnet-node-${{ steps.version.outputs.git_tag }}.tar.gz.sha256
opnet-node-${{ steps.version.outputs.git_tag }}.zip
opnet-node-${{ steps.version.outputs.git_tag }}.zip.sha256
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Container Registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.version.outputs.git_tag }}
type=raw,value=${{ steps.version.outputs.semver }}
type=raw,value=latest,enable=${{ !contains(steps.version.outputs.git_tag, '-') }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
file: ./docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64