-
Notifications
You must be signed in to change notification settings - Fork 0
245 lines (211 loc) · 7.89 KB
/
release.yml
File metadata and controls
245 lines (211 loc) · 7.89 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
# Release workflow
#
# Triggered when a version tag is pushed (e.g., v0.1.0).
# Builds release binaries for multiple platforms and creates a GitHub release.
name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-*" # Pre-releases like v0.1.0-beta.1
env:
CARGO_TERM_COLOR: always
BINARY_NAME: iggy-sample
permissions:
contents: write
jobs:
# ==========================================================================
# Validate release
# ==========================================================================
validate:
name: Validate Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
is_prerelease: ${{ steps.version.outputs.is_prerelease }}
steps:
- uses: actions/checkout@v4
- name: Extract version info
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Check if this is a pre-release
if [[ "$VERSION" == *"-"* ]]; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
echo "Version: $VERSION"
- name: Verify Cargo.toml version matches tag
run: |
CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | cut -d'"' -f2)
TAG_VERSION=${{ steps.version.outputs.version }}
# Strip pre-release suffix for comparison
TAG_VERSION_BASE=${TAG_VERSION%%-*}
if [[ "$CARGO_VERSION" != "$TAG_VERSION_BASE" ]]; then
echo "::error::Version mismatch: Cargo.toml has $CARGO_VERSION, tag is $TAG_VERSION_BASE"
exit 1
fi
echo "Version verified: $CARGO_VERSION"
# ==========================================================================
# Build release binaries
# ==========================================================================
build:
name: Build (${{ matrix.target }})
runs-on: ${{ matrix.os }}
needs: [validate]
strategy:
fail-fast: false
matrix:
include:
# Linux x86_64
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
# Linux ARM64
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
cross: true
# macOS x86_64
- target: x86_64-apple-darwin
os: macos-latest
archive: tar.gz
# macOS ARM64 (Apple Silicon)
- target: aarch64-apple-darwin
os: macos-latest
archive: tar.gz
# Windows x86_64
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: zip
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: release-${{ matrix.target }}
# Install cross for cross-compilation
- name: Install cross
if: matrix.cross
run: cargo install cross --git https://github.com/cross-rs/cross
# Build with cross or cargo
- name: Build release binary
run: |
if [ "${{ matrix.cross }}" = "true" ]; then
cross build --release --target ${{ matrix.target }}
else
cargo build --release --target ${{ matrix.target }}
fi
shell: bash
# Package the binary
- name: Package (Unix)
if: matrix.os != 'windows-latest'
run: |
mkdir -p dist
cp target/${{ matrix.target }}/release/${{ env.BINARY_NAME }} dist/
cp README.md LICENSE* dist/ 2>/dev/null || true
cd dist
tar -czvf ../${{ env.BINARY_NAME }}-${{ needs.validate.outputs.version }}-${{ matrix.target }}.tar.gz *
- name: Package (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path dist
Copy-Item "target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe" -Destination dist/
Copy-Item README.md -Destination dist/ -ErrorAction SilentlyContinue
Copy-Item LICENSE* -Destination dist/ -ErrorAction SilentlyContinue
Compress-Archive -Path dist/* -DestinationPath "${{ env.BINARY_NAME }}-${{ needs.validate.outputs.version }}-${{ matrix.target }}.zip"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.BINARY_NAME }}-${{ matrix.target }}
path: ${{ env.BINARY_NAME }}-${{ needs.validate.outputs.version }}-${{ matrix.target }}.*
# ==========================================================================
# Create GitHub Release
# ==========================================================================
release:
name: Create Release
runs-on: ubuntu-latest
needs: [validate, build]
environment: release # Requires manual approval in GitHub settings
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Generate changelog
id: changelog
run: |
# Get the previous tag
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$PREV_TAG" ]; then
echo "Generating changelog since $PREV_TAG"
CHANGELOG=$(git log --pretty=format:"- %s (%h)" $PREV_TAG..HEAD)
else
echo "No previous tag found, using all commits"
CHANGELOG=$(git log --pretty=format:"- %s (%h)" HEAD~20..HEAD)
fi
# Save to file for release body
echo "$CHANGELOG" > CHANGELOG.md
echo "Generated changelog with $(wc -l < CHANGELOG.md) entries"
- name: Create release
uses: softprops/action-gh-release@v1
with:
name: Release v${{ needs.validate.outputs.version }}
body_path: CHANGELOG.md
prerelease: ${{ needs.validate.outputs.is_prerelease == 'true' }}
files: artifacts/**/*
generate_release_notes: true
# ==========================================================================
# Publish to crates.io (optional)
# ==========================================================================
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: [validate, release]
# Only publish stable releases
if: needs.validate.outputs.is_prerelease == 'false'
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CRATES_IO_TOKEN }}
continue-on-error: true # Don't fail if already published
# ==========================================================================
# Deploy documentation
# ==========================================================================
docs:
name: Deploy Documentation
runs-on: ubuntu-latest
needs: [validate, release]
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Build documentation
run: cargo doc --no-deps --all-features
env:
RUSTDOCFLAGS: --cfg docsrs
- name: Add redirect to index
run: echo '<meta http-equiv="refresh" content="0; url=iggy_sample/index.html">' > target/doc/index.html
- name: Upload pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: target/doc
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4