Skip to content

Commit

Permalink
Merge pull request linorobot#34 from atticusrussell/feature/platformi…
Browse files Browse the repository at this point in the history
…o-ci

Feature/ci pio (linorobot#1)
  • Loading branch information
grassjelly authored Jul 21, 2023
2 parents a4e412b + d2d54de commit 272498a
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/parse_platformio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import configparser
import json

""" This script parses the platformio.ini file and outputs a JSON array of environments to be used by GitHub Actions."""

# Parse the platformio.ini file
config = configparser.ConfigParser()
config.read('firmware/platformio.ini')

# Extract the environment names from the sections
environments = []
for section in config.sections():
if section.startswith("env:"):
env_name = section.split("env:")[1]
environments.append({"env": env_name})

# Output the environments as a JSON array
print(json.dumps(environments))
116 changes: 116 additions & 0 deletions .github/workflows/ci-pio.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: PlatformIO CI

# Controls when this action will run.
on:
push:
pull_request:
workflow_dispatch:

jobs:
# This job is used to build the calibration firmware
build-calibration:
name: Build Calibration
runs-on: ubuntu-latest

steps:
# Check out the repository
- uses: actions/checkout@v3

# Cache dependencies to speed up workflows
- uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio

- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install PlatformIO Core
run: pip install --upgrade platformio

- name: Build Calibration
run: |
cd calibration
pio run
# This job parses the firmware/platformio.ini file
pio-fw-matrix:
name: Parse firmware/platformio.ini
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}

steps:
# check out the repository
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

# run the python script to parse the platformio.ini file and output as json to a matrix
- name: Parse platformio.ini
id: set-matrix
run: |
echo "matrix=$(python .github/parse_platformio.py)" >> $GITHUB_OUTPUT
# This job builds the firmware for each environment parsed from the platformio.ini file
build-firmware:
# require the pio-fw-matrix job to complete before running
needs: pio-fw-matrix
runs-on: ubuntu-latest
name: Build ${{ matrix.env }} firmware
strategy:
# don't stop all jobs if one fails
fail-fast: false
# Build the firmware for each environment from parsing job in parallel
matrix:
include: ${{fromJson(needs.pio-fw-matrix.outputs.matrix)}}

steps:
# Check out the repository
- uses: actions/checkout@v3

# speed up workflows by caching dependencies
- uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio

- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install PlatformIO Core
run: pip install --upgrade platformio

- name: Install PIO in Home
run: |
python3 -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)"
echo "PATH=\"\$PATH:\$HOME/.platformio/penv/bin\"" >> $HOME/.bashrc
source $HOME/.bashrc
# NOTE all req. PIO pip packages should already be installed, but found these to be necessary
# Missing packages determined from error messages
- name: Install required pip packages
run: |
source $HOME/.platformio/penv/bin/activate
pip install --upgrade catkin_pkg
pip uninstall em
pip install empy lark
# Build the firmware for each environment in parallel
- name: Build Firmware
env:
ROS_DISTRO: rolling
run: |
cd firmware
pio run -e ${{ matrix.env }}

0 comments on commit 272498a

Please sign in to comment.