-
Notifications
You must be signed in to change notification settings - Fork 6
330 lines (288 loc) · 12.1 KB
/
release.yml
File metadata and controls
330 lines (288 loc) · 12.1 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
name: Release
run-name: Release ${{ github.ref_name }}
on:
push:
tags:
- "v*"
concurrency:
group: release
cancel-in-progress: false
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
# ── Validate tag ─────────────────────────────────────────────────────────────
validate-version:
name: Validate Version Tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
is_full_release: ${{ steps.version.outputs.is_full_release }}
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Validate tag against Cargo.toml
id: version
run: |
TAG="${GITHUB_REF_NAME}"
TAG_VERSION="${TAG#v}"
CARGO_VERSION=$(cargo metadata --no-deps --format-version=1 \
| jq -r '.packages[] | select(.name == "nodedb-types") | .version')
CARGO_BASE=$(echo "$CARGO_VERSION" | grep -oP '^\d+\.\d+\.\d+')
echo "Tag version: $TAG_VERSION"
echo "Cargo.toml version: $CARGO_VERSION"
echo "Cargo.toml base: $CARGO_BASE"
if [[ ! "$TAG_VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+)(-[a-zA-Z]+\.[0-9]+)?$ ]]; then
echo "::error::Invalid tag format '$TAG'. Expected: vX.Y.Z or vX.Y.Z-label.N"
exit 1
fi
TAG_BASE="${BASH_REMATCH[1]}"
if [[ "$TAG_BASE" != "$CARGO_BASE" ]]; then
echo "::error::Base version mismatch! Tag '$TAG_BASE' != Cargo.toml '$CARGO_BASE'"
exit 1
fi
# Full release = no hyphen suffix (v0.0.1, not v0.0.1-beta.1)
if [[ "$TAG_VERSION" == *-* ]]; then
echo "is_full_release=false" >> "$GITHUB_OUTPUT"
else
echo "is_full_release=true" >> "$GITHUB_OUTPUT"
fi
echo "version=$TAG_VERSION" >> "$GITHUB_OUTPUT"
# ── CI gate ──────────────────────────────────────────────────────────────────
ci:
name: CI Gate
needs: validate-version
uses: ./.github/workflows/ci.yml
# ── Publish crates to crates.io ──────────────────────────────────────────────
# Requires secret: CARGO_REGISTRY_TOKEN
# All 4 tiers run in a single job with is_published checks and wait_for polling
# so re-running a failed publish never double-publishes an already-indexed crate.
publish-crates:
name: Publish to crates.io
needs: [validate-version, ci]
runs-on: ubuntu-latest
environment: crates.io
permissions:
contents: read
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install system deps
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
cmake clang libclang-dev pkg-config protobuf-compiler perl \
libcurl4-openssl-dev libsasl2-dev
- name: Set version from tag
run: |
VERSION="${{ needs.validate-version.outputs.version }}"
CURRENT=$(cargo metadata --no-deps --format-version=1 \
| jq -r '.packages[] | select(.name == "nodedb-types") | .version')
if [[ "$VERSION" != "$CURRENT" ]]; then
sed -i "0,/^version = \".*\"/s//version = \"$VERSION\"/" Cargo.toml
# For pre-release versions, pin internal dep requirements so semver
# "0.0.0" doesn't fail to match "0.0.0-beta.1"
if [[ "$VERSION" == *-* ]]; then
sed -i -E 's/(nodedb-(codec|bridge|wal|mem|crdt|raft|fts|types|vector|graph|spatial|strict|client|columnar|cluster|query|sql) = \{ [^}]*version = )"[^"]*"/\1"='"$VERSION"'"/' Cargo.toml
echo "Updated internal dep versions to =$VERSION"
fi
echo "Updated workspace version: $CURRENT -> $VERSION"
else
echo "Version already matches, no change needed"
fi
- name: Publish crates
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
# Tier 1: no internal NodeDB dependencies
TIER1="nodedb-codec nodedb-bridge nodedb-wal nodedb-mem nodedb-crdt nodedb-raft nodedb-fts"
# Tier 2: depends on tier 1 only
TIER2="nodedb-types"
# Tier 3: depends on tier 1-2
TIER3="nodedb-vector nodedb-graph nodedb-spatial nodedb-strict nodedb-client nodedb-sql nodedb-columnar nodedb-cluster"
# Tier 4: depends on tier 3 (nodedb-spatial)
TIER4="nodedb-query"
is_published() {
curl -sf \
-H "User-Agent: nodedb-ci (github.com/NodeDB-Lab/nodedb)" \
"https://crates.io/api/v1/crates/$1/$2" > /dev/null 2>&1
}
wait_for() {
local crate="$1" version="$2"
echo -n " Waiting for $crate@$version..."
for i in $(seq 1 30); do
if is_published "$crate" "$version"; then
echo " ready"
return 0
fi
sleep 5
done
echo " timed out!"
return 1
}
publish_tier() {
local tier_name="$1"; shift
local crates=("$@")
local need_wait=()
echo "::group::Tier: $tier_name"
for crate in "${crates[@]}"; do
VERSION=$(cargo metadata --no-deps --format-version=1 \
| jq -r --arg name "$crate" '.packages[] | select(.name == $name) | .version')
if is_published "$crate" "$VERSION"; then
echo " $crate@$VERSION already published — skipping"
else
echo " Publishing $crate@$VERSION..."
cargo publish -p "$crate" --allow-dirty
need_wait+=("$crate:$VERSION")
fi
done
for entry in "${need_wait[@]}"; do
wait_for "${entry%%:*}" "${entry##*:}"
done
echo "::endgroup::"
}
publish_tier "1 (no internal deps)" $TIER1
publish_tier "2 (depends on tier 1)" $TIER2
publish_tier "3 (depends on tier 2)" $TIER3
publish_tier "4 (depends on tier 3)" $TIER4
# ── Build nodedb server binary (Linux only — requires io_uring) ──────────────
build-server:
name: Build server (${{ matrix.label }})
needs: [validate-version, ci]
runs-on: ${{ matrix.runs-on }}
strategy:
fail-fast: false
matrix:
include:
- runs-on: ubuntu-latest
target: x86_64-unknown-linux-gnu
label: linux-x64
- runs-on: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
label: linux-arm64
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
prefix-key: server-${{ matrix.target }}
- name: Install system deps
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
cmake clang libclang-dev pkg-config protobuf-compiler perl \
libcurl4-openssl-dev libsasl2-dev
- name: Set version from tag
run: |
VERSION="${{ needs.validate-version.outputs.version }}"
CURRENT=$(cargo metadata --no-deps --format-version=1 \
| jq -r '.packages[] | select(.name == "nodedb-types") | .version')
if [[ "$VERSION" != "$CURRENT" ]]; then
perl -i -pe "if (!\$done && /^version = \"/) { s/^version = \".*\"/version = \"$VERSION\"/; \$done=1 }" Cargo.toml
# For pre-release versions, pin internal dep requirements so semver
# "0" doesn't fail to match "0.0.0-beta.3"
if [[ "$VERSION" == *-* ]]; then
sed -i -E 's/(nodedb-(codec|bridge|wal|mem|crdt|raft|fts|types|vector|graph|spatial|strict|client|columnar|cluster|query|sql) = \{ [^}]*version = )"[^"]*"/\1"='"$VERSION"'"/' Cargo.toml
echo "Updated internal dep versions to =$VERSION"
fi
echo "Updated workspace version: $CURRENT -> $VERSION"
fi
- name: Build server binary
run: cargo build -p nodedb --release --target ${{ matrix.target }}
- name: Package
run: |
cd target/${{ matrix.target }}/release
chmod +x nodedb
tar czf nodedb-${{ needs.validate-version.outputs.version }}-${{ matrix.label }}.tar.gz nodedb
ls -lh nodedb-*.tar.gz
- uses: actions/upload-artifact@v7
with:
name: server-${{ matrix.label }}
path: target/${{ matrix.target }}/release/nodedb-*.tar.gz
retention-days: 1
# ── Create GitHub Release ─────────────────────────────────────────────────────
github-release:
name: Create GitHub Release
needs: [validate-version, publish-crates, build-server]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Download binary artifacts
uses: actions/download-artifact@v8
with:
path: ./artifacts
pattern: "server-*"
merge-multiple: true
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.validate-version.outputs.version }}
name: NodeDB ${{ needs.validate-version.outputs.version }}
generate_release_notes: true
draft: false
prerelease: ${{ contains(needs.validate-version.outputs.version, '-') }}
files: artifacts/*
fail_on_unmatched_files: true
# ── Build and push Docker image (full releases only) ──────────────────────────
# Uses native runners per arch (no QEMU), then merges into a multi-arch manifest.
docker-build:
name: Docker build (${{ matrix.label }})
needs: [validate-version, ci]
if: needs.validate-version.outputs.is_full_release == 'true'
runs-on: ${{ matrix.runs-on }}
strategy:
fail-fast: false
matrix:
include:
- runs-on: ubuntu-latest
platform: linux/amd64
label: amd64
- runs-on: ubuntu-24.04-arm
platform: linux/arm64
label: arm64
steps:
- uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push platform image
uses: docker/build-push-action@v7
with:
context: .
platforms: ${{ matrix.platform }}
push: true
tags: farhansyah/nodedb:${{ needs.validate-version.outputs.version }}-${{ matrix.label }}
cache-from: type=gha,scope=${{ matrix.label }}
cache-to: type=gha,scope=${{ matrix.label }},mode=max
docker-manifest:
name: Docker manifest
needs: [validate-version, docker-build]
if: needs.validate-version.outputs.is_full_release == 'true'
runs-on: ubuntu-latest
steps:
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create and push multi-arch manifest
env:
VERSION: ${{ needs.validate-version.outputs.version }}
run: |
docker buildx imagetools create \
--tag farhansyah/nodedb:${VERSION} \
--tag farhansyah/nodedb:latest \
farhansyah/nodedb:${VERSION}-amd64 \
farhansyah/nodedb:${VERSION}-arm64