forked from metalbear-co/mirrord
-
Notifications
You must be signed in to change notification settings - Fork 0
300 lines (289 loc) · 13.5 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
293
294
295
296
297
298
299
300
name: Release
on:
push:
tags:
- "*.*.*"
# Running from workflow dispatch (AKA manual) will not publish anything.
# This is intended for testing changes to this flow.
workflow_dispatch:
jobs:
build_binaries_aarch64-unknown-linux-gnu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: taiki-e/install-action@v2
with:
tool: cross
# building layer and cli together leads to weird situation where embedded layer is x64, so split.
- name: build mirrord-layer
run: RUSTFLAGS="$RUSTFLAGS -A dead_code" cross build --release -p mirrord-layer --target=aarch64-unknown-linux-gnu
- name: build mirrord cli
env:
MIRRORD_LAYER_FILE: ../../../target/aarch64-unknown-linux-gnu/release/libmirrord_layer.so
run: RUSTFLAGS="$RUSTFLAGS -A dead_code" cross build --release -p mirrord --target=aarch64-unknown-linux-gnu
- uses: actions/upload-artifact@v3
with:
name: aarch64-unknown-linux-gnu
path: |
target/aarch64-unknown-linux-gnu/release/mirrord
target/aarch64-unknown-linux-gnu/release/libmirrord_layer.so
if-no-files-found: error
build_binaries_x86_64-unknown-linux-gnu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: taiki-e/install-action@v2
with:
tool: cross
- name: build mirrord-layer and cli
run: cross build --release -p mirrord -p mirrord-layer --target=x86_64-unknown-linux-gnu
- uses: actions/upload-artifact@v3
with:
name: x86_64-unknown-linux-gnu
path: |
target/x86_64-unknown-linux-gnu/release/mirrord
target/x86_64-unknown-linux-gnu/release/libmirrord_layer.so
if-no-files-found: error
build_binaries_macos:
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- run: rm rust-toolchain.toml
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: x86_64-apple-darwin,aarch64-apple-darwin
toolchain: nightly-2023-09-07
- name: Import Code-Signing Certificates
uses: Apple-Actions/import-codesign-certs@8f3fb608891dd2244cdab3d69cd68c0d37a7fe93
with:
# The certificates in a PKCS12 file encoded as a base64 string
p12-file-base64: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_BASE64 }}
# The password used to import the PKCS12 file.
p12-password: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_PASSWORD }}
- name: Install gon via HomeBrew for code signing and app notarization
run: |
brew tap mitchellh/gon
brew install mitchellh/gon/gon
- name: build mirrord-layer x86-64
run: cargo +nightly-2023-09-07 build --release -p mirrord-layer --target=x86_64-apple-darwin
- name: build mirrord-layer macOS arm/arm64e
# Editing the arm64 binary, since arm64e can be loaded into both arm64 & arm64e
# >> target/debug/libmirrord_layer.dylib: Mach-O 64-bit dynamically linked shared library arm64
# >> magic bits: 0000000 facf feed 000c 0100 0000 0000 0006 0000
# >> After editing using dd -
# >> magic bits: 0000000 facf feed 000c 0100 0002 0000 0006 0000
# >> target/debug/libmirrord_layer.dylib: Mach-O 64-bit dynamically linked shared library arm64e
run: |
cargo +nightly-2023-09-07 build --release -p mirrord-layer --target=aarch64-apple-darwin
cp target/aarch64-apple-darwin/release/libmirrord_layer.dylib target/aarch64-apple-darwin/release/libmirrord_layer_arm64e.dylib
printf '\x02' | dd of=target/aarch64-apple-darwin/release/libmirrord_layer_arm64e.dylib bs=1 seek=8 count=1 conv=notrunc
- name: Sign layer binaries
env:
AC_USERNAME: ${{ secrets.APPLE_DEVELOPER }}
AC_PASSWORD: ${{ secrets.APPLE_DEVELOPER_PASSWORD }}
run: gon -log-level=debug -log-json .github/workflows/arch_dylib_sign.json
- name: create universal target dir
run: mkdir -p /tmp/target/universal-apple-darwin/release
- name: create universal dylib
run: lipo -create -output /tmp/target/universal-apple-darwin/release/libmirrord_layer.dylib target/aarch64-apple-darwin/release/libmirrord_layer.dylib target/x86_64-apple-darwin/release/libmirrord_layer.dylib target/aarch64-apple-darwin/release/libmirrord_layer_arm64e.dylib
- name: Sign layer universal
env:
AC_USERNAME: ${{ secrets.APPLE_DEVELOPER }}
AC_PASSWORD: ${{ secrets.APPLE_DEVELOPER_PASSWORD }}
run: gon -log-level=debug -log-json .github/workflows/universal_dylib_sign.json
- name: build macOS arm cli with universal dylib
env:
MIRRORD_LAYER_FILE: /tmp/target/universal-apple-darwin/release/libmirrord_layer.dylib
run: cargo +nightly-2023-09-07 build --release -p mirrord --target=aarch64-apple-darwin
- name: build macOS x86-64 cli with universal dylib
env:
MIRRORD_LAYER_FILE: /tmp/target/universal-apple-darwin/release/libmirrord_layer.dylib
run: cargo +nightly-2023-09-07 build --release -p mirrord --target=x86_64-apple-darwin
- name: Sign cli binaries
env:
AC_USERNAME: ${{ secrets.APPLE_DEVELOPER }}
AC_PASSWORD: ${{ secrets.APPLE_DEVELOPER_PASSWORD }}
run: gon -log-level=debug -log-json .github/workflows/arch_cli_sign.json
- name: create universal macOS cli
run: lipo -create -output /tmp/target/universal-apple-darwin/release/mirrord target/aarch64-apple-darwin/release/mirrord target/x86_64-apple-darwin/release/mirrord
- name: Sign universal cli
env:
AC_USERNAME: ${{ secrets.APPLE_DEVELOPER }}
AC_PASSWORD: ${{ secrets.APPLE_DEVELOPER_PASSWORD }}
run: gon -log-level=debug -log-json .github/workflows/universal_cli_sign.json
- name: adjust directory layout for upload
run: cp -rf /tmp/target .
- uses: actions/upload-artifact@v3
with:
name: universal-apple-darwin
path: |
target/universal-apple-darwin/release/mirrord
target/universal-apple-darwin/release/libmirrord_layer.dylib
if-no-files-found: error
release_docker_image:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get release version
run: |
echo "version=$(grep -m 1 version Cargo.toml | cut -d' ' -f3 | tr -d '\"')" >> $GITHUB_OUTPUT
id: version
- name: Build and push (test)
if: github.event_name == 'workflow_dispatch'
uses: docker/build-push-action@v3
with:
context: .
file: mirrord/agent/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/metalbear-co/mirrord-staging:${{ github.sha }}
- name: Build and push (final/release)
if: github.event_name != 'workflow_dispatch'
uses: docker/build-push-action@v3
with:
context: .
file: mirrord/agent/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/metalbear-co/mirrord:latest
ghcr.io/metalbear-co/mirrord:${{ steps.version.outputs.version }}
release_gh:
needs:
[
build_binaries_aarch64-unknown-linux-gnu,
build_binaries_x86_64-unknown-linux-gnu,
build_binaries_macos,
release_docker_image,
]
runs-on: ubuntu-latest
if: github.event_name != 'workflow_dispatch'
permissions:
packages: write
contents: write
deployments: write
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
path: /tmp/artifacts
- uses: montudor/action-zip@v1
- name: Create mirrord linux-x64 zip file
run: |
zip mirrord_linux_x86_64.zip mirrord
shasum -a 256 mirrord_linux_x86_64.zip > mirrord_linux_x86_64.shasum256
working-directory: /tmp/artifacts/x86_64-unknown-linux-gnu
- name: Create mirrord linux-aarch64 zip file
run: |
zip mirrord_linux_aarch64.zip mirrord
shasum -a 256 mirrord_linux_aarch64.zip > mirrord_linux_aarch64.shasum256
working-directory: /tmp/artifacts/aarch64-unknown-linux-gnu
- name: Create mirrord macos zip file
run: |
zip mirrord_mac_universal.zip mirrord
shasum -a 256 mirrord_mac_universal.zip > mirrord_mac_universal.shasum256
working-directory: /tmp/artifacts/universal-apple-darwin
# used for the homebrew formula
- uses: actions/upload-artifact@v3
with:
name: shasum
path: |
/tmp/artifacts/x86_64-unknown-linux-gnu/mirrord_linux_x86_64.shasum256
/tmp/artifacts/aarch64-unknown-linux-gnu/mirrord_linux_aarch64.shasum256
/tmp/artifacts/universal-apple-darwin/mirrord_mac_universal.shasum256
if-no-files-found: error
- name: Prepare binaries for upload
run: |
mkdir /tmp/release
mv /tmp/artifacts/x86_64-unknown-linux-gnu/libmirrord_layer.so /tmp/release/libmirrord_layer_linux_x86_64.so
mv /tmp/artifacts/x86_64-unknown-linux-gnu/mirrord /tmp/release/mirrord_linux_x86_64
mv /tmp/artifacts/x86_64-unknown-linux-gnu/mirrord_linux_x86_64.zip /tmp/release/mirrord_linux_x86_64.zip
mv /tmp/artifacts/x86_64-unknown-linux-gnu/mirrord_linux_x86_64.shasum256 /tmp/release/mirrord_linux_x86_64.shasum256
mv /tmp/artifacts/aarch64-unknown-linux-gnu/libmirrord_layer.so /tmp/release/libmirrord_layer_linux_aarch64.so
mv /tmp/artifacts/aarch64-unknown-linux-gnu/mirrord /tmp/release/mirrord_linux_aarch64
mv /tmp/artifacts/aarch64-unknown-linux-gnu/mirrord_linux_aarch64.zip /tmp/release/mirrord_linux_aarch64.zip
mv /tmp/artifacts/aarch64-unknown-linux-gnu/mirrord_linux_aarch64.shasum256 /tmp/release/mirrord_linux_aarch64.shasum256
mv /tmp/artifacts/universal-apple-darwin/libmirrord_layer.dylib /tmp/release/libmirrord_layer_mac_universal.dylib
mv /tmp/artifacts/universal-apple-darwin/mirrord /tmp/release/mirrord_mac_universal
mv /tmp/artifacts/universal-apple-darwin/mirrord_mac_universal.zip /tmp/release/mirrord_mac_universal.zip
mv /tmp/artifacts/universal-apple-darwin/mirrord_mac_universal.shasum256 /tmp/release/mirrord_mac_universal.shasum256
# Consider to add changelog generation..
- name: Release
uses: softprops/action-gh-release@v1
with:
files: /tmp/release/**
release_homebrew:
needs: release_gh
runs-on: ubuntu-latest
if: github.event_name != 'workflow_dispatch'
steps:
- uses: actions/download-artifact@v3
with:
path: /tmp/artifacts
- uses: actions/checkout@v3
- name: Get release version and hashes
run: |
echo "version=$(grep -m 1 version Cargo.toml | cut -d' ' -f3 | tr -d '\"' | cut -d'-' -f1)" >> $GITHUB_ENV
echo "sha256_mac=$(cat /tmp/artifacts/shasum/universal-apple-darwin/mirrord_mac_universal.shasum256 | awk '{ print $1 }')" >> $GITHUB_ENV
echo "sha256_linux_aarch64=$(cat /tmp/artifacts/shasum/aarch64-unknown-linux-gnu/mirrord_linux_aarch64.shasum256 | awk '{ print $1 }')" >> $GITHUB_ENV
echo "sha256_linux_x86_64=$(cat /tmp/artifacts/shasum/x86_64-unknown-linux-gnu/mirrord_linux_x86_64.shasum256 | awk '{ print $1 }')" >> $GITHUB_ENV
- name: Checkout into homebrew-mirrord
uses: actions/checkout@v3
with:
repository: metalbear-co/homebrew-mirrord
path: ./
token: ${{ secrets.BREW_GITHUB_PAT }}
- name: Update hashes and urls
run: |
sed -i -e 's/\([0-9]\+\.[0-9]\+\.[0-9]\+\)/${{ env.version }}/g' mirrord.rb
sed -z -i -e 's/[0-9a-f]\{64\}/${{ env.sha256_mac }}/1' mirrord.rb
sed -z -i -e 's/[0-9a-f]\{64\}/${{ env.sha256_linux_aarch64 }}/2' mirrord.rb
sed -z -i -e 's/[0-9a-f]\{64\}/${{ env.sha256_linux_x86_64 }}/3' mirrord.rb
- name: Display formula (For debugging purposes only)
run: cat mirrord.rb
- name: Commit to metalbear-co/homebrew-mirrord
run: |
git config --global user.email "[email protected]"
git config --global user.name "Eyal Bukchin"
git add .
git commit -m "Update to ${{ env.version }}"
git push
update_latest:
needs: release_homebrew
runs-on: ubuntu-latest
if: github.event_name != 'workflow_dispatch'
steps:
- name: Check out code
uses: actions/checkout@v3
with:
# Get complete history
fetch-depth: 0
- name: Update major version and latest tags
uses: metalbear-co/release-tracker-action@main
env:
# GitHub token to enable pushing tags
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Move "latest" tag
update-latest: true
# Don't update the vX.Y tags
update-minor: false