-
Notifications
You must be signed in to change notification settings - Fork 9
397 lines (349 loc) · 15 KB
/
release.yml
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
name: Release
on:
workflow_dispatch:
push:
branches:
- master
paths:
- Cargo.toml
- Cargo.lock
- 'crates/**'
- .github/workflows/rust_binaries_release.yml
pull_request:
types: [opened, synchronize, reopened]
branches:
- master
paths:
- Cargo.toml
- Cargo.lock
- 'crates/**'
- .github/workflows/rust_binaries_release.yml
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
is_release_candidate: ${{ steps.check_release_candidate.outputs.is_release_candidate }}
binary_matrix: ${{ steps.setup_matrix.outputs.binary_matrix }}
steps:
- name: Check if release candidate
id: check_release_candidate
run: |
# Additional checks for head_ref when PR because GH doesn't support that
if [ "${{ github.event_name }}" == "pull_request" ] && ! [[ "${{ github.head_ref }}" == prerelease/* ]]; then
echo 'is_release_candidate=false' >> "$GITHUB_OUTPUT"
else
echo 'is_release_candidate=true' >> "$GITHUB_OUTPUT"
fi
- name: Setup matrix
id: setup_matrix
run: |
echo 'binary_matrix=["merod", "meroctl"]' >> "$GITHUB_OUTPUT"
build:
if: needs.prepare.outputs.is_release_candidate == 'true'
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin
runs-on: ${{ matrix.os }}
needs: prepare
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Craft cargo arguments
id: cargo_args
run: |
binaries=$(echo '${{ needs.prepare.outputs.binary_matrix }}' | jq -r 'join(" ") | split(" ") | map("-p " + .) | join(" ")')
args="$binaries --release --target ${{ matrix.target }}"
echo "Cargo build arguments: $args"
echo args="$args" >> "$GITHUB_OUTPUT"
- name: Install rustup and Rust toolchain
if: matrix.os == 'macos-latest'
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
rustup toolchain install stable
rustup default stable
- name: Setup rust toolchain
run: rustup toolchain install stable --profile minimal
- name: Setup rust cache
uses: Swatinem/rust-cache@v2
with:
key: rust-binaries-${{ runner.os }}-${{ matrix.target }}
- name: Install target for ${{ matrix.target }}
run: rustup target add ${{ matrix.target }}
- name: Install dependencies for cross-compilation
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y \
gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \
libstdc++-11-dev-arm64-cross \
zlib1g-dev \
libsnappy-dev \
libbz2-dev \
liblz4-dev \
libzstd-dev \
clang \
libc6-dev-arm64-cross
- name: Download and set up OpenSSL for cross-compilation
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar -xzf openssl-1.1.1g.tar.gz
cd openssl-1.1.1g
# More restrictive C99 flags and additional compiler options
export CROSS_COMPILE="" # Clear CROSS_COMPILE to prevent double prefix
export CC="aarch64-linux-gnu-gcc"
export CXX="aarch64-linux-gnu-g++"
export CFLAGS="-std=gnu99 -O2 -fPIC -D_GNU_SOURCE -I/usr/aarch64-linux-gnu/include"
export LDFLAGS="-L/usr/aarch64-linux-gnu/lib"
./Configure linux-aarch64 --prefix=$HOME/openssl-aarch64 \
no-asm \
no-shared \
no-async \
no-engine \
no-dso \
no-deprecated
make -j$(nproc) CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
make install_sw
cd ..
echo "OPENSSL_DIR=$HOME/openssl-aarch64" >> $GITHUB_ENV
echo "OPENSSL_LIB_DIR=$HOME/openssl-aarch64/lib" >> $GITHUB_ENV
echo "OPENSSL_INCLUDE_DIR=$HOME/openssl-aarch64/include" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$HOME/openssl-aarch64/lib/pkgconfig" >> $GITHUB_ENV
echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV
echo "PKG_CONFIG_SYSROOT_DIR=/" >> $GITHUB_ENV
echo "OPENSSL_STATIC=1" >> $GITHUB_ENV
- name: Build binaries
if: matrix.target == 'aarch64-unknown-linux-gnu'
env:
CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc
CXX_aarch64_unknown_linux_gnu: aarch64-linux-gnu-g++
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
OPENSSL_DIR: ${{ env.OPENSSL_DIR }}
OPENSSL_LIB_DIR: ${{ env.OPENSSL_LIB_DIR }}
OPENSSL_INCLUDE_DIR: ${{ env.OPENSSL_INCLUDE_DIR }}
PKG_CONFIG_PATH: ${{ env.PKG_CONFIG_PATH }}
PKG_CONFIG_ALLOW_CROSS: ${{ env.PKG_CONFIG_ALLOW_CROSS }}
PKG_CONFIG_SYSROOT_DIR: ${{ env.PKG_CONFIG_SYSROOT_DIR }}
OPENSSL_STATIC: ${{ env.OPENSSL_STATIC }}
run: |
cargo build ${{ steps.cargo_args.outputs.args }}
- name: Build binaries
if: matrix.target != 'aarch64-unknown-linux-gnu'
run: cargo build ${{ steps.cargo_args.outputs.args }}
- name: Compress artifacts using gzip
run: |
mkdir -p artifacts
echo '${{ needs.prepare.outputs.binary_matrix }}' | jq -r '.[]' | while read binary; do
tar -czf artifacts/"$binary"_${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release "$binary"
done
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.target }}
path: artifacts/*
retention-days: 2
release:
if: needs.prepare.outputs.is_release_candidate == 'true'
runs-on: ubuntu-latest
needs: [prepare, build]
strategy:
matrix:
binary: ${{ fromJSON(needs.prepare.outputs.binary_matrix) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Artifact
uses: actions/download-artifact@v4
with:
path: artifacts/
merge-multiple: true
- name: Get version info
id: version_info
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "target_commit=${{ github.sha }}" >> $GITHUB_OUTPUT
if [ "${{ github.ref }}" == "refs/heads/master" ]; then
binary_version=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "${{ matrix.binary }}") | .version')
version="${{ matrix.binary }}-$binary_version"
echo "Master version: $version"
if gh release view "$version" --repo ${{ github.repository }} >/dev/null 2>&1; then
echo "Master release for this version already exists"
echo "release_required=false" >> $GITHUB_OUTPUT
else
echo "New master release required"
echo "release_required=true" >> $GITHUB_OUTPUT
fi
echo "prerelease=false" >> $GITHUB_OUTPUT
echo "overwrite=false">> $GITHUB_OUTPUT
echo "binary_version=$binary_version" >> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
elif [ "${{ github.event_name }}" == "pull_request" ] && [[ "${{ github.head_ref }}" == prerelease/* ]]; then
version="prerelease-${{ github.event.number }}"
echo "Prerelease version: $version"
echo "release_required=true" >> $GITHUB_OUTPUT
echo "prerelease=true" >> $GITHUB_OUTPUT
echo "overwrite=true">> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
else
echo "This is not a master branch or a prerelease PR"
echo "release_required=false" >> $GITHUB_OUTPUT
fi
- name: Set release matrix outputs
uses: cloudposse/github-action-matrix-outputs-write@v1
with:
matrix-step-name: release
matrix-key: ${{ matrix.binary }}
outputs: |-
releaseRequired: ${{ steps.version_info.outputs.release_required }}
version: ${{ steps.version_info.outputs.binary_version }}
- name: Remove other binaries from artifacts
if: steps.version_info.outputs.release_required == 'true'
run: |
ls -al artifacts/
find artifacts/ -type f ! -name '${{ matrix.binary }}*' -exec rm {} +
ls -al artifacts/
- name: Upload binaries to release
if: steps.version_info.outputs.release_required == 'true'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: artifacts/*
file_glob: true
tag: ${{ steps.version_info.outputs.version }}
prerelease: ${{ steps.version_info.outputs.prerelease }}
overwrite: ${{ steps.version_info.outputs.overwrite }}
target_commit: ${{ steps.version_info.outputs.target_commit }}
brew-update:
if: needs.prepare.outputs.is_release_candidate == 'true' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
needs: [prepare, build, release]
steps:
- name: Get release matrix outputs
id: release-matrix-outputs
uses: cloudposse/github-action-matrix-outputs-read@v1
with:
matrix-step-name: release
- name: Create GitHub App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: |
homebrew-tap
- name: Checkout homebrew-tap
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/homebrew-tap
token: ${{ steps.app-token.outputs.token }}
persist-credentials: false
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Configure Git
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
gh auth setup-git
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
- name: Update Formula
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
target_branch="chore/bump-formulas-version"
git fetch origin "${target_branch}" || true
git checkout "${target_branch}" || git checkout -b "${target_branch}"
for binary in $(echo '${{ needs.prepare.outputs.binary_matrix }}' | jq -r '.[]'); do
release_required=$(echo '${{ steps.release-matrix-outputs.outputs.result }}' | jq -r --arg key "${binary}" '.releaseRequired[$key]')
version=$(echo '${{ steps.release-matrix-outputs.outputs.result }}' | jq -r --arg key "${binary}" '.version[$key]')
if [ "${release_required}" == "true" ]; then
echo "Updating formula for ${binary}, version: ${version}"
./generate-formula.sh "${binary}" "${version}"
else
echo "No formula update required for ${binary}"
fi
done
git status
if git diff-index --quiet HEAD --; then
echo "There are no changes to commit"
exit 0
fi
git add Formula/
git commit -m "chore: bump formulas version"
git push origin "${target_branch}"
gh pr create -f || true
installation-script-update:
if: needs.prepare.outputs.is_release_candidate == 'true' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
needs: [prepare, build, release]
steps:
- name: Get release matrix outputs
id: release-matrix-outputs
uses: cloudposse/github-action-matrix-outputs-read@v1
with:
matrix-step-name: release
- name: Create GitHub App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- name: Checkout core
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
persist-credentials: false
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Configure Git
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
gh auth setup-git
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
- name: Process each binary and create PRs
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
for binary in $(echo '${{ needs.prepare.outputs.binary_matrix }}' | jq -r '.[]'); do
release_required=$(echo '${{ steps.release-matrix-outputs.outputs.result }}' | jq -r --arg key "${binary}" '.releaseRequired[$key]')
version=$(echo '${{ steps.release-matrix-outputs.outputs.result }}' | jq -r --arg key "${binary}" '.version[$key]')
if [ "${release_required}" == "true" ]; then
echo "Updating installation script for ${binary}, version: ${version}"
target_branch="chore/bump-${binary}-installation-script-to-v${version}"
git fetch origin "${target_branch}" || true
git checkout "${target_branch}" || git checkout -b "${target_branch}"
./scripts/generate-installation-script.sh "${binary}" "${version}"
git add scripts/
git commit -m "chore: bump ${binary} installation script to v${version}" || true
git push origin "${target_branch}"
gh pr create \
--title "chore: bump ${binary} installation script to v${version}" \
--body "This PR updates the installation script for **${binary}** to version **${version}**." \
--head "${target_branch}" \
--base master \
-f || true
else
echo "No update required for ${binary}"
fi
done