-
Notifications
You must be signed in to change notification settings - Fork 1
184 lines (156 loc) · 5.6 KB
/
release.yml
File metadata and controls
184 lines (156 loc) · 5.6 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
name: Release
on:
push:
branches: [main, staging]
# Only one release at a time — if a new push arrives while releasing,
# the queued run waits and then computes the next version from the new tag.
concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: false
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
BINARY_NAME: switchboard
jobs:
check:
name: Pre-release checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --check
- run: cargo clippy -- -D warnings
- run: cargo test --bin switchboard
version:
name: Resolve next version
needs: check
runs-on: ubuntu-latest
outputs:
version: ${{ steps.next.outputs.version }}
tag: ${{ steps.next.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute next version from latest tag
id: next
run: |
BRANCH="${GITHUB_REF_NAME}"
if [ "$BRANCH" = "staging" ]; then
# Staging: v0.0.0-staging.N — increment N from latest staging tag
LATEST_TAG=$(git tag -l 'v0.0.0-staging.*' --sort=-v:refname | head -1)
if [ -z "$LATEST_TAG" ]; then
NEXT="0.0.0-staging.0"
else
NUM="${LATEST_TAG##*staging.}"
NEXT="0.0.0-staging.$((NUM + 1))"
fi
else
# Main: standard semver patch bump
LATEST_TAG=$(git tag -l 'v*' --sort=-v:refname | grep -v 'staging' | head -1)
if [ -z "$LATEST_TAG" ]; then
NEXT="0.1.0"
else
CURRENT="${LATEST_TAG#v}"
MAJOR=$(echo "$CURRENT" | cut -d. -f1)
MINOR=$(echo "$CURRENT" | cut -d. -f2)
PATCH=$(echo "$CURRENT" | cut -d. -f3)
NEXT="${MAJOR}.${MINOR}.$((PATCH + 1))"
fi
fi
echo "version=${NEXT}" >> "$GITHUB_OUTPUT"
echo "tag=v${NEXT}" >> "$GITHUB_OUTPUT"
echo "Next release: v${NEXT}"
build:
name: Build ${{ matrix.archive }}
needs: version
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: linux-x86_64
- target: aarch64-apple-darwin
os: macos-14
archive: darwin-aarch64
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Set version in Cargo.toml
run: |
sed -i.bak 's/^version = ".*"/version = "${{ needs.version.outputs.version }}"/' Cargo.toml
rm -f Cargo.toml.bak
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Strip binary (Linux)
if: runner.os == 'Linux'
run: strip target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}
- name: Strip and sign binary (macOS)
if: runner.os == 'macOS'
run: |
strip target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}
codesign --force --sign - target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}
- name: Package
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../${{ env.BINARY_NAME }}-${{ needs.version.outputs.tag }}-${{ matrix.archive }}.tar.gz ${{ env.BINARY_NAME }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.archive }}
path: ${{ env.BINARY_NAME }}-${{ needs.version.outputs.tag }}-${{ matrix.archive }}.tar.gz
release:
name: Create Release
needs: [version, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Generate checksums
run: |
cd artifacts
sha256sum * > checksums-sha256.txt
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.version.outputs.tag }}
name: ${{ needs.version.outputs.tag }}
target_commitish: ${{ github.sha }}
prerelease: ${{ github.ref_name == 'staging' }}
generate_release_notes: true
body: |
## Install
```bash
curl -fsSL https://raw.githubusercontent.com/liberuum/switchboard-cli/${{ github.ref_name }}/install.sh | CHANNEL=${{ github.ref_name == 'staging' && 'staging' || 'stable' }} bash
```
Or download a binary below, extract, and run:
```bash
# macOS — clear quarantine flag after extracting
xattr -d com.apple.quarantine ./switchboard
# Then move to PATH
sudo mv switchboard /usr/local/bin/
```
files: |
artifacts/*
- name: Sync Cargo.toml version
run: |
sed -i 's/^version = ".*"/version = "${{ needs.version.outputs.version }}"/' Cargo.toml
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Cargo.toml
git diff --cached --quiet || (git commit -m "chore: release v${{ needs.version.outputs.version }}" && git push)