Skip to content

Instantly share code, notes, and snippets.

@ybiquitous
Last active June 2, 2022 13:11
Show Gist options
  • Save ybiquitous/54586327550d57a4ad435da635d080a8 to your computer and use it in GitHub Desktop.
Save ybiquitous/54586327550d57a4ad435da635d080a8 to your computer and use it in GitHub Desktop.
Dynamic Ruby versions matrix on GitHub Actions
name: Test
on: push
jobs:
ruby-versions:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.versions.outputs.value }}
steps:
- id: versions
name: Fetch Ruby versions
run: |
versions="$(curl -s 'https://cache.ruby-lang.org/pub/misc/ci_versions/cruby.json' | jq -c)"
echo "Fetched Ruby versions: ${versions}"
echo "::set-output name=value::${versions}"
test:
name: Test on Ruby ${{ matrix.ruby }}
needs: ruby-versions
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: bundle exec rake
@ybiquitous
Copy link
Author

ybiquitous commented Jun 1, 2022

See https://cache.ruby-lang.org/pub/misc/ci_versions/ for other versions (e.g. jruby)

@ybiquitous
Copy link
Author

An example to add outdated versions to the matrix:

versions=$(curl -s 'https://cache.ruby-lang.org/pub/misc/ci_versions/all.json' | jq -c '. |= . + ["2.6", "2.5", "2.4"]')

See also:
https://github.com/ruby/net-pop/blob/1f06e08cde37e1c20153ca91da2890adeec0e2b3/.github/workflows/test.yml#L13

@ybiquitous
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment