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
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
permissions:
contents: write
jobs:
build:
name: Build for ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
artifact_name: cc-switch-x86_64-unknown-linux-gnu.tar.gz
binary_name: cc-switch
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
artifact_name: cc-switch-aarch64-unknown-linux-gnu.tar.gz
binary_name: cc-switch
- target: x86_64-apple-darwin
os: macos-latest
artifact_name: cc-switch-x86_64-apple-darwin.tar.gz
binary_name: cc-switch
- target: aarch64-apple-darwin
os: macos-latest
artifact_name: cc-switch-aarch64-apple-darwin.tar.gz
binary_name: cc-switch
- target: x86_64-pc-windows-msvc
os: windows-latest
artifact_name: cc-switch-x86_64-pc-windows-msvc.zip
binary_name: cc-switch.exe
- target: aarch64-pc-windows-msvc
os: windows-latest
artifact_name: cc-switch-aarch64-pc-windows-msvc.zip
binary_name: cc-switch.exe
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Cache cargo + target
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Add Linux dependencies
if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Set up cross compilation environment
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Build for ${{ matrix.target }}
run: |
cargo build --release --target ${{ matrix.target }}
- name: Package artifacts (Unix)
if: matrix.os != 'windows-latest'
shell: bash
run: |
mkdir -p dist/${{ matrix.target }}
cp target/${{ matrix.target }}/release/${{ matrix.binary_name }} dist/${{ matrix.target }}/${{ matrix.binary_name }}
cd dist/${{ matrix.target }}
tar -czf ../../${{ matrix.artifact_name }} ${{ matrix.binary_name }}
- name: Package artifacts (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
$stage = "dist/${{ matrix.target }}"
New-Item -ItemType Directory -Force -Path $stage | Out-Null
Copy-Item "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" "$stage/${{ matrix.binary_name }}"
Compress-Archive -Path "$stage/${{ matrix.binary_name }}" -DestinationPath "${{ matrix.artifact_name }}" -Force
- name: Generate SHA256 sidecar (Unix)
if: matrix.os != 'windows-latest'
shell: bash
run: |
shasum -a 256 ${{ matrix.artifact_name }} | awk '{print $1}' > ${{ matrix.artifact_name }}.sha256
- name: Generate SHA256 sidecar (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
$hash = (Get-FileHash -Algorithm SHA256 "${{ matrix.artifact_name }}").Hash.ToLower()
Set-Content -Path "${{ matrix.artifact_name }}.sha256" -Value $hash -NoNewline
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: |
${{ matrix.artifact_name }}
${{ matrix.artifact_name }}.sha256
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Generate Release Notes
id: notes
run: |
VERSION="${GITHUB_REF#refs/tags/}"
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Build changelog
CHANGELOG="## What's Changed in $VERSION"
CHANGELOG="$CHANGELOG\n"
if [ -n "$PREV_TAG" ]; then
# Get commits between previous tag and current
BREAK_LOG=""
FEAT_LOG=""
FIX_LOG=""
OTHER_LOG=""
while IFS= read -r line; do
hash=$(echo "$line" | cut -d' ' -f1)
msg=$(echo "$line" | cut -d' ' -f2-)
# Conventional Commits breaking marker: `<type>!:` or `<type>(<scope>)!:`
if echo "$msg" | grep -qE '^[a-z]+(\([^)]*\))?!:'; then
BREAK_LOG="$BREAK_LOG\n- $msg (\`$hash\`)"
continue
fi
case "$msg" in
feat\(*\)*|feat:*)
FEAT_LOG="$FEAT_LOG\n- $msg (\`$hash\`)"
;;
fix\(*\)*|fix:*)
FIX_LOG="$FIX_LOG\n- $msg (\`$hash\`)"
;;
chore:*|chore\(*\)*)
# Skip chore commits (version bumps, lock updates)
;;
*)
OTHER_LOG="$OTHER_LOG\n- $msg (\`$hash\`)"
;;
esac
done < <(git log ${PREV_TAG}..HEAD --oneline --no-merges)
if [ -n "$BREAK_LOG" ]; then
CHANGELOG="$CHANGELOG\n> ⚠️ **This release contains breaking changes.** Review the items below before upgrading.\n\n### 💥 Breaking Changes\n$BREAK_LOG\n"
fi
if [ -n "$FEAT_LOG" ]; then
CHANGELOG="$CHANGELOG\n### ✨ New Features\n$FEAT_LOG\n"
fi
if [ -n "$FIX_LOG" ]; then
CHANGELOG="$CHANGELOG\n### 🛠 Bug Fixes\n$FIX_LOG\n"
fi
if [ -n "$OTHER_LOG" ]; then
CHANGELOG="$CHANGELOG\n### Other Changes\n$OTHER_LOG\n"
fi
CHANGELOG="$CHANGELOG\n**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${VERSION}"
else
CHANGELOG="$CHANGELOG\nInitial release."
fi
# Write to file for multiline body
echo -e "$CHANGELOG" > release_notes.md
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
artifacts/**/*.tar.gz
artifacts/**/*.zip
artifacts/**/*.sha256
draft: false
prerelease: false
body_path: release_notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release Summary
run: |
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 📦 Built Artifacts" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Target | File |" >> $GITHUB_STEP_SUMMARY
echo "|--------|------|" >> $GITHUB_STEP_SUMMARY
shopt -s nullglob globstar
for artifact in artifacts/**/*.tar.gz artifacts/**/*.zip; do
if [ -f "$artifact" ]; then
filename=$(basename "$artifact")
target_name=$(echo "$filename" | sed -E 's/\.(tar\.gz|zip)$//')
echo "| $target_name | $filename |" >> $GITHUB_STEP_SUMMARY
fi
done