-
Notifications
You must be signed in to change notification settings - Fork 4
292 lines (252 loc) · 10.4 KB
/
release.yaml
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
name: Build Binaries
on:
push:
branches:
- main
- ci
workflow_dispatch:
concurrency:
group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
get_release_info:
name: Get Release Info
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.new_release_tag.outputs.TAG }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get latest release
if: startsWith(github.ref, 'refs/heads/main')
id: release
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: ${{ github.repository }}
excludes: prerelease, draft
- name: Determine if release build
if: startsWith(github.ref, 'refs/heads/main')
id: new_release_tag
env:
LATEST_RELEASE: ${{ steps.release.outputs.release }}
run: |
CARGO_VERSION=v$(grep "version" Cargo.toml | head -n 1 | cut -d\" -f2)
if [[ "${CARGO_VERSION}" != "${LATEST_RELEASE}" ]]; then
echo "::set-output name=TAG::${CARGO_VERSION}"
echo "::warning::Will create release for version: ${CARGO_VERSION}"
else
echo "::warning::Will not create a release"
fi
dist_surfpool:
name: Build Surfpool Distributions
runs-on: ${{ matrix.os }}
outputs:
LINUX_X64_SHA: ${{ steps.linux_x64_sha.outputs.LINUX_X64_SHA }}
MACOS_X64_SHA: ${{ steps.macos_x64_sha.outputs.MACOS_X64_SHA }}
MACOS_ARM64_SHA: ${{ steps.macos_arm64_sha.outputs.MACOS_ARM64_SHA }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-20.04
platform: linux
target: x86_64-unknown-linux-gnu
architecture: x64
# - os: windows-latest
# platform: windows
# target: x86_64-pc-windows-msvc
# architecture: x64
- os: macos-latest
platform: darwin
target: x86_64-apple-darwin
architecture: x64
- os: macos-latest
platform: darwin
target: aarch64-apple-darwin
architecture: arm64
steps:
# pre-build for windows
- name: Configure git to use LF (Windows)
if: matrix.os == 'windows-latest'
run: |
git config --global core.autocrlf false
git config --global core.eol lf
# pre-build for all OS
- name: Checkout repository
uses: actions/checkout@v4
# set up rust for all envs
- name: Install Rust toolchain
run: rustup toolchain install 1.84.0 --profile minimal --target ${{ matrix.target }}
- name: Install Rust Target
run: rustup target add ${{ matrix.target }}
# env vars unix
- name: Get Rust version (unix)
if: matrix.os != 'windows-latest'
run: echo "RUST_VERSION_HASH=$(rustc --version | shasum -a 256 | awk '{print $1}')" >> $GITHUB_ENV
# env vars windows
- name: "Get Rust version (windows)"
if: matrix.os == 'windows-latest'
shell: bash
run: echo "RUST_VERSION_HASH=$(rustc --version | sha256sum | awk '{print $1}')" >> $GITHUB_ENV
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/
./target/${{ matrix.target }}/release/
key: ${{ runner.os }}-rust-${{ env.RUST_VERSION_HASH }}-cargo-${{ hashFiles('./Cargo.lock') }}
# Set environment variables required from cross compiling from macos-x86_64 to macos-arm64
- name: Configure macos-arm64 cross compile config
if: matrix.target == 'aarch64-apple-darwin'
run: |
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
- name: Configure artifact names
shell: bash
run: |
echo "SHORT_TARGET_NAME=${{ matrix.platform }}-${{ matrix.architecture }}" >> $GITHUB_ENV
echo "PRE_GYP_TARGET_NAME=${{ matrix.platform }}-${{ matrix.architecture }}-unknown" >> $GITHUB_ENV
- name: Build - Cargo
run:
cargo build --release --locked --target ${{ matrix.target }}
# Don't compress for Windows because winget can't yet unzip files
- name: Compress cargo artifact (not windows)
if: matrix.os != 'windows-latest'
run: tar -C target/${{ matrix.target }}/release -zcvf surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz surfpool
- name: Store SHA256 Hash of Tar (Linux x64)
if: matrix.os == 'ubuntu-20.04'
id: linux_x64_sha
run: |
echo "LINUX_X64_SHA=$(sha256sum surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz | awk '{ print $1 }')" >> "$GITHUB_OUTPUT"
- name: Store SHA256 Hash of Tar (Mac x64)
if: matrix.os == 'macos-latest' && matrix.architecture == 'x64'
id: macos_x64_sha
run: |
echo "MACOS_X64_SHA=$(shasum -a 256 surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz | awk '{ print $1 }')" >> "$GITHUB_OUTPUT"
- name: Store SHA256 Hash of Tar (Mac arm64)
if: matrix.os == 'macos-latest' && matrix.architecture == 'arm64'
id: macos_arm64_sha
run: |
echo "MACOS_ARM64_SHA=$(shasum -a 256 surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz | awk '{ print $1 }')" >> "$GITHUB_OUTPUT"
# Separate uploads to prevent paths from being preserved
- name: Upload cargo artifacts (not windows)
if: matrix.os != 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: surfpool-${{ env.SHORT_TARGET_NAME }}
path: surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz
release:
name: Release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/heads/main') && needs.get_release_info.outputs.tag != ''
needs:
- dist_surfpool
- get_release_info
permissions:
actions: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download pre-built dists
uses: actions/download-artifact@v4
- name: Tag and Release
uses: ncipollo/release-action@v1
with:
artifacts: "**/*.tar.gz,**/*.msi"
tag: ${{ needs.get_release_info.outputs.tag }}
commit: ${{ env.GITHUB_SHA }}
- name: Pack artifacts
run: |
tar -czvf surfpool-linux-x64.tar.gz surfpool-linux-x64
tar -czvf surfpool-darwin-x64.tar.gz surfpool-darwin-x64
tar -czvf surfpool-darwin-arm64.tar.gz surfpool-darwin-arm64
homebrew:
name: Update Homebrew
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/heads/main') && needs.get_release_info.outputs.tag != ''
needs:
- dist_surfpool
- get_release_info
- release
permissions:
actions: write
contents: write
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Set up Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Clone the tap repository
run: |
git clone https://github.com/txtx/homebrew-taps.git
cd homebrew-taps
- name: Update the formula with new version and SHA256 values
run: |
pwd
ls
cd homebrew-taps
pwd
ls
# Define the new version
NEW_VERSION="${{ needs.get_release_info.outputs.tag }}"
# Update the version in all url fields, matching on any valid semver version
sed -i.bak "s/v[0-9]\+\.[0-9]\+\.[0-9]\+\(-[a-zA-Z0-9\.-]\+\)\?\(\+[a-zA-Z0-9\.-]\+\)\?/$(echo $NEW_VERSION)/g" Formula/surfpool.rb
# Update macOS x64 SHA256
sed -i.bak '/# sha for macos_x64/!b;n;c\ sha256 "'${{ needs.dist_surfpool.outputs.MACOS_X64_SHA }}'"' Formula/surfpool.rb
# Update macOS arm64 SHA256
sed -i.bak '/# sha for macos_arm64/!b;n;c\ sha256 "'${{ needs.dist_surfpool.outputs.MACOS_ARM64_SHA }}'"' Formula/surfpool.rb
# Update Linux x64 SHA256
sed -i.bak '/# sha for linux_x64/!b;n;c\ sha256 "'${{ needs.dist_surfpool.outputs.LINUX_X64_SHA }}'"' Formula/surfpool.rb
# Uncomment and update Linux ARM SHA256 when needed
# sed -i.bak '/# sha for linux_arm64/!b;n;c\ sha256 "'$SHA256_LINUX_ARM'"' Formula/surfpool.rb
# Remove backup file
rm Formula/surfpool.rb.bak
- name: Commit and push changes
run: |
pwd
ls
cd homebrew-taps
pwd
ls
git add Formula/surfpool.rb
git commit -m "Update to version ${{ needs.get_release_info.outputs.tag }}"
git push https://txtx:${{ secrets.TXTX_ACCESS_TOKEN }}@github.com/txtx/homebrew-taps.git
snapcraft:
name: Update Snapcraft
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/heads/main') && needs.get_release_info.outputs.tag != ''
needs:
- dist_surfpool
- get_release_info
- release
permissions:
actions: write
contents: write
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Set up Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Clone the tap repository
run: |
git clone https://github.com/txtx/snapcraft-surfpool.git
cd snapcraft-surfpool
- name: Update snapcraft.yaml
run: |
cd snapcraft-surfpool
NEW_VERSION="${{ needs.get_release_info.outputs.tag }}"
SOURCE_URL="https://github.com/txtx/surfpool/releases/download/${NEW_VERSION}/surfpool-linux-x64.tar.gz"
# Update the version and source URL in the snapcraft.yaml file
sed -i "s/^version:.*/version: '${NEW_VERSION}'/" snapcraft.yaml
sed -i "s|^ source: .*| source: ${SOURCE_URL}|" snapcraft.yaml
- name: Commit and push changes
run: |
cd snapcraft-surfpool
git add snapcraft.yaml
git commit -m "Update to version ${{ needs.get_release_info.outputs.tag }}"
git push https://txtx:${{ secrets.TXTX_ACCESS_TOKEN }}@github.com/txtx/snapcraft-surfpool.git