Skip to content

Workflow file for this run

name: C/C++ stm32 build for the open-source embedded software
on:
push:
branches: [ 'main' ]
paths: ['STM32/**', '.github/workflows/stm32build.yml']
pull_request:
branches: [ 'main' ]
paths: ['STM32/**', '.github/workflows/stm32build.yml']
jobs:
# JOB to run change detection
changes:
runs-on: ubuntu-latest
# Required permissions
permissions:
pull-requests: read
contents: read
outputs:
# Expose matched filters as job 'packages' output variable
packages: ${{ steps.filter.outputs.changes }}
steps:
# gets file environment with submodule included for libraries
- uses: actions/checkout@v3
with:
submodules: 'true'
# For pull requests it's not necessary to checkout the code
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
AC: STM32/AC/**
AirconCtrl: STM32/AirconCtrl/**
DC: STM32/DC/**
LightController: STM32/LightController/**
OTP: STM32/OTP/**
Temperature: STM32/Temperature/**
run_unittests:
needs: changes
if: ${{ needs.changes.outputs.packages != '[]' && needs.changes.outputs.packages != '' }}
strategy:
matrix:
# Parse JSON array containing names of all filters matching any of changed files
package: ${{ fromJSON(needs.changes.outputs.packages) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3 # gets file environment with submodule included for libraries
with:
submodules: 'true'
# Check whether the unittest folder exist in the modified project. If so, run unittests.
- name: Check if unittests exist
id: unittests_exists
run: |
if [ -d "STM32/${{ matrix.package }}/UnitTesting" ]; then
echo 'exist=1' >> $GITHUB_ENV
else
echo 'exist=0' >> $GITHUB_ENV
fi
# Build and run unittests. If the unittest fails the line number is output.
- name: Run unittests
if: env.exist == '1'
run: |
cd "STM32/${{ matrix.package }}/UnitTesting"
cmake CMakeLists.txt
make
output=$(./CA_UnitTesting)
echo $output
if [[ $output =~ "failed" ]]; then
echo "Test failed"
exit 1
fi
# Run the static code analysis test.
- name: Run static tests
run: STM32/CommonTests/code_generation_test.sh STM32/${{ matrix.package }}
build:
needs: changes
permissions:
pull-requests: read
contents: write
# If no changes has been made to projects above do not build
if: ${{ needs.changes.outputs.packages != '[]' && needs.changes.outputs.packages != '' }}
strategy:
matrix:
# Parse JSON array containing names of all filters matching any of changed files
package: ${{ fromJSON(needs.changes.outputs.packages) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3 # gets file environment with submodule included for libraries
with:
submodules: 'true'
- uses: carlosperate/arm-none-eabi-gcc-action@v1 # Setup the compiler and compile the program
- run: make
working-directory: 'STM32/${{ matrix.package }}/'
- uses: actions/upload-artifact@v3 # Upload the .elf and .bin file under the summary tab
with:
name: ${{ matrix.package }}
path: |
STM32/${{ matrix.package }}/build/${{ matrix.package }}.elf
STM32/${{ matrix.package }}/build/${{ matrix.package }}.bin
- uses: copenhagenatomics/mono_release_on_push_action@77f72f30f7ae516c440bb9e464eacc94a7f7f744
id: release-on-push
# if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # tag only pushes to the main branch
with:
bump_version_scheme: minor
use_github_release_notes: true
tag_prefix: "${{ matrix.package }}-"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Read PCB version
id: pcbversion
run: echo "version=$(head -1 STM32/${{ matrix.package }}/pcbversion)" >> $GITHUB_OUTPUT
- name: Release
# if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # upload only pushes to the main branch
uses: softprops/[email protected]
with:
files: |
**/*.elf
**/*.bin
tag_name: ${{ steps.release-on-push.outputs.tag_name }}
name: "${{ steps.release-on-push.outputs.tag_name }}-PCB${{ steps.pcbversion.outputs.version }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}