name: Push gem to RubyGems

on:
  push:
    tags:
      - "v*"

permissions:
  contents: read

jobs:
  push:
    if: github.repository == 'laserlemon/simple_oauth'
    runs-on: ubuntu-latest
    environment:
      name: rubygems.org
      url: https://rubygems.org/gems/simple_oauth
    permissions:
      contents: write
      id-token: write
    steps:
      - uses: actions/checkout@v4
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: ruby
          bundler-cache: true
      - uses: rubygems/configure-rubygems-credentials@v1.0.0
      - name: Update RubyGems
        run: gem update --system
      - name: Build gem
        run: bundle exec rake build
      - name: Sign gem with Sigstore
        run: gem exec sigstore-cli sign pkg/*.gem --bundle pkg/simple_oauth.gem.sigstore.json
      - name: Push gem
        run: gem push pkg/*.gem --attestation pkg/simple_oauth.gem.sigstore.json
      - name: Wait for release
        run: gem exec rubygems-await pkg/*.gem
