Skip to content

Update CI set-up

Update CI set-up #9

Workflow file for this run

name: CI
on:
push:
branches:
- 'master'
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
pull_request:
jobs:
test:
strategy:
fail-fast: false
matrix:
# All the (nominally) supported Ruby versions
ruby: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run tests
run: bundle exec rspec
# PRs from forks and Dependabot don't have access to secrets,
# which are needed to upload the code coverage report to Code
# Climate. Save the report as an artefact for a later,
# privileged workflow to upload.
- name: Save coverage report artefact
# No sense uploading coverage for each Ruby version tested
if: matrix.ruby == '3.3'
uses: actions/upload-artifact@v4
with:
name: coverage-json
path: coverage/coverage.json
retention-days: 1
publish:
needs: test
# Publish the gem only on push of a correctly formatted tag that
# passed the tests. As a push is done by somebody trusted, secrets
# are available.
#
# success() in the condition ensures the job runs only if the test
# job succeeded. Without it, this job could run if test failed but
# the condition otherwise passed.
if: success() && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: true
- name: Build gem and publish to RubyGems
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
rm -f sinject-*.gem
gem build sinject.gemspec
gem push sinject-*.gem
env:
# CI_VERSION is read by gemspec to set the gem's version to
# that specified by the tag.
CI_VERSION: ${{ github.ref_name }}
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"