Skip to content

Commit 8f8f83a

Browse files
authored
Merge pull request #3970 from element-hq/quenting/ci-split-builds
Speed-up CI by splitting binary builds for each architecture
2 parents fc575a2 + 16d37a5 commit 8f8f83a

File tree

1 file changed

+113
-51
lines changed

1 file changed

+113
-51
lines changed

.github/workflows/build.yaml

Lines changed: 113 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,55 @@ jobs:
4848
echo "describe=$(git describe --tags --match 'v*.*.*' --always)" >> $GITHUB_OUTPUT
4949
echo "timestamp=$(git log -1 --format=%ct)" >> $GITHUB_OUTPUT
5050
51+
build-assets:
52+
name: Build assets
53+
runs-on: ubuntu-22.04
54+
55+
permissions:
56+
contents: read
57+
58+
steps:
59+
- name: Checkout the code
60+
uses: actions/[email protected]
61+
62+
- name: Setup OPA
63+
uses: open-policy-agent/[email protected]
64+
with:
65+
version: 0.64.1
66+
67+
- name: Install frontend Node
68+
uses: actions/[email protected]
69+
with:
70+
node-version: 20
71+
72+
- name: Install frontend Node dependencies
73+
working-directory: ./frontend
74+
run: npm ci
75+
76+
- name: Build frontend
77+
working-directory: ./frontend
78+
run: npm run build
79+
80+
- name: Build policies
81+
working-directory: ./policies
82+
run: make
83+
84+
- name: Prepare assets artifact
85+
run: |
86+
mkdir -p assets-dist/share
87+
cp policies/policy.wasm assets-dist/share/policy.wasm
88+
cp frontend/dist/manifest.json assets-dist/share/manifest.json
89+
cp -r frontend/dist/ assets-dist/share/assets
90+
cp -r templates/ assets-dist/share/templates
91+
cp -r translations/ assets-dist/share/translations
92+
cp LICENSE assets-dist/LICENSE
93+
chmod -R u=rwX,go=rX assets-dist/
94+
95+
- name: Upload assets
96+
uses: actions/[email protected]
97+
with:
98+
name: assets
99+
path: assets-dist
51100

52101
build-binaries:
53102
name: Build binaries
@@ -56,6 +105,12 @@ jobs:
56105
needs:
57106
- compute-version
58107

108+
strategy:
109+
matrix:
110+
include:
111+
- target: x86_64-unknown-linux-gnu
112+
- target: aarch64-unknown-linux-gnu
113+
59114
env:
60115
VERGEN_GIT_DESCRIBE: ${{ needs.compute-version.outputs.describe }}
61116
SOURCE_DATE_EPOCH: ${{ needs.compute-version.outputs.timestamp }}
@@ -67,17 +122,11 @@ jobs:
67122
- name: Checkout the code
68123
uses: actions/[email protected]
69124

70-
- name: Setup OPA
71-
uses: open-policy-agent/[email protected]
72-
with:
73-
version: 0.64.1
74-
75125
- name: Install Rust toolchain
76126
uses: dtolnay/rust-toolchain@stable
77127
with:
78128
targets: |
79-
x86_64-unknown-linux-gnu
80-
aarch64-unknown-linux-gnu
129+
${{ matrix.target }}
81130
82131
- name: Setup sccache
83132
uses: mozilla-actions/[email protected]
@@ -92,62 +141,74 @@ jobs:
92141
with:
93142
tool: cargo-zigbuild
94143

95-
- name: Install frontend Node
96-
uses: actions/[email protected]
97-
with:
98-
node-version: 20
99-
100-
- name: Install frontend Node dependencies
101-
working-directory: ./frontend
102-
run: npm ci
103-
104-
- name: Build frontend
105-
working-directory: ./frontend
106-
run: npm run build
107-
108-
- name: Build policies
109-
working-directory: ./policies
110-
run: make
111-
112144
- name: Build the binary
113145
run: |
114146
cargo zigbuild \
115147
--release \
116-
--target x86_64-unknown-linux-gnu.2.17 \
117-
--target aarch64-unknown-linux-gnu.2.17 \
148+
--target ${{ matrix.target }}.2.17 \
118149
--no-default-features \
119150
--features dist \
120151
-p mas-cli
121152
122-
- name: Create one archive per architecture
153+
- name: Upload binary artifact
154+
uses: actions/[email protected]
155+
with:
156+
name: binary-${{ matrix.target }}
157+
path: target/${{ matrix.target }}/release/mas-cli
158+
159+
assemble-archives:
160+
name: Assemble release archives
161+
runs-on: ubuntu-22.04
162+
163+
needs:
164+
- build-assets
165+
- build-binaries
166+
167+
permissions:
168+
contents: read
169+
170+
steps:
171+
- name: Download assets
172+
uses: actions/download-artifact@v4
173+
with:
174+
name: assets
175+
path: assets-dist
176+
177+
- name: Download binary x86_64
178+
uses: actions/download-artifact@v4
179+
with:
180+
name: binary-x86_64-unknown-linux-gnu
181+
path: binary-x86_64
182+
183+
- name: Download binary aarch64
184+
uses: actions/download-artifact@v4
185+
with:
186+
name: binary-aarch64-unknown-linux-gnu
187+
path: binary-aarch64
188+
189+
- name: Create final archives
123190
run: |
124191
for arch in x86_64 aarch64; do
125-
# Create one directory per architecture
126-
mkdir -p dist/${arch}/share/
127-
# Copy the artifacts to the right place
128-
cp policies/policy.wasm dist/${arch}/share/policy.wasm
129-
cp frontend/dist/manifest.json dist/${arch}/share/manifest.json
130-
cp -r frontend/dist/ dist/${arch}/share/assets
131-
cp -r templates/ dist/${arch}/share/templates
132-
cp -r translations/ dist/${arch}/share/translations
133-
cp LICENSE dist/${arch}/LICENSE
192+
mkdir -p dist/${arch}/share
193+
cp -r assets-dist/share/* dist/${arch}/share/
194+
cp assets-dist/LICENSE dist/${arch}/LICENSE
195+
cp binary-$arch/mas-cli dist/${arch}/mas-cli
134196
chmod -R u=rwX,go=rX dist/${arch}/
135-
136-
# Copy the binary to the right place
137-
cp target/${arch}-unknown-linux-gnu/release/mas-cli dist/${arch}/
138197
chmod u=rwx,go=rx dist/${arch}/mas-cli
139-
140-
# Create the archive
141198
tar -czvf mas-cli-${arch}-linux.tar.gz --owner=0 --group=0 -C dist/${arch}/ .
142199
done
143200
144-
- name: Upload the artifacts
201+
- name: Upload aarch64 archive
202+
uses: actions/[email protected]
203+
with:
204+
name: mas-cli-aarch64-linux
205+
path: mas-cli-aarch64-linux.tar.gz
206+
207+
- name: Upload x86_64 archive
145208
uses: actions/[email protected]
146209
with:
147-
name: binaries
148-
path: |
149-
mas-cli-aarch64-linux.tar.gz
150-
mas-cli-x86_64-linux.tar.gz
210+
name: mas-cli-x86_64-linux
211+
path: mas-cli-x86_64-linux.tar.gz
151212

152213
build-image:
153214
name: Build and push Docker image
@@ -325,15 +386,16 @@ jobs:
325386
if: startsWith(github.ref, 'refs/tags/')
326387
runs-on: ubuntu-latest
327388
needs:
328-
- build-binaries
389+
- assemble-archives
329390
- build-image
330391
- syn2mas
331392
steps:
332393
- name: Download the artifacts from the previous job
333394
uses: actions/download-artifact@v4
334395
with:
335-
name: binaries
396+
pattern: mas-cli-*
336397
path: artifacts
398+
merge-multiple: true
337399

338400
- name: Prepare a release
339401
uses: softprops/action-gh-release@v2
@@ -387,19 +449,19 @@ jobs:
387449
name: Update the unstable release
388450
runs-on: ubuntu-24.04
389451
needs:
390-
- build-binaries
452+
- assemble-archives
391453
- build-image
392454
if: github.ref == 'refs/heads/main'
393455

394456
permissions:
395457
contents: write
396-
397458
steps:
398459
- name: Download the artifacts from the previous job
399460
uses: actions/download-artifact@v4
400461
with:
401-
name: binaries
462+
pattern: mas-cli-*
402463
path: artifacts
464+
merge-multiple: true
403465

404466
- name: Update unstable git tag
405467
uses: actions/[email protected]

0 commit comments

Comments
 (0)