revert argument #43
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
name: Test, Build and Release | |
on: | |
workflow_dispatch: | |
push: | |
branches: [main, develop, sonar_ci] | |
jobs: | |
versioning: | |
name: Determine version, Test, Build and Release | |
permissions: write-all | |
runs-on: ubuntu-latest | |
outputs: | |
branchname: ${{ steps.versioninfo.outputs.branchname }} | |
commithash: ${{ steps.versioninfo.outputs.commithash }} | |
buildtimestamp: ${{ steps.versioninfo.outputs.buildtimestamp }} | |
buildEpoch: ${{ steps.versioninfo.outputs.buildEpoch }} | |
lastmajordigit: ${{ steps.versioninfo.outputs.lastmajordigit }} | |
lastminordigit: ${{ steps.versioninfo.outputs.lastminordigit }} | |
lastpatchdigit: ${{ steps.versioninfo.outputs.lastpatchdigit }} | |
lastversion: ${{ steps.versioninfo.outputs.lastversion }} | |
nextmajordigit: ${{ steps.selectversion.outputs.nextmajordigit }} | |
nextminordigit: ${{ steps.selectversion.outputs.nextminordigit }} | |
nextpatchdigit: ${{ steps.selectversion.outputs.nextpatchdigit }} | |
buildversion: ${{ steps.selectversion.outputs.buildversion }} | |
buildversionfilename: ${{ steps.selectversion.outputs.buildversionfilename }} | |
env: | |
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory | |
steps: | |
# - name: Enable caching | |
# uses: actions/cache@v3 | |
# with: | |
# path: | | |
# ~/.cache/pip | |
# ~/.platformio/.cache | |
# key: ${{ runner.os }}-pio | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get version data | |
id: versioninfo | |
run: | | |
echo "extract branch name from github_ref '${{ github.ref }}'" | |
declare branchname=$(echo "${{ github.ref }}" | cut -d'/' -f 3-) | |
echo "clean branch name = $branchname" | |
echo "extract commit short hash : $(git rev-parse --short HEAD)" | |
declare commithash=$(git rev-parse --short HEAD) | |
echo "extract build timestamp" | |
declare buildtimestamp=$(date +"%a %b %d %H:%M:%S %Y") | |
echo "buildtimestamp = $buildtimestamp" | |
declare -i buildEpoch=$(date "+%s") | |
declare fulltag=$(git describe --tag $(git rev-parse --verify refs/remotes/origin/main)) | |
echo "fulltag = [$fulltag]" | |
declare versiontag=$(echo $fulltag | cut -d'-' -f1) | |
echo "extract SemVer numbers from version tag [$versiontag]" | |
declare -i lastmajordigit=$(echo $versiontag | cut -c 2- | cut -d'.' -f1) | |
echo "lastmajordigit = $lastmajordigit" | |
declare -i lastminordigit=$(echo $versiontag | cut -c 2- | cut -d'.' -f2) | |
echo "lastminordigit = $lastminordigit" | |
declare -i lastpatchdigit=$(echo $versiontag | cut -c 2- | cut -d'.' -f3) | |
echo "lastpatchdigit = $lastpatchdigit" | |
declare lastversion="v$lastmajordigit.$lastminordigit.$lastpatchdigit" | |
echo "output variables to GitHub Actions" | |
echo "branchname=$branchname" >> $GITHUB_OUTPUT | |
echo "lastmajordigit=$lastmajordigit" >> $GITHUB_OUTPUT | |
echo "lastminordigit=$lastminordigit" >> $GITHUB_OUTPUT | |
echo "lastpatchdigit=$lastpatchdigit" >> $GITHUB_OUTPUT | |
echo "commithash=$commithash" >> $GITHUB_OUTPUT | |
echo "buildtimestamp=$buildtimestamp" >> $GITHUB_OUTPUT | |
echo "buildEpoch=$buildEpoch" >> $GITHUB_OUTPUT | |
echo "lastversion=$lastversion" >> $GITHUB_OUTPUT | |
- name: Determine which version to build | |
id: selectversion | |
run: | | |
echo "Triggered from Branch : ${{ steps.versioninfo.outputs.branchname }}" | |
echo "Commit hash : ${{ steps.versioninfo.outputs.commithash }}" | |
echo "Last version : ${{ steps.versioninfo.outputs.lastversion }}" | |
echo " Major : ${{ steps.versioninfo.outputs.lastmajordigit }}" | |
echo " Minor : ${{ steps.versioninfo.outputs.lastminordigit }}" | |
echo " Patch : ${{ steps.versioninfo.outputs.lastpatchdigit }}" | |
if [ "${{ steps.versioninfo.outputs.branchname }}" == "main" ]; then | |
echo "Triggered from merge on main branch with commit title : ${{ github.event.head_commit.message }}" | |
if [[ "${{ github.event.head_commit.message }}" == *"major"* ]]; then | |
echo "Incrementing Major versionDigit" | |
declare -i nextmajordigit=${{ steps.versioninfo.outputs.lastmajordigit }}+1 | |
declare -i nextminordigit=0 | |
declare -i nextpatchdigit=0 | |
declare buildversion="v$nextmajordigit.$nextminordigit.$nextpatchdigit" | |
declare buildversionfilename=$(echo "${buildversion//./_}") | |
elif [[ "${{ github.event.head_commit.message }}" == *"minor"* ]]; then | |
echo "Incrementing Minor versionDigit" | |
declare -i nextmajordigit=${{ steps.versioninfo.outputs.lastmajordigit }} | |
declare -i nextminordigit=${{ steps.versioninfo.outputs.lastminordigit }}+1 | |
declare -i nextpatchdigit=0 | |
declare buildversion="v$nextmajordigit.$nextminordigit.$nextpatchdigit" | |
declare buildversionfilename=$(echo "${buildversion//./_}") | |
else | |
echo "Incrementing Patch versionDigit" | |
declare -i nextmajordigit=${{ steps.versioninfo.outputs.lastmajordigit }} | |
declare -i nextminordigit=${{ steps.versioninfo.outputs.lastminordigit }} | |
declare -i nextpatchdigit=${{ steps.versioninfo.outputs.lastpatchdigit }}+1 | |
declare buildversion="v$nextmajordigit.$nextminordigit.$nextpatchdigit" | |
declare buildversionfilename=$(echo "${buildversion//./_}") | |
fi | |
else | |
echo "Not on main branch -> development version" | |
declare -i nextmajordigit=${{ steps.versioninfo.outputs.lastmajordigit }} | |
declare -i nextminordigit=${{ steps.versioninfo.outputs.lastminordigit }} | |
declare -i nextpatchdigit=${{ steps.versioninfo.outputs.lastpatchdigit }} | |
declare buildversion="v$nextmajordigit.$nextminordigit.$nextpatchdigit-${{ steps.versioninfo.outputs.commithash }}" | |
declare buildversionfilename=$(echo "${buildversion//./_}") | |
fi | |
echo "Building Version : $buildversion" | |
echo " Major : $nextmajordigit" | |
echo " Minor : $nextminordigit" | |
echo " Patch : $nextpatchdigit" | |
echo "Filename : $buildversionfilename" | |
echo "output variables to GitHub Actions" | |
echo "nextmajordigit=$nextmajordigit" >> $GITHUB_OUTPUT | |
echo "nextminordigit=$nextminordigit" >> $GITHUB_OUTPUT | |
echo "nextpatchdigit=$nextpatchdigit" >> $GITHUB_OUTPUT | |
echo "buildversion=$buildversion" >> $GITHUB_OUTPUT | |
echo "buildversionfilename=$buildversionfilename" >> $GITHUB_OUTPUT | |
- name: Show Build info | |
id: showbuildinfo | |
run: | | |
echo "Build Version : ${{ steps.selectversion.outputs.buildversion }}" | |
echo " Major : ${{ steps.selectversion.outputs.nextmajordigit }}" | |
echo " Minor : ${{ steps.selectversion.outputs.nextminordigit }}" | |
echo " Patch : ${{ steps.selectversion.outputs.nextpatchdigit }}" | |
echo "Build Filename : ${{ steps.selectversion.outputs.buildversionfilename }}.bin" | |
echo "Build Timestamp : ${{ steps.versioninfo.outputs.buildtimestamp }}" | |
echo "Build Epoch : ${{ steps.versioninfo.outputs.buildEpoch }}" | |
- name: Save Build info | |
uses: "DamianReeves/write-file-action@master" | |
with: | |
path: lib/version/buildinfo.cpp | |
write-mode: overwrite | |
contents: | | |
// ########################################################################## | |
// ### This file is generated by Build and Continuous Integration scripts ### | |
// ### .github/workflows/buildinfo.py for local development environment ### | |
// ### .github/workflows/testbuildrelease.yml for CI environment ### | |
// ### Changes will be overwritten on the next build ### | |
// ########################################################################## | |
#include <buildinfo.hpp> | |
const buildEnvironment buildInfo::theBuildEnvironment{buildEnvironment::ci}; | |
const buildType buildInfo::theBuildType{buildType::production}; | |
const int buildInfo::mainVersionDigit = ${{ steps.selectversion.outputs.nextmajordigit }}; | |
const int buildInfo::minorVersionDigit = ${{ steps.selectversion.outputs.nextminordigit }}; | |
const int buildInfo::patchVersionDigit = ${{ steps.selectversion.outputs.nextpatchdigit }}; | |
const char* buildInfo::lastCommitTag = "${{ steps.versioninfo.outputs.commithash }}"; | |
const char* buildInfo::buildTimeStamp = "${{ steps.versioninfo.outputs.buildtimestamp }}"; | |
const time_t buildInfo::buildEpoch = ${{ steps.versioninfo.outputs.buildEpoch }}; | |
- name: Verify Saved Build info | |
run: | | |
cat lib/version/buildinfo.cpp | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.9" | |
- name: Install gcovr 5.0 | |
run: | | |
pip install gcovr==5.0 | |
- name: Install sonar-scanner and build-wrapper | |
uses: sonarsource/sonarcloud-github-c-cpp@v3 | |
- name: Install PlatformIO Core | |
run: | | |
pip install --upgrade platformio | |
pio pkg install --environment production | |
- name: Check PlatformIO | |
run: | | |
pio system info | |
- name: Run all generic unit tests | |
run: | | |
pio test -e all_generic_unittests | |
- name: Upload coverage reports to Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
gcov: true | |
gcov_include: '.pio/build/all_generic_unittests/*' | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
- name: Generate Compilation DataBase | |
run: | | |
pio run -t compiledb | |
- name: Build | |
run: | | |
pio run -e production | |
- name: Collect coverage into XML report | |
run: | | |
gcovr --sonarqube > coverage.xml | |
- name: Run sonar-scanner | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: | | |
sonar-scanner \ | |
--define sonar.projectKey=Strooom_PN7160 \ | |
--define sonar.organization=strooom-1 \ | |
--define sonar.coverageReportPaths=coverage.xml | |
- name: Attach Binary to Workflow run | |
id: attachbinarytoworkflowrun | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ steps.selectversion.outputs.buildversionfilename }}.elf | |
path: .pio/build/production/firmware.elf | |
if-no-files-found: error | |
- name: Release when on main branch | |
id: createrelease | |
uses: actions/create-release@v1 | |
if: ${{ steps.versioninfo.outputs.branchname == 'main'}} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.selectversion.outputs.buildversion }} | |
release_name: Release ${{ steps.selectversion.outputs.buildversion }} | |
draft: false | |
prerelease: false | |
- name: Attach Binary to Release | |
id: attachbinarytorelease | |
uses: actions/upload-release-asset@v1 | |
if: ${{ steps.versioninfo.outputs.branchname == 'main'}} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.createrelease.outputs.upload_url }} | |
asset_path: .pio/build/production/firmware.elf | |
asset_name: ${{ steps.selectversion.outputs.buildversionfilename }}.elf | |
asset_content_type: application/octet-stream |