Skip to content

Commit

Permalink
Merge pull request #589 from OpenEVSE/jeremypoulter/auto_version_fixes
Browse files Browse the repository at this point in the history
Fixes to the auto version number script
  • Loading branch information
jeremypoulter committed Apr 1, 2023
2 parents 4be7f09 + a2ce2fd commit 2ac0f88
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/release_validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@ jobs:
### Check the version number in the code matches the tag number
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Retrieve the version number(s)
run: |
TAG_VERSION=$GITHUB_REF_NAME
CODE_VERSION=$(git describe --tags)
CODE_VERSION=$(python3 scripts/auto_fw_version.py | grep -E 'BUILD_TAG=([^ ]+)' -o | cut -d= -f2)
echo TAG_VERSION=$TAG_VERSION >> $GITHUB_ENV
echo CODE_VERSION=$CODE_VERSION >> $GITHUB_ENV
Expand Down
45 changes: 33 additions & 12 deletions scripts/auto_fw_version.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
import subprocess
import os

Import("env")
def get_build_flag():
ret = subprocess.run(["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE, text=True) #Uses any tags
full_hash = ret.stdout.strip()
short_hash = full_hash[:8]

build_version = "local_" + short_hash

# get the GITHUB_REF_NAME
ref_name = os.environ.get('GITHUB_REF_NAME')
if ref_name:
if ref_name.startswith("v"):
build_version = ref_name
else:
build_version = ref_name + "_" + short_hash

def get_build_flag():
#ret = subprocess.run(["git", "describe"], stdout=subprocess.PIPE, text=True) #Uses only annotated tags
ret = subprocess.run(["git", "describe", "--tags"], stdout=subprocess.PIPE, text=True) #Uses any tags
build_version = ret.stdout.strip()
build_flag = "-D BUILD_TAG=" + build_version
print ("Firmware Revision: " + build_flag)
return (build_flag)

env.Append(
BUILD_FLAGS=[get_build_flag()]
)
# Check if the source has been modified since the last commit
ret = subprocess.run(["git", "diff-index", "--quiet", "HEAD", "--"], stdout=subprocess.PIPE, text=True)
if ret.returncode != 0:
build_version += "_modified"
short_hash += "_modified"
full_hash += "_modified"

build_flags = "-D BUILD_TAG=" + build_version + " " + "-D BUILD_HASH=" + short_hash + ""

return build_flags

build_flags = get_build_flag()

if "SCons.Script" == __name__:
print ("Firmware Revision: " + build_flags)
Import("env")
env.Append(
BUILD_FLAGS=[get_build_flag()]
)
elif "__main__" == __name__:
print(build_flags)
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void setup()
DEBUG.println();
DEBUG.printf("OpenEVSE WiFI %s\n", ESPAL.getShortId().c_str());
DEBUG.printf("Firmware: %s\n", currentfirmware.c_str());
DEBUG.printf("Git Hash: " ESCAPEQUOTE(BUILD_HASH) "\n");
DEBUG.printf("Build date: " __DATE__ " " __TIME__ "\n");
DEBUG.printf("IDF version: %s\n", ESP.getSdkVersion());
DEBUG.printf("Free: %d\n", ESPAL.getFreeHeap());
Expand Down

0 comments on commit 2ac0f88

Please sign in to comment.