gauth 0.10.2

HTTP Client for Google OAuth2
Documentation
name: Tag

on:
  push:
    branches: ["main"]
    paths:
      - "Cargo.toml"

jobs:
  tag:
    name: Create tag on version change
    runs-on: ubuntu-latest
    permissions:
      contents: write
      actions: write

    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - name: Read version from Cargo.toml
        id: version
        run: |
          version=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
          echo "value=$version" >> "$GITHUB_OUTPUT"

      - name: Check if tag exists
        id: check
        run: |
          # Resolve via the full ref so a branch or commit sharing the v* name
          # can't make us skip tagging.
          if git rev-parse --verify "refs/tags/v${{ steps.version.outputs.value }}" >/dev/null 2>&1; then
            echo "exists=true" >> "$GITHUB_OUTPUT"
          else
            echo "exists=false" >> "$GITHUB_OUTPUT"
          fi

      - name: Create and push tag
        if: steps.check.outputs.exists == 'false'
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git tag "v${{ steps.version.outputs.value }}"
          git push origin "v${{ steps.version.outputs.value }}"

      - name: Dispatch release
        if: steps.check.outputs.exists == 'false'
        run: |
          curl -sS --fail-with-body -X POST \
            -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
            -H "Accept: application/vnd.github+json" \
            -H "Content-Type: application/json" \
            "https://api.github.com/repos/${{ github.repository }}/actions/workflows/release.yml/dispatches" \
            -d '{"ref":"main","inputs":{"version":"${{ steps.version.outputs.value }}"}}'