Bump actions/checkout from 3 to 4 #94
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
# | |
# Copyright (C) 2019-2021 OpenBikeSensor Contributors | |
# Contact: https://openbikesensor.org | |
# | |
# This file is part of the OpenBikeSensor firmware. | |
# | |
# The OpenBikeSensor firmware is free software: you can redistribute it | |
# and/or modify it under the terms of the GNU Lesser General Public License as | |
# published by the Free Software Foundation, either version 3 of the License, | |
# or (at your option) any later version. | |
# | |
# OpenBikeSensor firmware is distributed in the hope that it will be | |
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | |
# General Public License for more details. | |
# | |
# You should have received a copy of the GNU Lesser General Public License | |
# along with the OpenBikeSensor firmware. If not, see | |
# <http://www.gnu.org/licenses/>. | |
# | |
name: OpenBikeSensor - CI | |
on: | |
# Trigger when pushing in main or pull requests, and when creating | |
# a pull request. | |
push: | |
branches: | |
- main | |
pull_request: | |
types: [opened, synchronize, reopened] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Cache pip | |
uses: actions/[email protected] | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Cache PlatformIO | |
uses: actions/[email protected] | |
with: | |
path: ~/.platformio | |
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} | |
- name: Set up Python | |
uses: actions/[email protected] | |
- name: Install PlatformIO | |
run: | | |
python -m pip install --upgrade pip | |
pip install --upgrade platformio | |
- name: Prepare source | |
run: | | |
mkdir bin | |
echo GITHUB Ref: ${{ github.ref }} | |
VERSION_STRING=`grep "const char \*VERSION =" src/main.c` | |
MAJOR=`echo ${VERSION_STRING} | cut -f2 -d\"` | |
if [ "${{ github.ref }}" = "refs/heads/main" ] | |
then | |
PATCH=${GITHUB_RUN_NUMBER} | |
SEPARATOR=. | |
PREPARE_RELEASE=true | |
else | |
PATCH=RC${GITHUB_RUN_NUMBER} | |
SEPARATOR=- | |
PREPARE_RELEASE=false | |
fi | |
VERSION=${MAJOR}${SEPARATOR}${PATCH} | |
echo "OBS_PREPARE_RELEASE=${PREPARE_RELEASE}" >> $GITHUB_ENV | |
echo "OBS_FLASH_VERSION=${VERSION}" >> $GITHUB_ENV | |
echo "PROJECT_VER=${VERSION}" >> $GITHUB_ENV | |
echo "OBS_MAJOR_VERSION=${MAJOR}" >> $GITHUB_ENV | |
echo $VERSION > VERSION | |
echo $VERSION > version.txt | |
echo Building OBS Version: $VERSION | |
sed -i 's|-DBUILD_NUMBER=\\"-dev\\"|-DPROJECT_VER=${VERSION} -DBUILD_NUMBER=\\"'${SEPARATOR}${PATCH}'\\"|' platformio.ini | |
echo "SONAR_SCANNER_VERSION=4.6.2.2472" >> $GITHUB_ENV | |
- name: Cache SonarCloud packages | |
id: cache-sonar | |
uses: actions/[email protected] | |
with: | |
path: | | |
~/.sonar/cache | |
sonarqube | |
key: ${{ runner.os }}-sonar-${{ env.SONAR_SCANNER_VERSION }}-ng | |
restore-keys: ${{ runner.os }}-sonar-${{ env.SONAR_SCANNER_VERSION }}-ng | |
- name: Install SonarQube dependencies | |
if: steps.cache-sonar.outputs.cache-hit != 'true' | |
run: | | |
mkdir -p sonarqube | |
cd sonarqube | |
wget --no-verbose https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip | |
unzip -qq build-wrapper-linux-x86.zip | |
rm build-wrapper-linux-x86.zip | |
wget --no-verbose https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip | |
unzip -qq sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip | |
rm sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip | |
cd .. | |
- name: Install build dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -qq -y zip | |
- name: Build flashsd | |
run: | | |
mkdir sonarqube-out | |
./sonarqube/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir sonarqube-out \ | |
platformio run --disable-auto-clean | |
# platformio ci -v --build-dir="./bin" --keep-build-dir --project-conf=platformio.ini ./src/ | |
- name: Package firmware | |
run: | | |
cp .pio/build/esp32dev/firmware.bin 0x10000.bin | |
cp .pio/build/esp32dev/firmware.bin flash.bin | |
wget --no-verbose -O COPYRIGHT-ESP.html https://docs.espressif.com/projects/esp-idf/en/latest/esp32/COPYRIGHT.html | |
zip --junk-paths obs-flash-${{ env.OBS_FLASH_VERSION }}.zip \ | |
flash.bin \ | |
COPYRIGHT-ESP.html \ | |
LICENSE | |
- name: Analyze with SonarCloud | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# Hack - point sonarqube to the real sources not the copy of it | |
# See also https://community.sonarsource.com/t/scanning-platformio-c-embeded-projects/35141/2 | |
# sed -i 's|OpenBikeSensorFlash/bin|OpenBikeSensorFlash|g' \ | |
# sonarqube-out/build-wrapper-dump.json | |
# looks like pio copys our source from the main folder to a src folder | |
# sed -i 's|"src/|"main/|g' \ | |
# sonarqube-out/build-wrapper-dump.json | |
# sed -i 's|\.pio/|bin/.pio/|g' \ | |
# sonarqube-out/build-wrapper-dump.json | |
# replace gcc with our script that reports the fake arch "le32-unknown-nacl" | |
sed -i "s|/github/home/.platformio/packages/toolchain-xtensa32/bin/xtensa-esp32-elf-g..|`pwd`/.github/fake-cc|g" \ | |
sonarqube-out/build-wrapper-dump.json | |
./sonarqube/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin/sonar-scanner \ | |
-Dsonar.host.url=https://sonarcloud.io \ | |
-Dsonar.organization=openbikesensor \ | |
-Dsonar.projectKey=openbikesensor_OpenBikeSensorFlash \ | |
-Dsonar.coverage.exclusions=**/* \ | |
-Dsonar.sources=src \ | |
-Dsonar.sourceEncoding=UTF-8 \ | |
-Dsonar.cfamily.cache.enabled=false \ | |
-Dsonar.cfamily.threads=1 \ | |
-Dsonar.cfamily.build-wrapper-output=sonarqube-out \ | |
-Dsonar.projectVersion=${{ env.OBS_MAJOR_VERSION }} || echo Result: $? | |
- name: Upload Build Asset | |
uses: actions/upload-artifact@v3 | |
with: | |
name: obs-flash-${{ env.OBS_FLASH_VERSION }} | |
path: | | |
flash.bin | |
sonarqube-out/build-wrapper-dump.json | |
COPYRIGHT-ESP.html | |
LICENSE | |
if-no-files-found: error | |
- name: Generate changelog | |
id: changelog | |
if: ${{ env.OBS_PREPARE_RELEASE == 'true' }} | |
uses: metcalfc/[email protected] | |
with: | |
myToken: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create Release | |
id: create_release | |
if: ${{ env.OBS_PREPARE_RELEASE == 'true' }} | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ env.OBS_FLASH_VERSION }} | |
release_name: ${{ env.OBS_FLASH_VERSION }} | |
body: | | |
![GitHub downloads](https://img.shields.io/github/downloads-pre/openbikesensor/OpenBikeSensorFlash/${{ env.OBS_FLASH_VERSION }}/total) ![GitHub commits since release](https://img.shields.io/github/commits-since/openbikesensor/OpenBikeSensorFlash/${{ github.sha }}?label=commits%20since%20${{ env.OBS_FLASH_VERSION }}) | |
Version ${{ env.OBS_FLASH_VERSION }} based on ${{ github.ref }} ${{ github.sha }} | |
${{ steps.changelog.outputs.changelog }} | |
## :tada: Major features and improvements | |
## :rocket: New features and improvements | |
## :bug: Bug Fixes | |
## :ghost: Maintenance | |
## :package: Dependency updates | |
## :construction_worker: Changes for developers / internal | |
draft: true | |
prerelease: true | |
- name: Upload Release Asset | |
id: upload-release-asset | |
if: ${{ env.OBS_PREPARE_RELEASE == 'true' }} | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./obs-flash-${{ env.OBS_FLASH_VERSION }}.zip | |
asset_name: obs-flash-${{ env.OBS_FLASH_VERSION }}.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset flash bin | |
id: upload-release-asset-flash-bin | |
if: ${{ env.OBS_PREPARE_RELEASE == 'true' }} | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: flash.bin | |
asset_name: flash.bin | |
asset_content_type: application/x-esp32 |