using python for some conditional stuff instead of bash
Some checks failed
Autotagger / Autotagger (push) Failing after 3s
Build / Documentation (push) Successful in 13s
Build / Export Files (push) Successful in 4s

This commit is contained in:
SeaswimmerTheFsh 2024-03-11 21:32:35 -04:00
parent 7da86574e6
commit a902fb01eb
Signed by: cswimr
GPG key ID: B8953EC01E5C4063
2 changed files with 27 additions and 11 deletions

View file

@ -27,18 +27,14 @@ jobs:
id: check_commit_message
run: |
COMMIT_MESSAGE=$(echo "${{ steps.extract_commit_message.outputs.message }}")
PATTERN="^(?:V|v)ersion\ bump(?:ed)?\ to\ ([0-9]+\.[0-9]+\.[0-9]+(?:-[a-zA-Z0-9]+)?).*"
if echo "$COMMIT_MESSAGE" | grep -E "$PATTERN"; then
echo "Found version bump in commit message."
echo "::set-output name=version::${BASH_REMATCH[1]}"
OUTPUT=$(python .forgejo/scripts/message.py "$COMMIT_MESSAGE")
if [ $OUTPUT == "Usage: python message.py <commit_message>"]; then
echo "Called without commit message!"
exit 1
else if [ $OUTPUT == "None"]; then
echo "::set-output name=latest_tag::$(git describe --tags --abbrev=0)"
else
echo "No version bump found in commit message."
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$LATEST_TAG" ]; then
echo "::set-output name=latest_tag::$LATEST_TAG"
else
echo "No tags found."
fi
echo "::set-output name=version::$OUTPUT"
fi
- name: Create tag

View file

@ -0,0 +1,20 @@
import re
import sys
from typing import Optional
pattern = r"^(?:V|v)ersion\ bump(?:ed)?\ to\ ([0-9]+\.[0-9]+\.[0-9]+(?:-[a-zA-Z0-9]+)?).*"
def get_commit_message(string) -> Optional[str]:
m = re.match(pattern, string)
if m:
return m.group(1)
else:
return None
if __name__ == "__main__":
if len(sys.argv) >= 2:
commit_message = sys.argv[1]
result = get_commit_message(commit_message)
print(result)
else:
print("Usage: python message.py <commit_message>")