name: Publish gem to rubygems.org

on:
  workflow_dispatch:

jobs:
  release:
    if: github.repository == 'rspec-parameterized/rspec-parameterized-table_syntax'
    runs-on: ubuntu-latest

    environment:
      name: rubygems.org
      url: https://rubygems.org/gems/rspec-parameterized-table_syntax

    permissions:
      contents: write
      id-token: write

    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
        with:
          egress-policy: audit

      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Set up Ruby
        uses: ruby/setup-ruby@8aeb6ff8030dd539317f8e1769a044873b56ea71 # v1.268.0
        with:
          bundler-cache: true
          ruby-version: ruby

      - name: Publish to RubyGems
        uses: rubygems/release-gem@1c162a739e8b4cb21a676e97b087e8268d8fc40b # v1.1.2

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