Skip to content

Update tag_from_version.yml #3

Update tag_from_version.yml

Update tag_from_version.yml #3

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

Check failure on line 26 in .github/workflows/tag_from_version.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/tag_from_version.yml

Invalid workflow file

You have an error in your yaml syntax on line 26
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