using python for some conditional stuff instead of bash
This commit is contained in:
parent
7da86574e6
commit
a902fb01eb
2 changed files with 27 additions and 11 deletions
|
@ -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
|
||||
|
|
20
.forgejo/workflows/scripts/message.py
Normal file
20
.forgejo/workflows/scripts/message.py
Normal 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>")
|
Reference in a new issue