-
-
Notifications
You must be signed in to change notification settings - Fork 2
450 lines (399 loc) · 14.7 KB
/
Copy pathrelease.yml
File metadata and controls
450 lines (399 loc) · 14.7 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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
name: Release
on:
push:
branches:
- main
paths:
- 'cli/**.rs'
- 'cli/Cargo.toml'
- 'cli/Cargo.lock'
workflow_dispatch:
inputs:
bump_type:
description: 'Version bump type'
required: false
type: choice
default: 'none'
options:
- none
- patch
- minor
- major
force_version:
description: 'Force a specific version (e.g., 0.1.1)'
required: false
type: string
skip_tests:
description: 'Skip tests (use with caution)'
required: false
type: boolean
default: false
bump_only:
description: 'Only bump the version and skip build/release steps'
required: false
type: boolean
default: false
permissions:
contents: write
packages: write
pull-requests: write
actions: write
env:
CARGO_TERM_COLOR: always
jobs:
test:
name: Run tests
if: ${{ !inputs.skip_tests && !inputs.bump_only }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup workspace dependencies
run: |
chmod +x scripts/setup-workspace.sh
./scripts/setup-workspace.sh
- name: Install protoc
uses: arduino/setup-protoc@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.91.0
- name: Run tests
run: cd cli && cargo test --all-features
check-version:
name: Check if version needs bump
needs: [test]
if: ${{ always() && (needs.test.result == 'success' || needs.test.result == 'skipped') }}
runs-on: ubuntu-latest
outputs:
needs_bump: ${{ steps.check.outputs.needs_bump }}
current_version: ${{ steps.check.outputs.current_version }}
new_version: ${{ steps.check.outputs.new_version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup workspace dependencies
run: |
chmod +x scripts/setup-workspace.sh
./scripts/setup-workspace.sh
- name: Check version
id: check
shell: bash
run: |
# Check if force_version is provided
if [[ -n "${{ github.event.inputs.force_version }}" ]]; then
CURRENT_VERSION=$(grep '^version = ' cli/Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
NEW_VERSION="${{ github.event.inputs.force_version }}"
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
if [[ "$CURRENT_VERSION" != "$NEW_VERSION" ]]; then
echo "needs_bump=true" >> $GITHUB_OUTPUT
echo "Forcing version from $CURRENT_VERSION to $NEW_VERSION"
else
echo "needs_bump=false" >> $GITHUB_OUTPUT
echo "Version is already $NEW_VERSION"
fi
# Check if manual bump_type is provided
elif [[ "${{ github.event.inputs.bump_type }}" != "" && "${{ github.event.inputs.bump_type }}" != "none" ]]; then
CURRENT_VERSION=$(grep '^version = ' cli/Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Calculate new version based on bump type
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR="${VERSION_PARTS[0]}"
MINOR="${VERSION_PARTS[1]}"
PATCH="${VERSION_PARTS[2]}"
case "${{ github.event.inputs.bump_type }}" in
major)
NEW_VERSION="$((MAJOR + 1)).0.0"
;;
minor)
NEW_VERSION="$MAJOR.$((MINOR + 1)).0"
;;
patch)
NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
;;
esac
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "needs_bump=true" >> $GITHUB_OUTPUT
echo "Manual bump requested: ${{ github.event.inputs.bump_type }} (from $CURRENT_VERSION to $NEW_VERSION)"
else
# Get current version from Cargo.toml
CURRENT_VERSION=$(grep '^version = ' cli/Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Check if this version has been published already
if git tag | grep -q "v$CURRENT_VERSION"; then
echo "Version $CURRENT_VERSION already exists, bumping patch version"
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR="${VERSION_PARTS[0]}"
MINOR="${VERSION_PARTS[1]}"
PATCH="${VERSION_PARTS[2]}"
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "needs_bump=true" >> $GITHUB_OUTPUT
else
echo "Version $CURRENT_VERSION is new"
echo "new_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "needs_bump=false" >> $GITHUB_OUTPUT
fi
fi
bump-version:
name: Bump version if needed
runs-on: ubuntu-latest
needs: check-version
if: needs.check-version.outputs.needs_bump == 'true'
outputs:
version: ${{ needs.check-version.outputs.new_version }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup workspace dependencies
run: |
chmod +x scripts/setup-workspace.sh
./scripts/setup-workspace.sh
- name: Update version in Cargo.toml
shell: bash
run: |
# Only update the package version (line 3), not dependency versions
sed -i '3s/^version = .*/version = "${{ needs.check-version.outputs.new_version }}"/' cli/Cargo.toml
# Update Cargo.lock
cd cli && cargo update --workspace
- name: Commit version bump
shell: bash
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git add cli/Cargo.toml cli/Cargo.lock
git commit -m "chore: bump version to ${{ needs.check-version.outputs.new_version }} [skip ci]"
git push
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
needs: [check-version, bump-version]
if: |
always() &&
!inputs.bump_only &&
needs.check-version.result == 'success' &&
(needs.bump-version.result == 'success' || needs.bump-version.result == 'skipped')
strategy:
matrix:
include:
# Linux
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
binary: bv
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
binary: bv
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
binary: bv
# macOS
- os: macos-latest
target: x86_64-apple-darwin
binary: bv
- os: macos-latest
target: aarch64-apple-darwin
binary: bv
# Windows
- os: windows-latest
target: x86_64-pc-windows-msvc
binary: bv.exe
- os: windows-latest
target: aarch64-pc-windows-msvc
binary: bv.exe
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Setup workspace dependencies (Unix)
if: runner.os != 'Windows'
run: |
chmod +x scripts/setup-workspace.sh
./scripts/setup-workspace.sh
- name: Setup workspace dependencies (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$repoRoot = (Resolve-Path ".").Path
$parentDir = Split-Path $repoRoot -Parent
git config --global url."https://github.com/".insteadOf "git@github.com:"
function Clone-IfMissing($name, $url, $branch = $null) {
$dest = Join-Path $parentDir $name
if (Test-Path $dest) {
Write-Host "$name already exists at $dest"
} else {
Write-Host "Cloning $name to $dest..."
if ($branch) {
git clone -b $branch $url $dest
} else {
git clone $url $dest
}
}
}
Clone-IfMissing "syftbox-sdk" "https://github.com/OpenMined/syftbox-sdk.git"
Clone-IfMissing "syft-crypto-core" "https://github.com/OpenMined/syft-crypto-core.git"
Clone-IfMissing "syftbox" "https://github.com/OpenMined/syftbox.git" "madhava/biovault"
Clone-IfMissing "biovault-beaver" "https://github.com/OpenMined/biovault-beaver.git"
Clone-IfMissing "sbenv" "https://github.com/OpenMined/sbenv.git"
Clone-IfMissing "bioscript" "https://github.com/OpenMined/bioscript.git"
function Create-Junction($name) {
$link = Join-Path $repoRoot $name
$target = Join-Path $parentDir $name
if (-not (Test-Path $link)) {
cmd /c mklink /J $link $target
Write-Host "Created junction: $name -> $target"
}
}
Create-Junction "syftbox-sdk"
Create-Junction "syft-crypto-core"
Create-Junction "syftbox"
Create-Junction "biovault-beaver"
Create-Junction "sbenv"
Create-Junction "bioscript"
- name: Install protoc
uses: arduino/setup-protoc@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.91.0
targets: ${{ matrix.target }}
- name: Ensure target installed
run: rustup target add ${{ matrix.target }}
- name: Install cross-compilation tools
if: matrix.os == 'ubuntu-latest'
run: |
if [[ "${{ matrix.target }}" == "x86_64-unknown-linux-musl" ]]; then
sudo apt-get update
sudo apt-get install -y musl-tools
elif [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]]; then
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
fi
- name: Configure cargo target linker
if: matrix.os == 'ubuntu-latest'
shell: bash
run: |
mkdir -p ~/.cargo
cfg=~/.cargo/config.toml
if [[ "${{ matrix.target }}" == "x86_64-unknown-linux-musl" ]]; then
printf '[target.x86_64-unknown-linux-musl]\nlinker = "musl-gcc"\n' >> "$cfg"
elif [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]]; then
printf '[target.aarch64-unknown-linux-gnu]\nlinker = "aarch64-linux-gnu-gcc"\n' >> "$cfg"
fi
- name: Build
shell: bash
run: |
cd cli
cargo build --release --target ${{ matrix.target }}
- name: Package binary
shell: bash
run: |
cd cli/target/${{ matrix.target }}/release
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
7z a ../../../../bv-${{ matrix.target }}.zip ${{ matrix.binary }}
else
tar czf ../../../../bv-${{ matrix.target }}.tar.gz ${{ matrix.binary }}
fi
cd -
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: bv-${{ matrix.target }}
path: |
bv-${{ matrix.target }}.tar.gz
bv-${{ matrix.target }}.zip
publish-crate:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: [build, check-version, bump-version]
if: |
always() &&
!inputs.bump_only &&
needs.build.result == 'success' &&
(needs.bump-version.result == 'success' || needs.bump-version.result == 'skipped')
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Setup workspace dependencies
run: |
chmod +x scripts/setup-workspace.sh
./scripts/setup-workspace.sh
- name: Install protoc
uses: arduino/setup-protoc@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.91.0
- name: Publish to crates.io
run: cd cli && cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
continue-on-error: true
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [build, check-version, bump-version, publish-crate]
if: |
always() &&
!inputs.bump_only &&
needs.build.result == 'success' &&
(needs.bump-version.result == 'success' || needs.bump-version.result == 'skipped')
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Setup workspace dependencies
run: |
chmod +x scripts/setup-workspace.sh
./scripts/setup-workspace.sh
- name: Get final version
id: version
shell: bash
run: |
VERSION=$(grep '^version = ' cli/Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.version }}
release_name: Release v${{ steps.version.outputs.version }}
draft: false
prerelease: false
body: |
# BioVault v${{ steps.version.outputs.version }}
## Installation
### Using curl (macOS/Linux)
```bash
curl -fsSL https://raw.githubusercontent.com/${{ github.repository }}/main/install.sh | sh
```
### Using Cargo
```bash
cargo install biovault
```
- name: Upload Release Assets
run: |
for file in artifacts/*/*.{tar.gz,zip}; do
if [ -f "$file" ]; then
asset_name=$(basename "$file")
echo "Uploading $asset_name"
gh release upload v${{ steps.version.outputs.version }} "$file" \
--repo ${{ github.repository }}
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}