-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Open-Shock/feature/multi-board-ci
Multi-board CI
- Loading branch information
Showing
4 changed files
with
131 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,32 +11,51 @@ env: | |
|
||
jobs: | ||
|
||
# Build all targets. This step also outputs the strategy matrix containing the names | ||
# of each board that is being built for. | ||
build: | ||
uses: ./.github/workflows/ci-build.yml | ||
|
||
publish: | ||
|
||
# Publish one artifact PER BOARD. | ||
publish-artifacts: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
strategy: | ||
matrix: ${{ fromJSON(needs.build.outputs.matrix) }} | ||
|
||
steps: | ||
- name: Download release notes | ||
uses: actions/checkout@v4 | ||
with: | ||
sparse-checkout: | | ||
RELEASE.md | ||
# Note: This step is NOT in fact `actions/download-artifact`. The reason is that since we | ||
# invoked the build workflow as a sub-workflow, we cannot directly access its artifacts. | ||
# This alternative implementation enables us to do it regardless. | ||
- name: Download build artifacts | ||
uses: dawidd6/[email protected] | ||
with: | ||
name: merged-firmware | ||
name: OpenShock_${{ matrix.board }} | ||
name_is_regexp: false | ||
run_id: ${{ github.event.workflow_run.id }} | ||
workflow_conclusion: '' # ignore | ||
search_artifacts: true | ||
|
||
# Push artifact for this board. | ||
- name: Upload artifact to release | ||
uses: svenstaro/upload-release-action@v2 | ||
with: | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
file: OpenShock.${{ matrix.board }}.bin | ||
asset_name: OpenShock.${{ matrix.board }}.bin | ||
tag: ${{ github.ref }} | ||
|
||
publish-release: | ||
runs-on: ubuntu-latest | ||
needs: [build] | ||
|
||
steps: | ||
- name: Download release notes | ||
uses: actions/checkout@v4 | ||
with: | ||
sparse-checkout: | | ||
RELEASE.md | ||
# This step reads a file from repo and use it for body of the release | ||
# This works on any self-hosted runner OS | ||
- name: Read RELEASE.md | ||
|
@@ -49,12 +68,12 @@ jobs: | |
r="${r//$'\r'/'%0D'}" # Multiline escape sequences for '\r' | ||
echo "RELEASE_BODY=$r" >> $GITHUB_OUTPUT # <--- Set environment variable | ||
- name: Upload binaries to release | ||
- name: Upload release notes | ||
uses: svenstaro/upload-release-action@v2 | ||
with: | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
file: merged.bin | ||
asset_name: OpenShock.ESP32.bin | ||
file: RELEASE.md | ||
asset_name: RELEASE.md | ||
tag: ${{ github.ref }} | ||
body: | | ||
${{ steps.read_release.outputs.RELEASE_BODY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
# This is a bit of a silly workflow, but Github Workflow definitions | ||
# do not let us easily reuse the strategy matrix used to trigger jobs | ||
# per-board. This is a workaround to define everything in one file, and | ||
# use the output in the multiple places we need it. | ||
# | ||
# Source: https://github.com/orgs/community/discussions/26284#discussioncomment-6701976 | ||
|
||
on: | ||
workflow_call: | ||
outputs: | ||
matrix: | ||
description: "Strategy matrix" | ||
value: ${{ jobs.generate-matrix.outputs.matrix }} | ||
|
||
name: targets | ||
|
||
jobs: | ||
generate-matrix: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.extract.outputs.matrix }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
sparse-checkout: platformio.ini | ||
|
||
# There's a lot going on here, so bear with me. | ||
# | ||
# sed: | ||
# -n Suppresses normal output, | ||
# "s/^\[env:\(.*\)]$/\1 Substitutes "[env:...]" with whatever value is at "..." | ||
# /p" Prints out the substituted value (i.e. the value of "...") | ||
# platformio.ini Reading from this file. | ||
# | ||
# jq: | ||
# "--raw-input --slurp" Takes the previous output, | ||
# -c Output in compact mode (no newlines or unnecessary spaces), | ||
# split("\n") Splits it by line, turning it into an array, | ||
# [ .[] | select(length > 0) Filters out empty lines (there is an empty trailing line usually), | ||
# | select(. != "fs") ] Filters out the "fs" entry since that's only for building the filesystem, | ||
# { board: ... } Wraps the whole thing into a JSON object with only a "board" key | ||
# and the array in question as value. | ||
# | ||
# echo "matrix=$(...)" >> $GITHUB_OUTPUT Sets the value as job output with name "matrix". | ||
# | ||
# Referenced: https://unix.stackexchange.com/a/278377 | ||
# Referenced: https://github.com/jqlang/jq/issues/563 | ||
- name: Extract targets | ||
id: extract | ||
run: | | ||
echo "matrix=$(sed -n "s/^\[env:\(.*\)]$/\1/p" platformio.ini | jq --raw-input --slurp -c '{ board: split("\n") | [ .[] | select(length > 0) | select(. != "fs") ] }')" >> $GITHUB_OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters