Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CI set-up #26

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
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
99 changes: 99 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
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

code-coverage:
needs: test
# PRs from forks and Dependabot don't have access to the secrets
# needed to upload the coverage report to Code Climate. Run this
# job only if the trigger is a push or a PR from a maintainer.
#
# Test for success() in the condition to ensure the job runs only
# if the test job succeeded. Without it, this might run if test
# failed but the condition otherwise passed.
if: >
success() &&
github.actor != 'dependabot[bot]' &&
(github.event_name == 'push' ||
(github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork))
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: Generate and upload coverage report Code Climate
uses: paambaati/codeclimate-action@v5
with:
coverageCommand: bundle exec rspec
env:
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}

publish:
needs: test
# Publish the gem only on push of a correctly formatted tag that
# passed the tests. As only somebody who's trusted can push a tag,
# secrets are available.
#
# Test for success() in the condition to ensure the job runs only
# if the test job succeeded. Without it, this might 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}}"
24 changes: 0 additions & 24 deletions .github/workflows/publish.yml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/test.yml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/upload_coverage.yml

This file was deleted.

5 changes: 0 additions & 5 deletions lib/sinject/version.rb

This file was deleted.

12 changes: 10 additions & 2 deletions sinject.gemspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'sinject/version'

ci_version = ENV.fetch('CI_VERSION', '')
puts "CI version - #{ci_version}" unless ci_version.empty?

version = if ci_version =~ /\Av[0-9]+\.[0-9]+\.[0-9]+/
ci_version[1..-1]
else
'0.0.0'
end

Gem::Specification.new do |spec|
spec.name = 'sinject'
spec.version = Sinject::VERSION
spec.version = version
spec.authors = ['Sage One']
spec.email = ['vaughan.britton@sage.com']

Expand Down
Loading