Create GitHub Tag from __version__ #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Create GitHub Tag from __version__ | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| create_tag: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set package name and read version | |
| id: version | |
| run: | | |
| INIT_PATH=$(find . -type f -name '__init__.py' | head -n1) | |
| echo "Found __init__.py at: $INIT_PATH" | |
| VERSION=$(grep -Po '__version__\s*=\s*"\K[0-9.]+' "$INIT_PATH") | |
| PACKAGE=$(basename "$(dirname "$INIT_PATH")") | |
| echo "PACKAGE=$PACKAGE" >> $GITHUB_ENV | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| echo "Detected package: $PACKAGE" | |
| echo "Detected version: $VERSION" | |
| - name: Create tag if not exists | |
| run: | | |
| git fetch --tags | |
| if git rev-parse "v$VERSION" >/dev/null 2>&1; then | |
| echo "Tag v$VERSION already exists" | |
| else | |
| git config user.name "github-actions" | |
| git config user.email "[email protected]" | |
| git tag "v$VERSION" | |
| git push origin "v$VERSION" | |
| fi |