-
Notifications
You must be signed in to change notification settings - Fork 88
231 lines (199 loc) · 7.46 KB
/
release.yml
File metadata and controls
231 lines (199 loc) · 7.46 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
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-22.04
- target: aarch64-unknown-linux-gnu
os: ubuntu-22.04
cross: true
- target: x86_64-unknown-linux-musl
os: ubuntu-22.04
musl: true
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install musl tools
if: matrix.musl == true
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
if [[ "${{ matrix.target }}" == aarch64-* ]]; then
sudo apt-get install -y gcc-aarch64-linux-gnu musl-dev
sudo ln -sf /usr/bin/aarch64-linux-gnu-gcc /usr/bin/aarch64-linux-musl-gcc || true
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CC_aarch64_unknown_linux_musl=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
fi
- name: Install cross-compilation tools
if: matrix.cross == true && matrix.musl != true
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Run tests
if: matrix.cross != true
working-directory: rust
shell: bash
run: |
if [[ "${{ runner.os }}" == "Windows" ]]; then
cargo test --lib --all-features
else
cargo test --all-features
fi
- name: Build
working-directory: rust
run: cargo build --release --target ${{ matrix.target }}
- name: Package (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
cd rust/target/${{ matrix.target }}/release
tar czf ../../../../lean-ctx-${{ matrix.target }}.tar.gz lean-ctx
cd ../../../..
- name: Package (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
Compress-Archive -Path "rust/target/${{ matrix.target }}/release/lean-ctx.exe" -DestinationPath "lean-ctx-${{ matrix.target }}.zip"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: lean-ctx-${{ matrix.target }}
path: |
lean-ctx-${{ matrix.target }}.tar.gz
lean-ctx-${{ matrix.target }}.zip
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: Create stable source tarball
run: |
VERSION="${GITHUB_REF_NAME#v}"
git archive --format=tar.gz --prefix="lean-ctx-${VERSION}/" "${GITHUB_REF_NAME}" -o "lean-ctx-${VERSION}-source.tar.gz"
- name: Generate checksums
run: sha256sum lean-ctx-*.tar.gz lean-ctx-*.zip > SHA256SUMS
- name: Extract release notes from CHANGELOG
id: notes
run: |
VERSION="${GITHUB_REF_NAME#v}"
PREV_TAG=$(git tag --sort=-v:refname | grep -A1 "^v${VERSION}$" | tail -1)
NOTES=$(awk "/^## \\[${VERSION}\\]/{found=1; next} /^## \\[/{if(found) exit} found{print}" CHANGELOG.md)
{
echo "body<<BODY_EOF"
echo "$NOTES"
echo ""
echo "#### Upgrade"
echo '```bash'
echo "cargo install lean-ctx # or"
echo "npm update -g lean-ctx-bin # or"
echo "brew upgrade lean-ctx"
echo '```'
echo ""
echo "**Full Changelog**: https://github.com/yvgude/lean-ctx/compare/${PREV_TAG}...v${VERSION}"
echo "BODY_EOF"
} >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
body: ${{ steps.notes.outputs.body }}
files: |
lean-ctx-*.tar.gz
lean-ctx-*.zip
SHA256SUMS
publish-crates:
name: Publish to crates.io
needs: release
runs-on: ubuntu-latest
if: ${{ !contains(github.ref_name, '-rc') }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Publish
working-directory: rust
run: cargo publish --allow-dirty --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
continue-on-error: true
publish-npm:
name: Publish to npm
needs: release
runs-on: ubuntu-latest
if: ${{ !contains(github.ref_name, '-rc') }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org
- name: Publish lean-ctx-bin
working-directory: packages/lean-ctx-bin
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
continue-on-error: true
- name: Publish pi-lean-ctx
working-directory: packages/pi-lean-ctx
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
continue-on-error: true
update-homebrew:
name: Update Homebrew
needs: release
runs-on: ubuntu-latest
if: ${{ !contains(github.ref_name, '-rc') }}
steps:
- name: Download checksums and extract hashes
id: checksums
run: |
VERSION="${GITHUB_REF_NAME#v}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
gh release download "${GITHUB_REF_NAME}" \
--repo yvgude/lean-ctx --pattern "SHA256SUMS" --dir .
SOURCE_SHA=$(grep "source\.tar\.gz" SHA256SUMS | awk '{print $1}')
echo "source_sha=${SOURCE_SHA}" >> "$GITHUB_OUTPUT"
echo "Source tarball SHA256: ${SOURCE_SHA}"
env:
GH_TOKEN: ${{ github.token }}
- name: Clone and update formula
run: |
VERSION="${{ steps.checksums.outputs.version }}"
SHA="${{ steps.checksums.outputs.source_sha }}"
git clone "https://x-access-token:${HOMEBREW_TOKEN}@github.com/yvgude/homebrew-lean-ctx.git"
cd homebrew-lean-ctx
sed -i "s|url \".*\"|url \"https://github.com/yvgude/lean-ctx/releases/download/v${VERSION}/lean-ctx-${VERSION}-source.tar.gz\"|" Formula/lean-ctx.rb
sed -i "s|sha256 \".*\"|sha256 \"${SHA}\"|" Formula/lean-ctx.rb
sed -i "s|assert_match \"lean-ctx [0-9][^\"]*\"|assert_match \"lean-ctx ${VERSION}\"|" Formula/lean-ctx.rb
grep -q "v${VERSION}/lean-ctx-${VERSION}-source.tar.gz" Formula/lean-ctx.rb
grep -q "sha256 \"${SHA}\"" Formula/lean-ctx.rb
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/lean-ctx.rb
git diff --cached --quiet || git commit -m "lean-ctx ${VERSION}"
git push
env:
HOMEBREW_TOKEN: ${{ secrets.HOMEBREW_GITHUB_TOKEN }}