Skip to content

Commit 57c0993

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

File tree

1 file changed

+98
-247
lines changed

1 file changed

+98
-247
lines changed

.github/workflows/build.yaml

Lines changed: 98 additions & 247 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/[email protected]
177+
with:
178+
name: assets
179+
path: assets-dist
180+
181+
- name: Download binary x86_64
182+
uses: actions/[email protected]
183+
with:
184+
name: binary-x86_64-unknown-linux-gnu
185+
path: binary-x86_64
186+
187+
- name: Download binary aarch64
188+
uses: actions/[email protected]
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
@@ -257,209 +314,3 @@ jobs:
257314
if: github.event_name != 'pull_request'
258315
with:
259316
files: |
260-
./docker-bake.hcl
261-
cwd://${{ steps.meta.outputs.bake-file }}
262-
cwd://${{ steps.meta-debug.outputs.bake-file }}
263-
cwd://${{ steps.meta-syn2mas.outputs.bake-file }}
264-
set: |
265-
base.output=type=image,push=true
266-
base.cache-from=type=registry,ref=${{ env.BUILDCACHE }}:buildcache
267-
base.cache-to=type=registry,ref=${{ env.BUILDCACHE }}:buildcache,mode=max
268-
269-
- name: Transform bake output
270-
# This transforms the ouput to an object which looks like this:
271-
# { reguar: { digest: "…", tags: ["…", "…"] }, debug: { digest: "…", tags: ["…"] }, … }
272-
id: output
273-
if: github.event_name != 'pull_request'
274-
run: |
275-
echo 'metadata<<EOF' >> $GITHUB_OUTPUT
276-
echo '${{ steps.bake.outputs.metadata }}' | jq -c 'with_entries(select(.value | (type == "object" and has("containerimage.digest")))) | map_values({ digest: .["containerimage.digest"], tags: (.["image.name"] | split(",")) })' >> $GITHUB_OUTPUT
277-
echo 'EOF' >> $GITHUB_OUTPUT
278-
279-
- name: Sign the images with GitHub Actions provided token
280-
# Only sign on tags and on commits on main branch
281-
if: |
282-
github.event_name != 'pull_request'
283-
&& (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
284-
285-
env:
286-
REGULAR_DIGEST: ${{ steps.output.outputs.metadata && fromJSON(steps.output.outputs.metadata).regular.digest }}
287-
DEBUG_DIGEST: ${{ steps.output.outputs.metadata && fromJSON(steps.output.outputs.metadata).debug.digest }}
288-
SYN2MAS_DIGEST: ${{ steps.output.outputs.metadata && fromJSON(steps.output.outputs.metadata).syn2mas.digest }}
289-
290-
run: |-
291-
cosign sign --yes \
292-
"$IMAGE@$REGULAR_DIGEST" \
293-
"$IMAGE@$DEBUG_DIGEST" \
294-
"$IMAGE_SYN2MAS@$SYN2MAS_DIGEST"
295-
296-
syn2mas:
297-
name: Release syn2mas on NPM
298-
runs-on: ubuntu-latest
299-
300-
permissions:
301-
contents: read
302-
id-token: write
303-
304-
steps:
305-
- name: Checkout the code
306-
uses: actions/[email protected]
307-
308-
- name: Install Node
309-
uses: actions/[email protected]
310-
with:
311-
node-version-file: ./tools/syn2mas/.nvmrc
312-
313-
- name: Install Node dependencies
314-
working-directory: ./tools/syn2mas
315-
run: npm ci
316-
317-
- name: Publish
318-
uses: JS-DevTools/npm-publish@v3
319-
with:
320-
package: ./tools/syn2mas
321-
token: ${{ secrets.NPM_TOKEN }}
322-
provenance: true
323-
dry-run: ${{ !startsWith(github.ref, 'refs/tags/') }}
324-
325-
release:
326-
name: Release
327-
if: startsWith(github.ref, 'refs/tags/')
328-
runs-on: ubuntu-latest
329-
needs:
330-
- build-binaries
331-
- build-image
332-
- syn2mas
333-
steps:
334-
- name: Download the artifacts from the previous job
335-
uses: actions/download-artifact@v4
336-
with:
337-
name: binaries
338-
path: artifacts
339-
340-
- name: Prepare a release
341-
uses: softprops/action-gh-release@v2
342-
with:
343-
generate_release_notes: true
344-
body: |
345-
### Docker image
346-
347-
Regular image:
348-
349-
- Digest:
350-
```
351-
${{ env.IMAGE }}@${{ fromJSON(needs.build-image.outputs.metadata).regular.digest }}
352-
```
353-
- Tags:
354-
```
355-
${{ join(fromJSON(needs.build-image.outputs.metadata).regular.tags, '
356-
') }}
357-
```
358-
359-
Debug variant:
360-
361-
- Digest:
362-
```
363-
${{ env.IMAGE }}@${{ fromJSON(needs.build-image.outputs.metadata).debug.digest }}
364-
```
365-
- Tags:
366-
```
367-
${{ join(fromJSON(needs.build-image.outputs.metadata).debug.tags, '
368-
') }}
369-
```
370-
371-
`syn2mas` migration tool:
372-
373-
- Digest:
374-
```
375-
${{ env.IMAGE_SYN2MAS }}@${{ fromJSON(needs.build-image.outputs.metadata).syn2mas.digest }}
376-
```
377-
- Tags:
378-
```
379-
${{ join(fromJSON(needs.build-image.outputs.metadata).syn2mas.tags, '
380-
') }}
381-
```
382-
383-
files: |
384-
artifacts/mas-cli-aarch64-linux.tar.gz
385-
artifacts/mas-cli-x86_64-linux.tar.gz
386-
draft: true
387-
388-
unstable:
389-
name: Update the unstable release
390-
runs-on: ubuntu-24.04
391-
needs:
392-
- build-binaries
393-
- build-image
394-
if: github.ref == 'refs/heads/main'
395-
396-
permissions:
397-
contents: write
398-
399-
steps:
400-
- name: Download the artifacts from the previous job
401-
uses: actions/download-artifact@v4
402-
with:
403-
name: binaries
404-
path: artifacts
405-
406-
- name: Update unstable git tag
407-
uses: actions/[email protected]
408-
with:
409-
script: |
410-
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
411-
const sha = process.env.GITHUB_SHA;
412-
413-
const tag = await github.rest.git.updateRef({
414-
owner,
415-
repo,
416-
force: true,
417-
ref: 'tags/unstable',
418-
sha,
419-
});
420-
console.log("Updated tag ref:", tag.data.url);
421-
422-
- name: Update unstable release
423-
uses: softprops/action-gh-release@v2
424-
with:
425-
name: 'Unstable build'
426-
tag_name: unstable
427-
body: |
428-
This is an automatically updated unstable release containing the latest builds from the main branch.
429-
430-
**⚠️ Warning: These are development builds and may be unstable.**
431-
432-
Last updated: ${{ github.event.head_commit.timestamp }}
433-
Commit: ${{ github.sha }}
434-
435-
### Docker image
436-
437-
Regular image:
438-
439-
- Digest:
440-
```
441-
${{ env.IMAGE }}@${{ fromJSON(needs.build-image.outputs.metadata).regular.digest }}
442-
```
443-
- Tags:
444-
```
445-
${{ join(fromJSON(needs.build-image.outputs.metadata).regular.tags, '
446-
') }}
447-
```
448-
449-
Debug variant:
450-
451-
- Digest:
452-
```
453-
${{ env.IMAGE }}@${{ fromJSON(needs.build-image.outputs.metadata).debug.digest }}
454-
```
455-
- Tags:
456-
```
457-
${{ join(fromJSON(needs.build-image.outputs.metadata).debug.tags, '
458-
') }}
459-
```
460-
461-
files: |
462-
artifacts/mas-cli-aarch64-linux.tar.gz
463-
artifacts/mas-cli-x86_64-linux.tar.gz
464-
prerelease: true
465-
make_latest: false

0 commit comments

Comments
 (0)