Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Have firmware version be assigned by git + Create draft release from new tag build #360

Merged
merged 6 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches:
- main
pull_request:
workflow_dispatch:
create:

jobs:
format:
Expand Down Expand Up @@ -55,3 +57,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
37 changes: 35 additions & 2 deletions scripts/get_git_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,44 @@
else:
try:
revision = (
subprocess.check_output(["git", "rev-parse", "HEAD"])
subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
.strip()
.decode("utf-8")
)
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)
5 changes: 4 additions & 1 deletion src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,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_