-
Notifications
You must be signed in to change notification settings - Fork 51
303 lines (296 loc) · 13.6 KB
/
release-cli.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
name: Release Workflow
on:
release:
types: [published]
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
CARGO_INCREMENTAL: 0
jobs:
check-versions-match:
name: Check versions match
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # ratchet:actions/checkout@v3
- name: Install jq
run: sudo apt-get install jq
- name: Check release version matches code
run: |
RELEASE_VERSION=${{ github.event.release.tag_name }}
STRIPPED_VERSION=${RELEASE_VERSION#v}
make check_versions_match GITHUB_RELEASE_VERSION=$STRIPPED_VERSION
upload_cli_release_linux:
strategy:
fail-fast: false
matrix:
platform:
- target: x86_64-unknown-linux-gnu
bin: quary
name: quary-linux-x86_64-gnu.zip
runs-on: ubuntu-latest
# - target: x86_64-pc-windows-gnu
# bin: quary.exe
# name: quary-windows-x86_64-gnu.zip
# runs-on: ubuntu-latest
runs-on: ${{ matrix.platform.runs-on }}
continue-on-error: true
needs:
- check-versions-match
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # ratchet:actions/checkout@v3
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # ratchet:Swatinem/rust-cache@v2
- name: Set up Rust
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # ratchet:actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
if: ${{ !matrix.platform.cross }}
- name: Install cross
run: cargo install cross
- name: Build binary (*nix)
shell: bash
run: |
cross build --locked --release --bin quary --target ${{ matrix.platform.target }}
- name: Install zip and dev utilities
run: sudo apt-get install zip libssl-dev pkg-config
- name: Extract version from tag
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
- name: Package as archive
shell: bash
run: |
cd target/${{ matrix.platform.target }}/release
zip -j ${{ matrix.platform.name }} ${{ matrix.platform.bin }}
mv ${{ matrix.platform.name }} ../../../
- name: Upload Release Asset
uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87 # ratchet:softprops/[email protected]
with:
files: 'quary-*'
upload_cli_release_linux_aarch:
strategy:
fail-fast: false
matrix:
platform:
- target: aarch64-unknown-linux-gnu
bin: quary
name: quary-linux-aarch64-gnu.zip
runs-on: ubicloud-standard-2-arm
runs-on: ${{ matrix.platform.runs-on }}
continue-on-error: true
needs:
- check-versions-match
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # ratchet:actions/checkout@v3
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # ratchet:Swatinem/rust-cache@v2
- name: Set up Rust
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # ratchet:actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
if: ${{ !matrix.platform.cross }}
- name: Build binary (*nix)
shell: bash
run: |
cargo build --locked --release --bin quary --target ${{ matrix.platform.target }}
- name: Install zip and dev utilities
run: sudo apt-get install zip libssl-dev pkg-config
- name: Extract version from tag
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
- name: list files in target
run: ls -la target/${{ matrix.platform.target }}/release
- name: Package as archive
shell: bash
run: |
cd target/${{ matrix.platform.target }}/release
zip -j ${{ matrix.platform.name }} ${{ matrix.platform.bin }}
mv ${{ matrix.platform.name }} ../../../
- name: Upload Release Asset
uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87 # ratchet:softprops/[email protected]
with:
files: 'quary-*'
upload_cli_release_mac:
name: Release CLI
strategy:
fail-fast: false
matrix:
platform:
- target: x86_64-apple-darwin
bin: quary
name: quary-macos-x86_64-gnu.zip
- target: aarch64-apple-darwin
bin: quary
name: quary-macos-aarch64-gnu.zip
runs-on: macos-latest
continue-on-error: true
needs:
- check-versions-match
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # ratchet:actions/checkout@v3
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # ratchet:Swatinem/rust-cache@v2
- name: Set up Rust
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # ratchet:actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
if: ${{ !matrix.platform.cross }}
- run: rustup target add x86_64-apple-darwin
- name: Install cross
run: cargo install cross
- name: Install aarch rust target
run: rustup target add aarch64-apple-darwin
- name: Build binary (*nix)
shell: bash
run: |
cross build --locked --release --bin quary --target ${{ matrix.platform.target }}
- name: Extract version from tag
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
- name: Codesign app bundle
# Extract the secrets we defined earlier as environment variables
env:
MACOS_CERTIFICATE: ${{ secrets.PROD_MACOS_CERTIFICATE }}
MACOS_CERTIFICATE_PWD: ${{ secrets.PROD_MACOS_CERTIFICATE_PWD }}
MACOS_CERTIFICATE_NAME: ${{ secrets.PROD_MACOS_CERTIFICATE_NAME }}
MACOS_CI_KEYCHAIN_PWD: ${{ secrets.PROD_MACOS_CI_KEYCHAIN_PWD }}
run: |
# Turn our base64-encoded certificate back to a regular .p12 file
echo $MACOS_CERTIFICATE | base64 --decode > certificate.p12
# We need to create a new keychain, otherwise using the certificate will prompt
# with a UI dialog asking for the certificate password, which we can't
# use in a headless CI environment
security create-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain
security import certificate.p12 -k build.keychain -P "$MACOS_CERTIFICATE_PWD" -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$MACOS_CI_KEYCHAIN_PWD" build.keychain
# We finally codesign our app bundle, specifying the Hardened runtime option
/usr/bin/codesign --force -s "$MACOS_CERTIFICATE_NAME" --options runtime target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }} -v
- name: Package as archive
run: |
cd target/${{ matrix.platform.target }}/release
zip -j ${{ matrix.platform.name }} ${{ matrix.platform.bin }}
mv ${{ matrix.platform.name }} ../../../
- name: Notarize app bundle
timeout-minutes: 30
# Extract the secrets we defined earlier as environment variables
env:
PROD_MACOS_NOTARIZATION_APPLE_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_APPLE_ID }}
PROD_MACOS_NOTARIZATION_TEAM_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_TEAM_ID }}
PROD_MACOS_NOTARIZATION_PWD: ${{ secrets.PROD_MACOS_NOTARIZATION_PWD }}
run: |
# Store the notarization credentials so that we can prevent a UI password dialog
# from blocking the CI
echo "Create keychain profile"
xcrun notarytool store-credentials "notarytool-profile" --apple-id "$PROD_MACOS_NOTARIZATION_APPLE_ID" --team-id "$PROD_MACOS_NOTARIZATION_TEAM_ID" --password "$PROD_MACOS_NOTARIZATION_PWD"
# We can't notarize an app bundle directly, but we need to compress it as an archive.
# Therefore, we create a zip file containing our app bundle, so that we can send it to the
# notarization service
# Here we send the notarization request to the Apple's Notarization service, waiting for the result.
# This typically takes a few seconds inside a CI environment, but it might take more depending on the App
# characteristics. Visit the Notarization docs for more information and strategies on how to optimize it if
# you're curious
echo "Notarize app"
xcrun notarytool submit "${{ matrix.platform.name }}" --keychain-profile "notarytool-profile" --wait
# Finally, we need to "attach the staple" to our executable, which will allow our app to be
# validated by macOS even when an internet connection is not available.
# Cannot yet staple binary "Although tickets are created for standalone binaries, it’s not currently possible to staple tickets to them."
# https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution/customizing_the_notarization_workflow#3087720
# echo "Attach staple"
# xcrun stapler staple -v notarization.zip
- name: Upload Release Asset
uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87 # ratchet:softprops/[email protected]
with:
files: 'quary-*'
upload_cli_release_windows:
runs-on: windows-latest
continue-on-error: true
needs:
- check-versions-match
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # ratchet:actions/checkout@v4
- name: Install stable toolchain
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # ratchet:actions-rs/toolchain@v1
with:
toolchain: stable
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # ratchet:Swatinem/rust-cache@v2
- run: cargo build --release
- name: Extract version from tag
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $env:GITHUB_ENV
- name: Package as archive
run: |
cd target/release
Compress-Archive -Path quary.exe -DestinationPath "quary-windows-x86_64-gnu.zip"
Move-Item -Path "quary-windows-x86_64-gnu.zip" -Destination "../../"
- name: Upload Release Asset
uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87 # ratchet:softprops/[email protected]
with:
files: 'quary-*'
calculate-hash:
runs-on: ubuntu-latest
needs:
- upload_cli_release_linux
- upload_cli_release_linux_aarch
- upload_cli_release_mac
- upload_cli_release_windows
steps:
- name: Checkout Repository
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # ratchet:actions/checkout@v4
- name: Fetch Release Assets
id: fetch-assets
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # ratchet:actions/github-script@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const fs = require('fs');
const response = await github.rest.repos.listReleaseAssets({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: context.payload.release.id
});
const assets = response.data.map(asset => ({ url: asset.url, name: asset.name }));
fs.writeFileSync('assets.json', JSON.stringify(assets));
- name: Download and Calculate SHA-256 Hashes
run: |
mkdir -p downloads
echo "File Name | SHA-256 Hash" >> SHA256SUMS.txt
echo "--------- | ------------" >> SHA256SUMS.txt
jq -c '.[]' assets.json | while read -r asset; do
url=$(echo $asset | jq -r '.url')
name=$(echo $asset | jq -r '.name')
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/octet-stream" -o "downloads/$name" "$url"
echo "Calculating SHA-256 for $name"
hash=$(sha256sum "downloads/$name" | awk '{print $1}')
echo "$name | $hash" >> SHA256SUMS.txt
done
- name: Update Release Description with SHA-256 Hashes
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # ratchet:actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const sha256sums = fs.readFileSync('SHA256SUMS.txt', 'utf8');
const { owner, repo } = context.repo;
const release = context.payload.release;
const newBody = release.body + '\n\n### SHA-256 Hashes\n' + sha256sums;
await github.rest.repos.updateRelease({
owner,
repo,
release_id: release.id,
body: newBody
});
update-homebrew-formula:
name: Update Homebrew Formula
runs-on: ubuntu-latest
needs:
- upload_cli_release_linux
- upload_cli_release_linux_aarch
- upload_cli_release_mac
- upload_cli_release_windows
permissions: write-all
env:
HOMEBREW_ACCESS_TOKEN: ${{ secrets.HOMEBREW_ACCESS_TOKEN }}
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # ratchet:actions/checkout@v4
- run: ./.hacking/scripts/update_homebrew_pr.sh $HOMEBREW_ACCESS_TOKEN