Skip to content

Commit

Permalink
Extract ruby-gem composite action (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjunior authored May 21, 2024
1 parent 0f3613f commit 536bc1d
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 15 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/build-ruby-gem-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: build-ruby-gem

on:
push:

jobs:
build:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}
strategy:
fail-fast: true
matrix:
ruby:
- 3.0
- 3.1
- 3.2
- 3.3
steps:
- uses: actions/checkout@v3
- name: 'Test ruby gem action'
uses: ./build-ruby-gem
with:
workdir: build-ruby-gem/test
ruby: ${{ matrix.ruby }}
22 changes: 7 additions & 15 deletions .github/workflows/ruby-gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,17 @@ jobs:
gemfile: ${{ fromJSON(inputs.gemfiles) }}
bundler: ${{ fromJSON(inputs.bundler) }}
exclude: ${{ fromJSON(inputs.exclude)}}
env:
BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
BUNDLER_VERSION: "${{ matrix.bundler }}"
RAILS_ENV: test
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
bundler: ${{ matrix.bundler }}
ruby-version: ${{ matrix.ruby }}
working-directory: ${{ inputs.workdir }}
- name: Before build
if: ${{ inputs.before_build != '' }}
run: "${{ inputs.before_build }}"
- name: Run the build script
working-directory: ${{ inputs.workdir }}
run: bundle exec rake
- uses: powerhome/github-actions-workflows/build-ruby-gem@main
with:
workdir: ${{ inputs.workdir }}
ruby: ${{ matrix.ruby }}
gemfile: ${{ matrix.gemfile }}
bundler: ${{ matrix.bundler }}

license-compliance:
uses: ./.github/workflows/license-compliance.yml
Expand All @@ -72,7 +64,7 @@ jobs:
if: ${{ contains(github.ref, 'refs/tags/v') && contains(github.ref, inputs.package) }}
steps:
- uses: actions/checkout@v3
- uses: powerhome/publish-rubygems-action@git-safe-directory
- uses: cadwallion/publish-rubygems-action@master
env:
RELEASE_COMMAND: rake build release:guard_clean release:rubygem_push
RUBYGEMS_API_KEY: ${{ secrets.rubygems_api_key }}
Expand Down
40 changes: 40 additions & 0 deletions build-ruby-gem/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "Ruby Gem"
description: "Power Home ruby gem build"
inputs:
workdir:
description: 'The working directory during this build'
required: false
ruby:
description: 'The ruby version to use on this build'
default: '3.3'
required: false
gemfile:
description: 'The path to a Gemfile, relative to workdir'
default: 'Gemfile'
required: false
bundler:
description: 'Bundler major version'
default: '2'
required: false
runs:
using: 'composite'
steps:
- name: 'Set up Ruby'
uses: ruby/setup-ruby@v1
env:
BUNDLE_GEMFILE: '${{ inputs.gemfile }}'
BUNDLER_VERSION: '${{ inputs.bundler }}'
RAILS_ENV: 'test'
with:
bundler-cache: true
bundler: '${{ inputs.bundler }}'
ruby-version: '${{ inputs.ruby }}'
working-directory: '${{ inputs.workdir }}'
- name: 'Run the build script'
env:
BUNDLE_GEMFILE: '${{ inputs.gemfile }}'
BUNDLER_VERSION: '${{ inputs.bundler }}'
RAILS_ENV: 'test'
working-directory: '${{ inputs.workdir }}'
shell: 'bash'
run: 'bundle exec rake'
3 changes: 3 additions & 0 deletions build-ruby-gem/test/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gem "rake", ">= 13.0"
8 changes: 8 additions & 0 deletions build-ruby-gem/test/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env rake

# frozen_string_literal: true

task :default do
puts "Default task invoked successfully"
puts "Ruby: #{RUBY_VERSION}"
end

0 comments on commit 536bc1d

Please sign in to comment.