From c58f0e4779fe900d1ca027a1a6bf20628fccae95 Mon Sep 17 00:00:00 2001 From: loucass003 Date: Fri, 8 Nov 2024 17:13:51 +0100 Subject: [PATCH 1/5] Have firmware version be assigned by git + Create draft release from new tag build --- .github/workflows/actions.yml | 13 +++++++++++++ scripts/get_git_commit.py | 35 ++++++++++++++++++++++++++++++++++- src/debug.h | 5 ++++- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index d2714f081..c8ae3feff 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,11 @@ name: Build on: push: + branches: + - main pull_request: + workflow_dispatch: + create: jobs: build: @@ -35,3 +39,12 @@ jobs: with: name: binaries path: ./build/*.bin + + - name: Upload to draft release + uses: softprops/action-gh-release@v2 + if: startsWith(github.ref, 'refs/tags/') + with: + draft: true + generate_release_notes: true + files: | + ./build/BOARD_SLIMEVR-firmware.bin diff --git a/scripts/get_git_commit.py b/scripts/get_git_commit.py index ba482183a..0cb43fc22 100644 --- a/scripts/get_git_commit.py +++ b/scripts/get_git_commit.py @@ -16,4 +16,37 @@ except Exception: revision = "NOT_GIT" -print(f"'-DGIT_REV=\"{revision}\"'") +tag = "" +try: + tag = ( + subprocess.check_output["git", "--no-pager", "tag", "--sort", "-taggerdate", "--points-at" , "HEAD"] + .split("\n")[0] + .strip() + .decode("utf-8") + ) + + if tag.startswith("v"): + tag = tag[1:] +except Exception: + tag = "" + +branch = "" +try: + branch = ( + subprocess.check_output["git", "symbolic-ref", "--short", "-q", "HEAD"] + .strip() + .decode("utf-8") + ) +except Exception: + branch = "" + +output = f'-DGIT_REV=\"{revision}\"' + +if tag != "": + output += f' -DFIRMWARE_VERSION=\"{tag}\"' +if tag == "" and branch != "": + output += f' -DFIRMWARE_VERSION=\"{branch}\"' +else: + output += f' -DFIRMWARE_VERSION=\"git-{revision}\"' + +print(output) diff --git a/src/debug.h b/src/debug.h index 5e794f26b..0fb18be98 100644 --- a/src/debug.h +++ b/src/debug.h @@ -90,6 +90,9 @@ #define ENABLE_INSPECTION false #define PROTOCOL_VERSION 18 -#define FIRMWARE_VERSION "0.5.0" + +#ifndef FIRMWARE_VERSION + #define FIRMWARE_VERSION "UNKNOWN" +#endif #endif // SLIMEVR_DEBUG_H_ From 378d0a9796b1cd4361481d96ac128f190fe9b716 Mon Sep 17 00:00:00 2001 From: loucass003 Date: Fri, 8 Nov 2024 17:22:39 +0100 Subject: [PATCH 2/5] Fix quotes --- scripts/get_git_commit.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/get_git_commit.py b/scripts/get_git_commit.py index 0cb43fc22..6d20847a9 100644 --- a/scripts/get_git_commit.py +++ b/scripts/get_git_commit.py @@ -40,13 +40,13 @@ except Exception: branch = "" -output = f'-DGIT_REV=\"{revision}\"' +output = f"'-DGIT_REV=\"{revision}\"'" if tag != "": - output += f' -DFIRMWARE_VERSION=\"{tag}\"' + output += f" '-DFIRMWARE_VERSION=\"{tag}\"'" if tag == "" and branch != "": - output += f' -DFIRMWARE_VERSION=\"{branch}\"' + output += f" '-DFIRMWARE_VERSION=\"{branch}\"'" else: - output += f' -DFIRMWARE_VERSION=\"git-{revision}\"' + output += f" '-DFIRMWARE_VERSION=\"git-{revision}\"'" print(output) From 10cc1ba8cddad3a05458a8629606197c1ce20d9e Mon Sep 17 00:00:00 2001 From: loucass003 Date: Fri, 8 Nov 2024 17:49:13 +0100 Subject: [PATCH 3/5] Short commit id --- scripts/get_git_commit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/get_git_commit.py b/scripts/get_git_commit.py index 6d20847a9..4c9ece05d 100644 --- a/scripts/get_git_commit.py +++ b/scripts/get_git_commit.py @@ -9,7 +9,7 @@ else: try: revision = ( - subprocess.check_output(["git", "rev-parse", "HEAD"]) + subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]) .strip() .decode("utf-8") ) From 1ca9a27ad434972b35910cd1ccd4b7f000e2368f Mon Sep 17 00:00:00 2001 From: loucass003 Date: Fri, 8 Nov 2024 18:12:12 +0100 Subject: [PATCH 4/5] Fix function call --- scripts/get_git_commit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/get_git_commit.py b/scripts/get_git_commit.py index 4c9ece05d..de446bc32 100644 --- a/scripts/get_git_commit.py +++ b/scripts/get_git_commit.py @@ -19,7 +19,7 @@ tag = "" try: tag = ( - subprocess.check_output["git", "--no-pager", "tag", "--sort", "-taggerdate", "--points-at" , "HEAD"] + subprocess.check_output(["git", "--no-pager", "tag", "--sort", "-taggerdate", "--points-at" , "HEAD"]) .split("\n")[0] .strip() .decode("utf-8") @@ -33,7 +33,7 @@ branch = "" try: branch = ( - subprocess.check_output["git", "symbolic-ref", "--short", "-q", "HEAD"] + subprocess.check_output(["git", "symbolic-ref", "--short", "-q", "HEAD"]) .strip() .decode("utf-8") ) From dcb4cf90724c98aaa1d26ade083c7b0f730b8eda Mon Sep 17 00:00:00 2001 From: loucass003 Date: Fri, 8 Nov 2024 19:08:10 +0100 Subject: [PATCH 5/5] clang-format --- src/debug.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debug.h b/src/debug.h index 438888775..79cc6ec52 100644 --- a/src/debug.h +++ b/src/debug.h @@ -97,7 +97,7 @@ #define PROTOCOL_VERSION 18 #ifndef FIRMWARE_VERSION - #define FIRMWARE_VERSION "UNKNOWN" +#define FIRMWARE_VERSION "UNKNOWN" #endif #endif // SLIMEVR_DEBUG_H_