-
Notifications
You must be signed in to change notification settings - Fork 1
235 lines (192 loc) · 6.78 KB
/
release.yml
File metadata and controls
235 lines (192 loc) · 6.78 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
name: Release
# Triggers on tags like v1.0.0 and v1.0.0-beta
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
env:
CARGO_TERM_COLOR: always
BINARY_NAME: rustyochestrator
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-apple-darwin
os: macos-latest
archive: tar.gz
- target: x86_64-apple-darwin
os: macos-latest
archive: tar.gz
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
cross: true
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
archive: tar.gz
cross: true
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: zip
binary_suffix: .exe
steps:
- uses: actions/checkout@v4
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
if: matrix.cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
- name: Build (cross)
if: matrix.cross
run: cross build --release --target ${{ matrix.target }}
- name: Build (native)
if: "!matrix.cross"
run: cargo build --release --target ${{ matrix.target }}
- name: Package (tar.gz, Unix)
if: matrix.archive == 'tar.gz'
shell: bash
run: |
BINARY=target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}
ARCHIVE=${{ env.BINARY_NAME }}-${{ github.ref_name }}-${{ matrix.target }}.tar.gz
chmod +x "$BINARY"
tar -czf "$ARCHIVE" -C "$(dirname "$BINARY")" "$(basename "$BINARY")"
echo "ASSET=$ARCHIVE" >> "$GITHUB_ENV"
sha256sum "$ARCHIVE" > "$ARCHIVE.sha256"
- name: Package (zip, Windows)
if: matrix.archive == 'zip'
shell: pwsh
run: |
$binary = "target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe"
$archive = "${{ env.BINARY_NAME }}-${{ github.ref_name }}-${{ matrix.target }}.zip"
Compress-Archive -Path $binary -DestinationPath $archive
echo "ASSET=$archive" | Out-File -Append $env:GITHUB_ENV
$hash = (Get-FileHash $archive -Algorithm SHA256).Hash.ToLower()
"$hash $archive" | Out-File -Encoding ASCII "$archive.sha256"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: |
${{ env.ASSET }}
${{ env.ASSET }}.sha256
release:
name: Publish GitHub Release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
# 🔥 Extract changelog for this version from CHANGELOG.md
- name: Extract changelog
run: |
VERSION=${GITHUB_REF_NAME#v}
# Extract the section between this version header and the next version header (or EOF)
awk "/^## \\[${VERSION}\\]/{found=1; next} /^## \\[/{if(found) exit} found" CHANGELOG.md > CHANGELOG_GEN.md
# Fall back to git log if the version wasn't found in CHANGELOG.md
if [ ! -s CHANGELOG_GEN.md ]; then
echo "Version ${VERSION} not found in CHANGELOG.md, falling back to git log"
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREV_TAG" ]; then
git log --pretty=format:"- %s" > CHANGELOG_GEN.md
else
git log $PREV_TAG..HEAD --pretty=format:"- %s" > CHANGELOG_GEN.md
fi
fi
# 🔥 Generate install.sh
- name: Generate install script
run: |
cat << 'EOF' > install.sh
#!/usr/bin/env bash
set -e
REPO="${{ github.repository }}"
BINARY="rustyochestrator"
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Darwin) OS="apple-darwin" ;;
Linux) OS="unknown-linux-gnu" ;;
*) echo "Unsupported OS: $OS"; exit 1 ;;
esac
case "$ARCH" in
x86_64) ARCH="x86_64" ;;
arm64|aarch64) ARCH="aarch64" ;;
*) echo "Unsupported ARCH: $ARCH"; exit 1 ;;
esac
TARGET="$ARCH-$OS"
VERSION="${{ github.ref_name }}"
ARCHIVE="$BINARY-$VERSION-$TARGET.tar.gz"
URL="https://github.com/$REPO/releases/download/$VERSION/$ARCHIVE"
echo "Installing $BINARY $VERSION for $TARGET..."
curl -L "$URL" -o "$ARCHIVE"
tar -xzf "$ARCHIVE"
chmod +x "$BINARY"
sudo mv "$BINARY" /usr/local/bin/
echo "✅ Installed!"
EOF
chmod +x install.sh
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Generate combined checksums file
run: |
cat artifacts/*.sha256 > checksums.txt
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: "rustyochestrator ${{ github.ref_name }}"
body_path: CHANGELOG_GEN.md
files: |
artifacts/*
checksums.txt
install.sh
draft: false
prerelease: ${{ contains(github.ref_name, '-') }}
publish-crate:
name: Publish to crates.io
needs: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: Validate version matches tag
run: |
TAG_VERSION=${GITHUB_REF_NAME#v}
CARGO_VERSION=$(grep '^version' Cargo.toml | head -n1 | cut -d '"' -f2)
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "Version mismatch"
exit 1
fi
- name: Check token
run: |
if [ -z "${{ secrets.CARGO_REGISTRY_TOKEN }}" ]; then
echo "Missing token"
exit 1
fi
- name: Dry run
run: cargo publish --dry-run
- name: Publish
if: "!contains(github.ref_name, '-')"
run: cargo publish --locked --token $CARGO_REGISTRY_TOKEN || echo "Already published"
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}