Skip to content

Commit 5709e27

Browse files
committed
Speedup CI by splitting binary builds for each architecture
1 parent 53ce40e commit 5709e27

File tree

1 file changed

+98
-41
lines changed

1 file changed

+98
-41
lines changed

.github/workflows/build.yaml

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

56105
build-binaries:
57106
name: Build binaries
@@ -60,6 +109,12 @@ jobs:
60109
needs:
61110
- compute-version
62111

112+
strategy:
113+
matrix:
114+
include:
115+
- target: x86_64-unknown-linux-gnu
116+
- target: aarch64-unknown-linux-gnu
117+
63118
env:
64119
VERGEN_GIT_DESCRIBE: ${{ needs.compute-version.outputs.describe }}
65120
SOURCE_DATE_EPOCH: ${{ needs.compute-version.outputs.timestamp }}
@@ -71,17 +126,11 @@ jobs:
71126
- name: Checkout the code
72127
uses: actions/[email protected]
73128

74-
- name: Setup OPA
75-
uses: open-policy-agent/[email protected]
76-
with:
77-
version: 0.64.1
78-
79129
- name: Install Rust toolchain
80130
uses: dtolnay/rust-toolchain@stable
81131
with:
82132
targets: |
83-
x86_64-unknown-linux-gnu
84-
aarch64-unknown-linux-gnu
133+
${{ matrix.target }}
85134
86135
- name: Setup sccache
87136
uses: mozilla-actions/[email protected]
@@ -96,52 +145,60 @@ jobs:
96145
with:
97146
tool: cargo-zigbuild
98147

99-
- name: Install frontend Node
100-
uses: actions/[email protected]
101-
with:
102-
node-version: 20
103-
104-
- name: Install frontend Node dependencies
105-
working-directory: ./frontend
106-
run: npm ci
107-
108-
- name: Build frontend
109-
working-directory: ./frontend
110-
run: npm run build
111-
112-
- name: Build policies
113-
working-directory: ./policies
114-
run: make
115-
116148
- name: Build the binary
117149
run: |
118150
cargo zigbuild \
119151
--release \
120-
--target x86_64-unknown-linux-gnu.2.17 \
121-
--target aarch64-unknown-linux-gnu.2.17 \
152+
--target ${{ matrix.target }}.2.17 \
122153
--no-default-features \
123154
--features dist \
124155
-p mas-cli
125156
126-
- name: Create one archive per architecture
157+
- name: Upload binary artifact
158+
uses: actions/[email protected]
159+
with:
160+
name: binary-${{ matrix.target }}
161+
path: target/${{ matrix.target }}/release/mas-cli
162+
163+
assemble-archives:
164+
name: Assemble release archives
165+
runs-on: ubuntu-22.04
166+
167+
needs:
168+
- build-assets
169+
- build-binaries
170+
171+
permissions:
172+
contents: read
173+
174+
steps:
175+
- name: Download assets
176+
uses: actions/download-artifact@v4
177+
with:
178+
name: assets
179+
path: assets-dist
180+
181+
- name: Download binary x86_64
182+
uses: actions/download-artifact@v4
183+
with:
184+
name: binary-x86_64-unknown-linux-gnu
185+
path: binary-x86_64
186+
187+
- name: Download binary aarch64
188+
uses: actions/download-artifact@v4
189+
with:
190+
name: binary-aarch64-unknown-linux-gnu
191+
path: binary-aarch64
192+
193+
- name: Create final archives
127194
run: |
128195
for arch in x86_64 aarch64; do
129-
# Create one directory per architecture
130-
mkdir -p dist/${arch}/share/
131-
# Copy the artifacts to the right place
132-
cp policies/policy.wasm dist/${arch}/share/policy.wasm
133-
cp frontend/dist/manifest.json dist/${arch}/share/manifest.json
134-
cp -r frontend/dist/ dist/${arch}/share/assets
135-
cp -r templates/ dist/${arch}/share/templates
136-
cp -r translations/ dist/${arch}/share/translations
137-
cp LICENSE dist/${arch}/LICENSE
196+
mkdir -p dist/${arch}/share
197+
cp -r assets-dist/share/* dist/${arch}/share/
198+
cp assets-dist/LICENSE dist/${arch}/LICENSE
199+
cp binary-$arch/mas-cli dist/${arch}/mas-cli
138200
chmod -R u=rwX,go=rX dist/${arch}/
139-
140-
# Copy the binary to the right place
141-
cp target/${arch}-unknown-linux-gnu/release/mas-cli dist/${arch}/
142201
chmod u=rwx,go=rx dist/${arch}/mas-cli
143-
144-
# Create the archive
145202
tar -czvf mas-cli-${arch}-linux.tar.gz --owner=0 --group=0 -C dist/${arch}/ .
146203
done
147204

0 commit comments

Comments
 (0)