Skip to content

Commit

Permalink
Merge pull request #8 from Open-Shock/feature/multi-board-ci
Browse files Browse the repository at this point in the history
Multi-board CI
  • Loading branch information
redmushie authored Sep 30, 2023
2 parents 5d20f51 + 6d11328 commit d931834
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 26 deletions.
38 changes: 26 additions & 12 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@ on:
- develop
types: [opened, reopened, synchronize]
workflow_call: # When another workflow invokes this one.
outputs:
matrix:
description: "Strategy matrix"
value: ${{ jobs.get-targets.outputs.matrix }}
workflow_dispatch: # Manually invoked by user.

name: ci-build

env:
NODE_VERSION: 16
PYTHON_VERSION: 3.11
PLATFORMIO_ENV: ShockLink
SHOCKLINK_API_DOMAIN: api.shocklink.net
SHOCKLINK_FW_VERSION: master-${{ github.sha }}

jobs:

# Read platformio.ini and extract all specific targets. See the referenced file for more info.
get-targets:
uses: ./.github/workflows/targets.yml

build-captive-portal:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -84,19 +91,23 @@ jobs:
path: WebUI/build/

- name: Build filesystem
run: pio run --target buildfs
run: pio run --target buildfs -e fs

- name: Upload internal filesystem artifact
uses: actions/upload-artifact@v3
with:
name: filesystem
path: .pio/build/${{ env.PLATFORMIO_ENV }}/littlefs.bin
path: .pio/build/fs/littlefs.bin
retention-days: 1
if-no-files-found: error

build-firmware:
runs-on: ubuntu-latest

needs: get-targets
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.get-targets.outputs.matrix) }}

steps:
- uses: actions/checkout@v4

Expand All @@ -117,19 +128,22 @@ jobs:
run: pip install -r requirements.txt

- name: Build firmware
run: pio run
run: pio run -e ${{ matrix.board }}

- name: Upload internal firmware binaries
uses: actions/upload-artifact@v3
with:
name: firmware
path: .pio/build/${{ env.PLATFORMIO_ENV }}/*.bin
name: firmware_${{ matrix.board }}
path: .pio/build/${{ matrix.board }}/*.bin
retention-days: 1
if-no-files-found: error

merge-images:
runs-on: ubuntu-latest
needs: [build-filesystem, build-firmware]
needs: [get-targets, build-filesystem, build-firmware]
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.get-targets.outputs.matrix )}}

steps:
- uses: actions/checkout@v4
Expand All @@ -155,7 +169,7 @@ jobs:
- name: Download firmware images
uses: actions/download-artifact@v3
with:
name: firmware
name: firmware_${{ matrix.board }}
path: .

- name: Merge flash image
Expand All @@ -164,7 +178,7 @@ jobs:
python -m esptool \
--chip esp32 \
merge_bin \
-o merged.bin \
-o OpenShock.${{ matrix.board }}.bin \
--flash_mode dio \
--flash_freq 40m \
--flash_size 4MB \
Expand All @@ -176,7 +190,7 @@ jobs:
- name: Upload merged flashable image
uses: actions/upload-artifact@v3
with:
name: merged-firmware
path: merged.bin
name: OpenShock_${{ matrix.board }}
path: OpenShock.${{ matrix.board }}.bin
retention-days: 1
if-no-files-found: error
43 changes: 31 additions & 12 deletions .github/workflows/ci-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
53 changes: 53 additions & 0 deletions .github/workflows/targets.yml
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
23 changes: 21 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:ShockLink]
[env]
platform = espressif32
board = az-delivery-devkit-v4
framework = arduino
build_flags =
-std=gnu++2a
Expand All @@ -31,3 +30,23 @@ extra_scripts =
; Serial Monitor options
upload_speed = 921600
monitor_speed = 115200

[env:fs]
# This exists so we don't build a filesystem per board.

# https://docs.platformio.org/en/stable/boards/espressif32/wemos_d1_mini32.html
[env:Wemos-D1-Mini-ESP32]
board = wemos_d1_mini32

# https://docs.platformio.org/en/latest/boards/espressif32/lolin_s2_mini.html
[env:Wemos-Lolin-S2-Mini]
board = lolin_s2_mini

# https://docs.platformio.org/en/latest/boards/espressif32/lolin_s3.html
# SOC:
[env:Wemos-Lolin-S3]
board = lolin_s3

# TODO:
# https://docs.platformio.org/en/latest/boards/espressif32/upesy_wroom.html#upesy-esp32-wroom-devkit
#

0 comments on commit d931834

Please sign in to comment.