Skip to content

Merge pull request #13 from hmasdev/fix-workflow #1

Merge pull request #13 from hmasdev/fix-workflow

Merge pull request #13 from hmasdev/fix-workflow #1

name: Check and Fix Version on Push Tags
on:
push:
tags:
- "*.*.*"
jobs:
validate-tag:
uses: ./.github/workflows/validate-version-workflow-call.yaml
with:
git-ref: ${{ github.ref }}
update-version:
needs: [validate-tag]
if: ${{ failure() }}
runs-on: windows-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Update Tags
shell: bash
run: |
# Get the latest tag
export latest_tag=$(git describe --tags --abbrev=0)
export branch_name="bot/update-version-to-$latest_tag"
git checkout -b $branch_name
# Update the version
line_before_chg=$(grep -P "__version__ *= *['|\"]v?\d+\.\d+\.\d+.*['|\"]" simple_typing_application/__init__.py)
line_after_chg="__version__ = '$latest_tag'"
echo "line_before_chg: $line_before_chg"
echo "line_after_chg: $line_after_chg"
sed -i -e "s/$line_before_chg/$line_after_chg/g" simple_typing_application/__init__.py
# Commit and push the changes
if [ $(grep "$line_after_chg" simple_typing_application/__init__.py | wc -l) -eq 1 ]; then
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add simple_typing_application/__init__.py
git commit -m "Update version to $latest_tag"
git push -u origin $branch_name
git tag -d $latest_tag
git push --delete origin $latest_tag
gh pr create \
--title "Update version to $latest_tag" \
--body "Update version to $latest_tag" \
--base main \
--head $branch_name \
--assignee hmasdev \
--reviewer hmasdev \
--label "bot"
else
echo "Failed to update the version"
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}