name: Publish gem to rubygems.org

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: read

jobs:
  push:
    if: github.repository == 'madeintandem/jsonb_accessor'
    runs-on: ubuntu-24.04

    permissions:
      contents: write
      id-token: write

    strategy:
      matrix:
        ruby: ["ruby-3.4", "jruby-9.4"]

    steps:
      - uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0
        with:
          egress-policy: audit

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

      - if: matrix.ruby == 'jruby-9.4' # cribbed from https://github.com/ruby/psych/blob/v5.2.4/.github/workflows/push_gem.yml
        run: |
          sudo apt install default-jdk maven
          gem update --system
          gem install ruby-maven rake-compiler --no-document
          rake compile

      - uses: ruby/setup-ruby@319994f95fa847cf3fb3cd3dbe89f6dcde9f178f # v1.295.0
        with:
          bundler-cache: true
          ruby-version: ${{ matrix.ruby }}

      - uses: rubygems/release-gem@e9a6361a0b14562539327c2a02373edc56dd3169 # v1.1.4
