Skip to content
Snippets Groups Projects
Commit 1efb39f5 authored by q3k's avatar q3k
Browse files

st3m: make version.py aware of CI

parent 5ab461c2
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ and the release process. ...@@ -10,6 +10,7 @@ and the release process.
import subprocess import subprocess
import sys import sys
import os
class Tag: class Tag:
...@@ -50,7 +51,7 @@ def tags_for_commit(release, commit): ...@@ -50,7 +51,7 @@ def tags_for_commit(release, commit):
return res return res
def get_version(): def get_git_based_version():
commit = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip() commit = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip()
branches = ( branches = (
subprocess.check_output( subprocess.check_output(
...@@ -118,7 +119,15 @@ if len(sys.argv) > 1: ...@@ -118,7 +119,15 @@ if len(sys.argv) > 1:
if sys.argv[1] == "-c": if sys.argv[1] == "-c":
fmt = "C" fmt = "C"
v = get_version() v = None
if os.environ.get('CI') is not None:
tag = os.environ.get('CI_COMMIT_TAG')
if tag is not None:
# If we're building a tag, just use that as a version.
v = tag
if v is None:
v = get_git_based_version()
if fmt == "C": if fmt == "C":
print('const char *st3m_version = "' + v + '";') print('const char *st3m_version = "' + v + '";')
else: else:
......
...@@ -11,21 +11,12 @@ if [ ! -f sdkconfig.defaults ] || [ ! -f recovery/sdkconfig.defaults ]; then ...@@ -11,21 +11,12 @@ if [ ! -f sdkconfig.defaults ] || [ ! -f recovery/sdkconfig.defaults ]; then
exit 1 exit 1
fi fi
if [ ! -z "${CI}" ]; then # Always fetch full history on Gitlab when not building a tag, otherwise we get bogus results.
if [ ! -z "${CI_COMMIT_TAG}" ]; then if [ ! -z "${CI}" && -z "${CI_COMMIT_TAG}" ]; then
# If we're building a tag, just use that as a version.
version="${CI_COMMIT_TAG}"
else
# Otherwise, let normal version machinery run, but fetch all changes
# and check out the correct branch. Otherwise we'll get weird version
# strings.
git fetch --unshallow origin "$CI_COMMIT_REF_NAME" git fetch --unshallow origin "$CI_COMMIT_REF_NAME"
git checkout "$CI_COMMIT_REF_NAME" git checkout "$CI_COMMIT_REF_NAME"
version="$(python3 components/st3m/host-tools/version.py)"
fi fi
else
version="$(python3 components/st3m/host-tools/version.py)" version="$(python3 components/st3m/host-tools/version.py)"
fi
rm -rf sdkconfig build rm -rf sdkconfig build
rm -rf recovery/sdkconfig recovery/build rm -rf recovery/sdkconfig recovery/build
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment