Skip to content

ci: add workflow_dispatch trigger to publish.yml #3

ci: add workflow_dispatch trigger to publish.yml

ci: add workflow_dispatch trigger to publish.yml #3

Workflow file for this run

name: Auto Release
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
environment: pypi
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version from pyproject.toml
id: version
run: |
VERSION=$(python3 -c "
import re
with open('pyproject.toml') as f:
match = re.search(r'version\s*=\s*\"(.+?)\"', f.read())
print(match.group(1))
")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Check if tag exists
id: check
run: |
if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Create tag and release
if: steps.check.outputs.exists == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git tag "v${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"
gh release create "v${{ steps.version.outputs.version }}" \
--title "v${{ steps.version.outputs.version }}" \
--generate-notes
- uses: actions/setup-python@v5
if: steps.check.outputs.exists == 'false'
with:
python-version: "3.13"
- name: Build and publish to PyPI
if: steps.check.outputs.exists == 'false'
run: |
pip install build
python -m build
- uses: pypa/gh-action-pypi-publish@release/v1
if: steps.check.outputs.exists == 'false'