Skip to content

Commit bbb58cc

Browse files
authored
Merge pull request #2903 from liamcottle/ci/build-matrix
Refactor builds via GitHub Actions to be super fast
2 parents 57563ab + 54234b5 commit bbb58cc

6 files changed

Lines changed: 126 additions & 92 deletions

File tree

.github/actions/setup-build-environment/action.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,14 @@ runs:
2525
- name: Extract Version from Git Tag
2626
shell: bash
2727
run: |
28-
GIT_TAG_NAME="${GITHUB_REF#refs/tags/}"
29-
echo "GIT_TAG_VERSION=${GIT_TAG_NAME##*-}" >> $GITHUB_ENV
28+
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
29+
# triggered by a tag push (e.g: refs/tags/companion-v1.2.3)
30+
GIT_TAG_NAME="${GITHUB_REF#refs/tags/}"
31+
VERSION_STRING="${GIT_TAG_NAME##*-}"
32+
else
33+
# triggered by a workflow dispatch (e.g: refs/heads/main)
34+
# strip "refs/heads/" prefix and replace any remaining "/" with "-" to protect file paths
35+
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
36+
VERSION_STRING=$(echo "$BRANCH_NAME" | tr '/' '-')
37+
fi
38+
echo "GIT_TAG_VERSION=${VERSION_STRING}" >> $GITHUB_ENV

.github/workflows/build-companion-firmwares.yml

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,8 @@ on:
1010
- 'companion-*'
1111

1212
jobs:
13-
14-
build:
15-
runs-on: ubuntu-latest
16-
steps:
17-
18-
- name: Clone Repo
19-
uses: actions/checkout@v6
20-
21-
- name: Setup Build Environment
22-
uses: ./.github/actions/setup-build-environment
23-
24-
- name: Build Firmwares
25-
env:
26-
FIRMWARE_VERSION: ${{ env.GIT_TAG_VERSION }}
27-
run: /usr/bin/env bash build.sh build-companion-firmwares
28-
29-
- name: Upload Workflow Artifacts
30-
uses: actions/upload-artifact@v7
31-
with:
32-
name: companion-firmwares
33-
path: out
34-
35-
- name: Create Release
36-
uses: softprops/action-gh-release@v3
37-
if: startsWith(github.ref, 'refs/tags/')
38-
with:
39-
name: Companion Firmware ${{ env.GIT_TAG_VERSION }}
40-
body: ""
41-
draft: true
42-
files: out/*
13+
build-companion-firmwares:
14+
uses: ./.github/workflows/firmware-builder.yml
15+
with:
16+
firmware_type: 'companion'
17+
release_title_prefix: 'Companion Firmware'

.github/workflows/build-repeater-firmwares.yml

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,8 @@ on:
1010
- 'repeater-*'
1111

1212
jobs:
13-
14-
build:
15-
runs-on: ubuntu-latest
16-
steps:
17-
18-
- name: Clone Repo
19-
uses: actions/checkout@v6
20-
21-
- name: Setup Build Environment
22-
uses: ./.github/actions/setup-build-environment
23-
24-
- name: Build Firmwares
25-
env:
26-
FIRMWARE_VERSION: ${{ env.GIT_TAG_VERSION }}
27-
run: /usr/bin/env bash build.sh build-repeater-firmwares
28-
29-
- name: Upload Workflow Artifacts
30-
uses: actions/upload-artifact@v7
31-
with:
32-
name: repeater-firmwares
33-
path: out
34-
35-
- name: Create Release
36-
uses: softprops/action-gh-release@v3
37-
if: startsWith(github.ref, 'refs/tags/')
38-
with:
39-
name: Repeater Firmware ${{ env.GIT_TAG_VERSION }}
40-
body: ""
41-
draft: true
42-
files: out/*
13+
build-repeater-firmwares:
14+
uses: ./.github/workflows/firmware-builder.yml
15+
with:
16+
firmware_type: 'repeater'
17+
release_title_prefix: 'Repeater Firmware'

.github/workflows/build-room-server-firmwares.yml

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,8 @@ on:
1010
- 'room-server-*'
1111

1212
jobs:
13-
14-
build:
15-
runs-on: ubuntu-latest
16-
steps:
17-
18-
- name: Clone Repo
19-
uses: actions/checkout@v6
20-
21-
- name: Setup Build Environment
22-
uses: ./.github/actions/setup-build-environment
23-
24-
- name: Build Firmwares
25-
env:
26-
FIRMWARE_VERSION: ${{ env.GIT_TAG_VERSION }}
27-
run: /usr/bin/env bash build.sh build-room-server-firmwares
28-
29-
- name: Upload Workflow Artifacts
30-
uses: actions/upload-artifact@v7
31-
with:
32-
name: room-server-firmwares
33-
path: out
34-
35-
- name: Create Release
36-
uses: softprops/action-gh-release@v3
37-
if: startsWith(github.ref, 'refs/tags/')
38-
with:
39-
name: Room Server Firmware ${{ env.GIT_TAG_VERSION }}
40-
body: ""
41-
draft: true
42-
files: out/*
13+
build-room-server-firmwares:
14+
uses: ./.github/workflows/firmware-builder.yml
15+
with:
16+
firmware_type: 'room-server'
17+
release_title_prefix: 'Room Server Firmware'
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Firmware Builder
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
firmware_type:
7+
required: true
8+
type: string
9+
release_title_prefix:
10+
required: true
11+
type: string
12+
13+
jobs:
14+
15+
generate-build-matrix:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
targets: ${{ steps.get-build-targets.outputs.targets }}
19+
steps:
20+
21+
- name: Clone Repo
22+
uses: actions/checkout@v6
23+
24+
- name: Setup Build Environment
25+
uses: ./.github/actions/setup-build-environment
26+
27+
- name: Get Build Targets
28+
id: get-build-targets
29+
run: |
30+
# get list of firmwares to build
31+
TARGET_LIST=$(/usr/bin/env bash build.sh get-${{ inputs.firmware_type }}-firmwares-to-build)
32+
33+
# convert targets separated by new line into a json array string
34+
JSON_ARRAY=$(echo "$TARGET_LIST" | jq -R -s -c 'split("\n") | map(select(length > 0))')
35+
36+
# use json array as targets result
37+
echo "targets=$JSON_ARRAY" >> $GITHUB_OUTPUT
38+
39+
build:
40+
needs: generate-build-matrix
41+
runs-on: ubuntu-latest
42+
continue-on-error: true # don't fail entire build if one board fails to build
43+
strategy:
44+
matrix:
45+
target: ${{ fromJson(needs.generate-build-matrix.outputs.targets) }}
46+
fail-fast: false # don't cancel other builds if one board fails to build
47+
steps:
48+
49+
- name: Clone Repo
50+
uses: actions/checkout@v6
51+
52+
- name: Setup Build Environment
53+
uses: ./.github/actions/setup-build-environment
54+
55+
- name: Build Firmware
56+
env:
57+
FIRMWARE_VERSION: ${{ env.GIT_TAG_VERSION }}
58+
run: /usr/bin/env bash build.sh build-firmware ${{ matrix.target }}
59+
60+
- name: Upload Workflow Artifacts
61+
uses: actions/upload-artifact@v7
62+
with:
63+
name: "${{ matrix.target }}"
64+
path: out
65+
66+
create-release:
67+
needs: build
68+
runs-on: ubuntu-latest
69+
if: startsWith(github.ref, 'refs/tags/') # only create release for tagged builds
70+
steps:
71+
72+
- name: Clone Repo
73+
uses: actions/checkout@v6
74+
75+
- name: Setup Build Environment
76+
uses: ./.github/actions/setup-build-environment
77+
78+
- name: Download All Artifacts
79+
uses: actions/download-artifact@v8
80+
with:
81+
merge-multiple: true
82+
path: out
83+
84+
- name: Create Release
85+
uses: softprops/action-gh-release@v3
86+
with:
87+
name: "${{ inputs.release_title_prefix }} ${{ env.GIT_TAG_VERSION }}"
88+
body: ""
89+
draft: true
90+
files: out/*

build.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env bash
22

3+
# exit when any command fails
4+
set -e
5+
36
global_usage() {
47
cat - <<EOF
58
Usage:
@@ -275,4 +278,11 @@ elif [[ $1 == "build-repeater-firmwares" ]]; then
275278
build_repeater_firmwares
276279
elif [[ $1 == "build-room-server-firmwares" ]]; then
277280
build_room_server_firmwares
281+
elif [[ $1 == "get-companion-firmwares-to-build" ]]; then
282+
get_pio_envs_ending_with_string "_companion_radio_usb"
283+
get_pio_envs_ending_with_string "_companion_radio_ble"
284+
elif [[ $1 == "get-repeater-firmwares-to-build" ]]; then
285+
get_pio_envs_ending_with_string "_repeater"
286+
elif [[ $1 == "get-room-server-firmwares-to-build" ]]; then
287+
get_pio_envs_ending_with_string "_room_server"
278288
fi

0 commit comments

Comments
 (0)