dsn 1.2.1

DSN (Data Source Name) parser
Documentation
---
name: Release

on:
  push:
    tags:
      - '[0-9]+.[0-9]+.[0-9]+'
  workflow_dispatch:

permissions:
  contents: write

jobs:
  test:
    uses: ./.github/workflows/test.yml

  create-release:
    name: Create GitHub Release
    runs-on: ubuntu-latest
    needs:
      - test
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Get version from tag
        id: version
        run: |
          TAG=${GITHUB_REF#refs/tags/}
          # Remove 'v' prefix if present
          VERSION=${TAG#v}
          echo "version=$VERSION" >> $GITHUB_OUTPUT
          echo "tag=$TAG" >> $GITHUB_OUTPUT
          echo "Version: $VERSION"
          echo "Tag: $TAG"

      - name: Extract changelog for version
        id: changelog
        run: |
          # Extract the changelog section for this version
          VERSION=${{ steps.version.outputs.version }}
          awk "/## \[$VERSION\]/,/## \[/" CHANGELOG.md | sed '1d;$d' > release_notes.md
          cat release_notes.md

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          name: ${{ steps.version.outputs.tag }}
          body_path: release_notes.md
          draft: false
          prerelease: false

  publish-crates:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    needs:
      - test
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - uses: Swatinem/rust-cache@v2

      - name: Publish to crates.io
        run: cargo publish --token ${CRATES_TOKEN}
        env:
          CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}