From 129c7c6457189674a7fd96f4d34bf2b075270bd1 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Fri, 13 May 2022 10:21:16 +0200 Subject: [PATCH] refactor scripts and version --- .github/workflows/buid_check.yml | 60 +++++++++++++++++++++++++ .github/workflows/main.yml | 69 ----------------------------- .github/workflows/release.yml | 39 ++++++++++++++++ .github/workflows/tweet_release.yml | 19 ++++++++ .vscode/extensions.json | 18 +++++--- scripts/check_version.py | 49 ++++++++++++++++++++ scripts/create_version_tag.py | 21 +++++++++ src/LoRa_APRS_Tracker.cpp | 5 ++- 8 files changed, 203 insertions(+), 77 deletions(-) create mode 100644 .github/workflows/buid_check.yml delete mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/tweet_release.yml create mode 100755 scripts/check_version.py create mode 100755 scripts/create_version_tag.py diff --git a/.github/workflows/buid_check.yml b/.github/workflows/buid_check.yml new file mode 100644 index 0000000..accada7 --- /dev/null +++ b/.github/workflows/buid_check.yml @@ -0,0 +1,60 @@ +name: Integreation Tests + +on: + push: + branches: + - '*' + - '!master' + pull_request: + branches: + - master + +jobs: + build: + name: Compile Firmware + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + - name: Install PlatformIO + run: python -m pip install --upgrade pip platformio + - name: Run PlatformIO CI + run: platformio run + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: firmware + path: .pio/build/*/firmware.bin + + formatting-check: + name: Formatting Check + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Run clang-format style check for C/C++ programs. + uses: jidicula/clang-format-action@v4.6.2 + with: + clang-format-version: '11' + check-path: src + + cppcheck: + name: Run cppcheck + runs-on: ubuntu-latest + env: + CPPCHECK_ARGS: --enable=all --std=c++14 --inline-suppr src + steps: + - name: checkout code + uses: actions/checkout@v2 + - run: docker pull facthunder/cppcheck:latest + - name: Run cppcheck and print result + run: docker run --rm -v ${PWD}:/src facthunder/cppcheck:latest /bin/bash -c "cppcheck $CPPCHECK_ARGS" + - name: Run cppcheck and create html + run: docker run --rm -v ${PWD}:/src facthunder/cppcheck:latest /bin/bash -c "cppcheck --xml $CPPCHECK_ARGS 2> report.xml && cppcheck-htmlreport --file=report.xml --report-dir=output" + - name: Upload report + uses: actions/upload-artifact@v1 + with: + name: Cppcheck Report + path: output diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 5ad7719..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,69 +0,0 @@ - -name: check and build - -on: [push, pull_request] - -jobs: - PlatformIO-Check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Cache pip - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: ${{ runner.os }}-pip- - - name: Cache PlatformIO - uses: actions/cache@v2 - with: - path: ~/.platformio - key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} - - name: Set up Python - uses: actions/setup-python@v2 - - name: Install PlatformIO - run: | - python -m pip install --upgrade pip - pip install --upgrade platformio - - name: Run PlatformIO Check - run: platformio check --fail-on-defect low --fail-on-defect medium --fail-on-defect high - - PlatformIO-Build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Cache pip - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: ${{ runner.os }}-pip- - - name: Cache PlatformIO - uses: actions/cache@v2 - with: - path: ~/.platformio - key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} - - name: Set up Python - uses: actions/setup-python@v2 - - name: Install PlatformIO - run: | - python -m pip install --upgrade pip - pip install --upgrade platformio - - name: Run PlatformIO CI - run: platformio run - - uses: actions/upload-artifact@v2 - with: - name: firmware - path: .pio/build/*/firmware.bin - - formatting-check: - name: Formatting Check - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: Run clang-format style check for C/C++ programs. - uses: jidicula/clang-format-action@v4.6.2 - with: - clang-format-version: '11' - check-path: src diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..71a9939 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,39 @@ +name: Create new release + +on: + workflow_dispatch: + +jobs: + version_check: + name: Version Check + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v2 + - run: pip install GitPython + - name: check version + run: ./scripts/check_version.py + + create_release: + needs: version_check + name: Create new release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: sudo apt-get install python3-setuptools python3-wheel + - run: pip3 install platformio + - run: echo "$HOME/.local/bin" >> $GITHUB_PATH + - run: platformio run + - run: echo "VERSION=$(./scripts/create_version_tag.py)" >> $GITHUB_ENV + - uses: ncipollo/release-action@v1 + with: + tag: ${{ env.VERSION }} + commit: master + generateReleaseNotes: true + artifacts: ".pio/build/lora_board/firmware.bin,data/is-cfg.json" + owner: ${{ secrets.OWNER }} + token: ${{ secrets.PAT }} diff --git a/.github/workflows/tweet_release.yml b/.github/workflows/tweet_release.yml new file mode 100644 index 0000000..ce366a9 --- /dev/null +++ b/.github/workflows/tweet_release.yml @@ -0,0 +1,19 @@ +name: tweet-release + +on: + release: + types: [published] + +jobs: + tweet: + runs-on: ubuntu-latest + steps: + - uses: Eomm/why-don-t-you-tweet@v1 + if: ${{ !github.event.repository.private }} + with: + tweet-message: "New ${{ github.event.repository.name }} release ${{ github.event.release.tag_name }}! ${{ github.event.release.html_url }} #LoRa #APRS #HAM #hamradio #Tracker" + env: + TWITTER_CONSUMER_API_KEY: ${{ secrets.TWITTER_CONSUMER_API_KEY }} + TWITTER_CONSUMER_API_SECRET: ${{ secrets.TWITTER_CONSUMER_API_SECRET }} + TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} + TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 0f0d740..c4e499f 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,7 +1,11 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ] -} +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide", + "xaver.clang-format" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} \ No newline at end of file diff --git a/scripts/check_version.py b/scripts/check_version.py new file mode 100755 index 0000000..12535af --- /dev/null +++ b/scripts/check_version.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +import git +from datetime import date + +today = date.today() + +current_year = int(str(today.isocalendar()[0])[2:]) +current_week = int(today.isocalendar()[1]) + +version = None +with open("src/LoRa_APRS_Tracker.cpp") as f: + for line in f: + if line.startswith("#define VERSION"): + version = line.strip().split(" ")[-1].replace('"', "") + +version_split = version.split(".") +version_year = int(version_split[0]) +version_week = int(version_split[1]) +version_vers = int(version_split[2]) + +print(f"[INFO] firmware version year: {version_year}") +print(f"[INFO] firmware version week: {version_week}") +print(f"[INFO] firmware version version: {version_vers}") +print(f"[INFO] -> {version}") + +print(f"[INFO] current year: {current_year}") +print(f"[INFO] current week: {current_week}") +print(f"[INFO] -> {current_year}.{current_week}.x") + +error = False +if version_year != current_year: + print("[ERROR] firmware version is not current year!") + error = True + +if version_week != current_week: + print("[ERROR] firmware version is not current week!") + error = True + +repo = git.Repo('.') +print(f"[INFO] found {len(repo.tags)} tags in repo") +if f"v{version}" in repo.tags: + print("[ERROR] tag with this version is already existing") + error = True + +if error: + print("[ERROR] check/update VERSION define in src/LoRa_APRS_iGate.cpp to fix this issue") + +exit(error) diff --git a/scripts/create_version_tag.py b/scripts/create_version_tag.py new file mode 100755 index 0000000..5b37c82 --- /dev/null +++ b/scripts/create_version_tag.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +from datetime import date + +today = date.today() + +current_year = int(str(today.isocalendar()[0])[2:]) +current_week = int(today.isocalendar()[1]) + +version = None +with open("src/LoRa_APRS_iGate.cpp") as f: + for line in f: + if line.startswith("#define VERSION"): + version = line.strip().split(" ")[-1].replace('"', "") + +version_split = version.split(".") +version_year = int(version_split[0]) +version_week = int(version_split[1]) +version_vers = int(version_split[2]) + +print(f"v{version_year}.{version_week}.{version_vers}") diff --git a/src/LoRa_APRS_Tracker.cpp b/src/LoRa_APRS_Tracker.cpp index c272ad6..c64aa4f 100644 --- a/src/LoRa_APRS_Tracker.cpp +++ b/src/LoRa_APRS_Tracker.cpp @@ -13,6 +13,8 @@ #include "pins.h" #include "power_management.h" +#define VERSION "22.14.0" + Configuration Config; BeaconManager BeaconMan; @@ -75,9 +77,10 @@ void setup() { delay(500); logPrintlnI("LoRa APRS Tracker by OE5BPA (Peter Buchegger)"); + logPrintlnI("Version: " VERSION); setup_display(); - show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", 2000); + show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", "Version: " VERSION, 2000); load_config(); setup_gps();