-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #589 from OpenEVSE/jeremypoulter/auto_version_fixes
Fixes to the auto version number script
- Loading branch information
Showing
3 changed files
with
40 additions
and
13 deletions.
There are no files selected for viewing
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
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
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) |
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