Skip to content

Checking that #38 builds #4

Checking that #38 builds

Checking that #38 builds #4

Workflow file for this run

name: Build
run-name: >-
${{ github.event_name == 'pull_request' && format('Checking that #{0} builds', github.event.pull_request.number)
|| format('Building {0}', github.ref_name) }}
# Trunk-based: main is the only long-lived branch. Every pull request and every push to main runs the specs
# on each supported Ruby and builds the gem, but nothing is published here: RubyGems versions are permanent,
# so a release is a deliberate act - publishing a GitHub Release v{semver}, which runs publish.yml. The
# required status check is the `build` job, which passes only when every Ruby passed and the gem built.
on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
concurrency:
# A newer push to the same pull request cancels the older build; builds of main never cancel each other.
group: build-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.run_id }}
cancel-in-progress: true
jobs:
test:
name: test (Ruby ${{ matrix.ruby }})
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
ruby: ['3.2', '3.3', '3.4', '4.0']
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: ruby/setup-ruby@824c0e29fdfc7d689c191c27acc969d2d04b7dd8 # v1.331.0
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
# The examples tagged `live: true` convert real files on ConvertAPI and run only when the
# CONVERTAPI_SECRET secret (an API token) exists; pull requests from forks and Dependabot never get it,
# so for them only the offline examples run. CONVERTAPI_BASE_URI (a variable) can point them at
# another deployment, e.g. https://stag-v2.convertapi.com/.
- name: Specs
env:
CONVERT_API_SECRET: ${{ secrets.CONVERTAPI_SECRET }}
CONVERT_API_BASE_URI: ${{ vars.CONVERTAPI_BASE_URI }}
RUBYOPT: -W
run: bundle exec rake spec
build:
name: build
needs: test
# Runs even when a test job failed, so that the required check reports a failure instead of being
# skipped - a skipped required check counts as passed.
if: always()
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Check the specs
env:
RESULT: ${{ needs.test.result }}
run: |
if [ "$RESULT" != success ]; then
echo "::error::The specs did not pass on every Ruby ($RESULT)"
exit 1
fi
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- uses: ruby/setup-ruby@824c0e29fdfc7d689c191c27acc969d2d04b7dd8 # v1.331.0
with:
ruby-version: '3.4'
# ConvertApi::VERSION is the gem's version and goes into the User-Agent of every request; publish.yml
# refuses a tag that does not match it. It may run ahead of the latest release, never behind it.
- name: Check the version
id: version
run: |
set -euo pipefail
VERSION=$(ruby -Ilib -rconvert_api/version -e 'print ConvertApi::VERSION')
if ! [[ "$VERSION" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\.(alpha|beta|rc)\.(0|[1-9][0-9]*))?$ ]]; then
echo "::error file=lib/convert_api/version.rb::ConvertApi::VERSION '$VERSION' is not {major}.{minor}.{patch} or {major}.{minor}.{patch}.{alpha|beta|rc}.{n}"
exit 1
fi
# The highest release so far, pre-releases included (v3.1.0-rc.2 is gem version 3.1.0.rc.2). Gem::Version
# sorts a pre-release below its release, so this also refuses a pre-release of a released version.
LATEST=$(git tag --list 'v*' | ruby -e '
tags = $stdin.read.split.grep(/\Av\d+\.\d+\.\d+(-(alpha|beta|rc)\.\d+)?\z/)
print tags.map { |t| Gem::Version.new(t.delete_prefix("v").tr("-", ".")) }.max')
if [ -n "$LATEST" ] && ! ruby -e 'exit Gem::Version.new(ARGV[0]) >= Gem::Version.new(ARGV[1])' "$VERSION" "$LATEST"; then
echo "::error file=lib/convert_api/version.rb::ConvertApi::VERSION $VERSION is lower than the latest release $LATEST"
exit 1
fi
{
echo "version=$VERSION"
echo "latest=$LATEST"
} >> "$GITHUB_OUTPUT"
# The gem a release would publish, built and installed outside the checkout, so a change can be tried
# out from the run's artifact before it is released.
- name: Build the gem
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
mkdir -p dist
gem build convert_api.gemspec --output "dist/convert_api-$VERSION.gem"
GEM_HOME="$RUNNER_TEMP/gems" gem install --local --no-document "dist/convert_api-$VERSION.gem"
cd "$RUNNER_TEMP"
GEM_HOME="$RUNNER_TEMP/gems" GEM_PATH="$RUNNER_TEMP/gems" ruby -W -e '
require "convert_api"
abort "loaded #{ConvertApi::VERSION}, expected #{ARGV[0]}" unless ConvertApi::VERSION == ARGV[0]
abort "loaded from #{$LOADED_FEATURES.grep(/convert_api\.rb\z/)}" unless $LOADED_FEATURES.grep(/convert_api\.rb\z/).all? { |f| f.start_with?(ENV["GEM_HOME"]) }
puts ConvertApi::Client::USER_AGENT' "$VERSION"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: convert_api-${{ steps.version.outputs.version }}-run${{ github.run_number }}
path: dist/
retention-days: 14
if-no-files-found: error
- name: Summary
env:
VERSION: ${{ steps.version.outputs.version }}
LATEST: ${{ steps.version.outputs.latest }}
run: |
{
echo "| | |"
echo "|---|---|"
echo "| \`ConvertApi::VERSION\` | \`$VERSION\` (latest release: \`$LATEST\`) |"
echo "| Gem | \`convert_api-$VERSION.gem\` (artifact only, not published) |"
echo "| Ruby | 3.2, 3.3, 3.4, 4.0 |"
} >> "$GITHUB_STEP_SUMMARY"