Skip to content

Move static code generation test to unittest folder - Embedded #233

Move static code generation test to unittest folder - Embedded

Move static code generation test to unittest folder - Embedded #233

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@v4
with:
submodules: 'true'
# For pull requests it's not necessary to checkout the code
- uses: dorny/paths-filter@v3
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@v4 # 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 "unit_testing/${{ matrix.package }}" ]; then
echo 'exist=1' >> $GITHUB_ENV
else
echo 'exist=0' >> $GITHUB_ENV
fi
- uses: actions/setup-python@v4
with:
python-version: '3.10'
# Build and run unittests. If the unittest fails the line number is output.
- name: Run unittests
if: env.exist == '1'
run: |
cd unit_testing
python unitTests.py -D ${{ matrix.package }}
# Run the static code analysis test.
- name: Run static tests
run: |
cd unit_testing
./code_generation_test.sh ${{ 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:
# gets file environment with submodule included for libraries
- uses: actions/checkout@v4
with:
submodules: 'true'
# Setup the compiler and compile the program
- uses: carlosperate/arm-none-eabi-gcc-action@v1
# Generate the next release + tag for including in the build
- uses: copenhagenatomics/mono_release_on_push_action@master
id: release-on-push-1
with:
bump_version_scheme: minor
# Tag prefix required for this action to update the most relevant version number
tag_prefix: "${{ matrix.package }}-"
# Note: This is a dry_run, because if something goes wrong in the build (next step), we
# don't want to actually make any release.
dry_run: "true"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Tag Filter
id: tagfilter
run: echo "version=$(echo "${{ steps.release-on-push-1.outputs.tag_name }}" | cut -d'-' -f2)" >> $GITHUB_OUTPUT
# Build the upload artifacts
- run: make
working-directory: "STM32/${{ matrix.package }}/"
env:
VERSION_TAG: ${{ steps.tagfilter.outputs.version }}
# Upload the .elf and .bin file under the summary tab
- uses: actions/upload-artifact@v3
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@master
id: release-on-push-2
# tag only pushes to the main branch
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
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
# Checks if the file pcbversion exists and that the first line is configured as a version number with v<number>.number and returns the first line, otherwise it returns v0.0.
run: |
if [[ -e STM32/${{ matrix.package }}/Core/Inc/pcbversion.h ]]; then
echo "versionfile=STM32/${{ matrix.package }}/Core/Inc/pcbversion.h" >> $GITHUB_OUTPUT
echo "latest=$(eval "./util/pcbversion.py STM32/${{ matrix.package }}/Core/Inc/pcbversion.h latest both")" >> $GITHUB_OUTPUT
echo "breaking=$(eval "./util/pcbversion.py STM32/${{ matrix.package }}/Core/Inc/pcbversion.h breaking both")" >> $GITHUB_OUTPUT
else
echo "versionfile=STM32/${{ matrix.package }}/pcbversion" >> $GITHUB_OUTPUT
echo "latest=$(eval "./util/pcbversion.py STM32/${{ matrix.package }}/pcbversion latest both")" >> $GITHUB_OUTPUT
echo "breaking=$(eval "./util/pcbversion.py STM32/${{ matrix.package }}/pcbversion breaking both")" >> $GITHUB_OUTPUT
fi
- 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-2.outputs.tag_name }}
name: "${{ steps.release-on-push-2.outputs.tag_name }}-PCBv${{ steps.pcbversion.outputs.latest }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare zip file for Azure blob
run: zip -j ${{ matrix.package }}.zip STM32/${{ matrix.package }}/build/${{ matrix.package }}.elf STM32/${{ matrix.package }}/build/${{ matrix.package }}.bin
shell: bash
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Test PCB file
run: python release_mgmt/updatePcbVersionList.py "${{ steps.pcbversion.outputs.versionfile }}"
env :
AZURE_BLOB_QUERYSTRING : ${{ secrets.AZURE_BLOB_QUERYSTRING }}
MODULE_NAME : ${{ matrix.package }}
- name: Manage PCB Versioning
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # File only updated on merge into main (not on pull-request)
run: python release_mgmt/managePcbVersions.py -c $(echo "${{ steps.pcbversion.outputs.latest }}" | sed 's/[a-zA-Z]//g') -b $(echo "${{ steps.pcbversion.outputs.breaking }}" | sed 's/[a-zA-Z]//g') -fw ${{ steps.tagfilter.outputs.version }} -m ${{ matrix.package }}
env :
AZURE_BLOB_QUERYSTRING : ${{ secrets.AZURE_BLOB_QUERYSTRING }}