name: Release

on:
  pull_request:
    types:
      - closed
    branches:
      - main
    paths:
      - lib/http/2/version.rb

permissions:
  contents: read
  id-token: write

jobs:
  release:
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true
          ruby-version: 3.4

      - name: Publish to RubyGems
        uses: rubygems/release-gem@v1

      - name: Create GitHub release
        run: |
          tag_name="$(git describe --tags --abbrev=0)"
          gh release create "${tag_name}" --verify-tag --draft --generate-notes pkg/*.gem
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}