Skip to content

Commit

Permalink
Updated git-rev.py for workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
oseiler2 committed Jul 24, 2022
1 parent 96aafef commit eb3a111
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
pip install --upgrade platformio
- name: Install platformIO libraries
run: pio pkg install
- name: Set env
run: echo "GITHUB_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Run PlatformIO
run: pio run --environment debug
- name: "Build & test"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tagged-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
pip install --upgrade platformio
- name: Install platformIO libraries
run: pio pkg install
- name: Set env
run: echo "GITHUB_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Run PlatformIO
run: pio run --environment release
- name: "Build & test"
Expand Down
37 changes: 33 additions & 4 deletions git-rev.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@
import subprocess
import time
import os

# get tag/base version
tag = subprocess.check_output("git describe --tags --abbrev=0", shell=True).decode().strip()
try:
tag = subprocess.check_output("git describe --tags --abbrev=0", shell=True).decode().strip()
except:
tag = "?"

GITHUB_TAG = os.environ.get('GITHUB_TAG')

if GITHUB_TAG is not None:
tag = GITHUB_TAG

if tag.startswith('v'):
tag = tag[1:]
version = tag

# get current revision hash
commit = subprocess.check_output("git log --pretty=format:%h -n 1", shell=True).decode().strip()
try:
commit = subprocess.check_output("git log --pretty=format:%h -n 1", shell=True).decode().strip()
except:
commit = "?"

GITHUB_SHA = os.environ.get('GITHUB_SHA')

if GITHUB_SHA is not None:
commit = GITHUB_SHA

# get branch name
branch = subprocess.check_output("git rev-parse --abbrev-ref HEAD", shell=True).decode().strip()
try:
branch = subprocess.check_output("git rev-parse --abbrev-ref HEAD", shell=True).decode().strip()
except:
branch = "unknown"

if GITHUB_TAG is not None:
branch = "main"

# if not main branch append branch name
if branch != "main":
version += "-[" + branch + "]"

# check if clean
clean = subprocess.check_output("git status -uno --porcelain", shell=True).decode().strip()
try:
clean = subprocess.check_output("git status -uno --porcelain", shell=True).decode().strip()
except:
clean = ""

ts = time.strftime('%Y%m%d%H%M%S')
# if not clean append timestamp
if clean != "":
Expand Down

0 comments on commit eb3a111

Please sign in to comment.