diff --git a/.github/workflows/version_tag.yaml b/.github/workflows/version_tag.yaml new file mode 100644 index 00000000..4b21c203 --- /dev/null +++ b/.github/workflows/version_tag.yaml @@ -0,0 +1,46 @@ +name: Create version tag + +on: + push: + branches: + - main + paths: + - 'pyproject.toml' + +jobs: + create-version-tag: + name: Check version and create tag + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Extract version from pyproject.toml + id: get_version + run: | + VERSION=$(grep -m 1 '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Extracted version: $VERSION" + + - name: Check if tag exists + id: check_tag + run: | + if git rev-parse "${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then + echo "exists=true" >> $GITHUB_OUTPUT + echo "Tag '${{ steps.get_version.outputs.version }}' already exists" + else + echo "exists=false" >> $GITHUB_OUTPUT + echo "Tag '${{ steps.get_version.outputs.version }}' does not exist" + fi + + - name: Create and push tag + if: steps.check_tag.outputs.exists == 'false' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag -a "${{ steps.get_version.outputs.version }}" + git push origin "${{ steps.get_version.outputs.version }}"