Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/push_gem.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Publish gem to rubygems.org

on:
push:
tags:
- 'v*'

permissions:
contents: read

jobs:
push:
if: github.repository == 'ruby/json'
runs-on: ubuntu-latest

environment:
name: rubygems.org
url: https://rubygems.org/gems/json

permissions:
contents: write
id-token: write

strategy:
matrix:
ruby: ["ruby", "jruby"]

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

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Set up Ruby
uses: ruby/setup-ruby@eaecf785f6a34567a6d97f686bbb7bccc1ac1e5c # v1.237.0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need to use setup-ruby-pkg because JRuby needs ragel:

      - name: Set up Ruby
        uses: ruby/setup-ruby-pkgs@v1
        with:
          ruby-version: ${{ matrix.ruby }}
          apt-get: "${{ startsWith(matrix.ruby, 'jruby') && 'ragel' || '' }}"
          brew: "${{ startsWith(matrix.ruby, 'jruby') && 'ragel' || '' }}"

with:
ruby-version: ${{ matrix.ruby }}

# https://github.com/rubygems/rubygems/issues/5882
- name: Install dependencies and build for JRuby
run: |
sudo apt install default-jdk maven
gem update --system
gem install ruby-maven rake-compiler --no-document
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we need this? rake-compiler is already in the gemfile, and I don't remember ever needing to install ruby-maven.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also worried gem install over using the gemfile may break with some update.

rake compile
if: matrix.ruby == 'jruby'

- name: Install dependencies
run: bundle install --jobs 4 --retry 3
Comment on lines +50 to +51
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can combine this with the name: Set up Ruby step. e.g.

      - name: Set up Ruby ${{ matrix.ruby }}
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: ${{ matrix.ruby }}
          bundler-cache: true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For regular CI: #845

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that but jruby sometimes failed bundle install and build steps while ruby/setup-ruby.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's very annoying.... But I just pushed that change on regular CI and it seems to work?


- name: Publish to RubyGems
uses: rubygems/release-gem@a25424ba2ba8b387abc8ef40807c2c85b96cbe32 # v1.1.1

- 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 }}
if: matrix.ruby != 'jruby'
Loading