-
Notifications
You must be signed in to change notification settings - Fork 60
291 lines (258 loc) · 10.1 KB
/
Copy pathrelease.yml
File metadata and controls
291 lines (258 loc) · 10.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
name: Release
on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
bump:
description: "Version bump type (leave 'auto' to detect from commit messages)"
required: true
type: choice
default: auto
options:
- auto
- patch
- minor
- major
permissions:
contents: write
packages: write
env:
CARGO_TERM_COLOR: always
jobs:
# Manual dispatch path: bump Cargo.toml, commit, tag, push.
# Downstream jobs run in this same workflow run (keyed off needs.bump)
# because tag pushes signed by GITHUB_TOKEN don't cascade into a new
# workflow run — so we can't rely on the `push: tags` trigger firing.
bump:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-22.04
outputs:
new_tag: ${{ steps.version.outputs.tag }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Detect bump type from commits
id: detect
run: |
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
RANGE="HEAD"
else
RANGE="${LAST_TAG}..HEAD"
fi
COMMITS=$(git log --pretty=format:"%s" "$RANGE")
echo "## Commits since $LAST_TAG:"
echo "$COMMITS"
echo ""
BUMP="patch"
if echo "$COMMITS" | grep -qiE "^feat(\(.*\))?!:|BREAKING CHANGE"; then
BUMP="major"
elif echo "$COMMITS" | grep -qiE "^feat(\(.*\))?:"; then
BUMP="minor"
elif echo "$COMMITS" | grep -qiE "^(fix|perf)(\(.*\))?:"; then
BUMP="patch"
fi
echo "detected=$BUMP" >> "$GITHUB_OUTPUT"
echo "Detected bump: $BUMP"
- name: Resolve bump type
id: bump
run: |
if [ "${{ inputs.bump }}" = "auto" ]; then
BUMP="${{ steps.detect.outputs.detected }}"
else
BUMP="${{ inputs.bump }}"
fi
echo "type=$BUMP" >> "$GITHUB_OUTPUT"
echo "Using bump type: $BUMP"
- name: Compute new version
id: version
run: |
CURRENT=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)"/\1/')
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
case "${{ steps.bump.outputs.type }}" in
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
patch) PATCH=$((PATCH + 1)) ;;
esac
NEW="${MAJOR}.${MINOR}.${PATCH}"
echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
echo "new=$NEW" >> "$GITHUB_OUTPUT"
echo "tag=v${NEW}" >> "$GITHUB_OUTPUT"
- name: Summary
run: |
echo "### Release Summary" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "| | |" >> "$GITHUB_STEP_SUMMARY"
echo "|---|---|" >> "$GITHUB_STEP_SUMMARY"
echo "| **Current** | v${{ steps.version.outputs.current }} |" >> "$GITHUB_STEP_SUMMARY"
echo "| **New** | ${{ steps.version.outputs.tag }} |" >> "$GITHUB_STEP_SUMMARY"
echo "| **Bump** | ${{ steps.bump.outputs.type }} |" >> "$GITHUB_STEP_SUMMARY"
echo "| **Auto-detected** | ${{ steps.detect.outputs.detected }} |" >> "$GITHUB_STEP_SUMMARY"
- name: Bump Cargo.toml
run: sed -i "0,/^version = \".*\"/s//version = \"${{ steps.version.outputs.new }}\"/" Cargo.toml
- name: Update Cargo.lock
run: cargo generate-lockfile
- name: Commit, tag, and push
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Cargo.toml Cargo.lock
git commit -m "chore: release ${{ steps.version.outputs.tag }}"
git tag "${{ steps.version.outputs.tag }}"
git push origin main --tags
build-linux:
name: Build Linux (${{ matrix.target }})
needs: [bump]
if: |
always() &&
(startsWith(github.ref, 'refs/tags/') || needs.bump.result == 'success')
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
arch: x86_64
- target: aarch64-unknown-linux-gnu
arch: aarch64
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ needs.bump.outputs.new_tag || github.ref }}
- uses: dtolnay/rust-toolchain@e081816240890017053eacbb1bdf337761dc5582 # 1.95.0
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
with:
key: release-${{ matrix.target }}
- name: Install cross-compilation tools
if: matrix.arch == 'aarch64'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo '[target.aarch64-unknown-linux-gnu]' >> ~/.cargo/config.toml
echo 'linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml
- name: Build
run: |
T="${{ matrix.target }}"
cargo build --release --target $T --no-default-features --features fuse,vendored-openssl --bin hf-mount-fuse
cargo build --release --target $T --no-default-features --features fuse,vendored-openssl --bin hf-mount-fuse-sidecar
cargo build --release --target $T --no-default-features --features nfs,vendored-openssl --bin hf-mount-nfs
cargo build --release --target $T --no-default-features --features vendored-openssl --bin hf-mount
- name: Package
run: |
mkdir -p dist
for bin in hf-mount-fuse hf-mount-fuse-sidecar hf-mount-nfs hf-mount; do
cp target/${{ matrix.target }}/release/$bin dist/${bin}-${{ matrix.arch }}-linux
done
chmod +x dist/*
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: linux-${{ matrix.arch }}
path: dist/
build-macos:
name: Build macOS (${{ matrix.arch }})
needs: [bump]
if: |
always() &&
(startsWith(github.ref, 'refs/tags/') || needs.bump.result == 'success')
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
- arch: arm64
target: aarch64-apple-darwin
runner: macos-14
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ needs.bump.outputs.new_tag || github.ref }}
- uses: dtolnay/rust-toolchain@e081816240890017053eacbb1bdf337761dc5582 # 1.95.0
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
with:
key: ${{ matrix.target }}
- name: Install macFUSE
run: brew install macfuse
- name: Build
run: |
T="${{ matrix.target }}"
cargo build --release --target $T --no-default-features --features fuse,vendored-openssl --bin hf-mount-fuse
cargo build --release --target $T --no-default-features --features fuse,vendored-openssl --bin hf-mount-fuse-sidecar
cargo build --release --target $T --no-default-features --features nfs,vendored-openssl --bin hf-mount-nfs
cargo build --release --target $T --no-default-features --features vendored-openssl --bin hf-mount
- name: Package
run: |
mkdir -p dist
for bin in hf-mount-fuse hf-mount-fuse-sidecar hf-mount-nfs hf-mount; do
cp target/${{ matrix.target }}/release/$bin dist/${bin}-${{ matrix.arch }}-apple-darwin
done
chmod +x dist/*
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: macos-${{ matrix.arch }}
path: dist/
# Compute the docker tag base + whether to push :latest. A bumped
# release wins, then a manually-pushed tag, else fall back to sha-<sha>.
# `latest` only on stable releases (tag matches `v\d` and has no `-`).
docker-tag:
needs: [bump]
if: always() && needs.bump.result != 'failure'
runs-on: ubuntu-22.04
outputs:
base: ${{ steps.compute.outputs.base }}
push_latest: ${{ steps.compute.outputs.push_latest }}
steps:
- id: compute
run: |
NEW_TAG="${{ needs.bump.outputs.new_tag }}"
if [[ -n "$NEW_TAG" ]]; then
BASE="$NEW_TAG"
elif [[ "${GITHUB_REF}" == refs/tags/* ]]; then
BASE="${GITHUB_REF#refs/tags/}"
else
BASE="sha-${GITHUB_SHA}"
fi
PUSH_LATEST=false
if [[ "$BASE" =~ ^v[0-9] && "$BASE" != *"-"* ]]; then
PUSH_LATEST=true
fi
echo "base=$BASE" >> "$GITHUB_OUTPUT"
echo "push_latest=$PUSH_LATEST" >> "$GITHUB_OUTPUT"
docker:
needs: [bump, docker-tag]
if: always() && needs.docker-tag.result == 'success'
uses: ./.github/workflows/_docker-build.yml
with:
ref: ${{ needs.bump.outputs.new_tag || github.ref }}
tag_base: ${{ needs.docker-tag.outputs.base }}
push_latest: ${{ needs.docker-tag.outputs.push_latest == 'true' }}
release:
name: Create Release
needs: [bump, build-linux, build-macos]
if: |
always() &&
needs.build-linux.result == 'success' &&
needs.build-macos.result == 'success' &&
(startsWith(github.ref, 'refs/tags/') || needs.bump.result == 'success')
runs-on: ubuntu-22.04
steps:
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: artifacts
pattern: '{linux-*,macos-*}'
merge-multiple: true
- name: List artifacts
run: ls -lh artifacts/
- name: Create release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="${{ needs.bump.outputs.new_tag || github.ref_name }}"
gh release create "$TAG" artifacts/* \
--repo "${{ github.repository }}" \
--title "$TAG" \
--generate-notes