Update tag_from_version.yml #3
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: Detect version using AST | ||
| id: get_version | ||
| run: | | ||
| echo "π Searching for __init__.py..." | ||
| INIT_PATH=$(find . -type f -name '__init__.py' | head -n1) | ||
| echo "Found: $INIT_PATH" | ||
| python3 <<EOF > version.txt | ||
| import ast | ||
| with open("$INIT_PATH") as f: | ||
| tree = ast.parse(f.read()) | ||
| for node in ast.walk(tree): | ||
| if isinstance(node, ast.Assign): | ||
| if getattr(node.targets[0], "id", None) == "__version__": | ||
| print(node.value.s) | ||
| break | ||
| EOF | ||
| VERSION=$(cat version.txt) | ||
| PACKAGE=$(basename $(dirname "$INIT_PATH")) | ||
| if [ -z "$VERSION" ]; then | ||
| echo "β __version__ not found in $INIT_PATH" | ||
| exit 1 | ||
| fi | ||
| echo "π¦ PACKAGE: $PACKAGE" | ||
| echo "π VERSION: $VERSION" | ||
| echo "PACKAGE=$PACKAGE" >> $GITHUB_ENV | ||
| echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
| - 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. Skipping." | ||
| else | ||
| echo "π· Creating new tag v$VERSION" | ||
| git config user.name "github-actions" | ||
| git config user.email "[email protected]" | ||
| git tag "v$VERSION" | ||
| git push origin "v$VERSION" | ||
| fi | ||