Migrate from circleci

Hey everyone,

I currently have a CircleCi config file that builds my code and runs my tests for the client and the api. I would really like to move over to Github actions to do all this but I’ve been having issues migrating over.

Here is my CircleCi config, I would love to know how to achieve the same with Github Actions

working_dir: &working_dir ~/app

.build_template: &build_definition
steps:
- checkout
- run: curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- run: chmod +x ./cc-test-reporter
- run: ./cc-test-reporter before-build
- run: gem install bundler:2.1.4
- run: bundle install --jobs=4 --retry=4 --path vendor/bundle
- run: bundle exec rake rubocop
- run:
name: Run tests
command: |
bundle exec rspec -r rspec_junit_formatter --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/junit.xml
./cc-test-reporter after-build --exit-code $?
working_directory: *working_dir

version: 2.0

jobs:
build:
docker:
- image: ruby
steps:
- checkout
build_ruby2_7:
<<: *build_definition
docker:
- image: ruby:2.7
build_ruby2_6:
<<: *build_definition
docker:
- image: ruby:2.6
build_ruby2_5:
<<: *build_definition
docker:
- image: ruby:2.5
build_ruby2_4:
<<: *build_definition
docker:
- image: ruby:2.4
build_ruby2_3:
<<: *build_definition
docker:
- image: ruby:2.3

workflows:
version: 2
build_ruby_versions:
jobs:
- build
- build_ruby2_7
- build_ruby2_6
- build_ruby2_5
- build_ruby2_4
- build_ruby2_3

The YAML parser GitHub uses for Actions doesn’t support anchors. However to looks like you use them only to run what’s otherwise the same job using Docker images for different Ruby versions.

You can do that with a matrix job, where you have the list of images (or image tags) to use in a matrix variable, and then use that matrix variable to select the job container image.

The job definition might look something like this:

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        container:
          - 'ruby:2.3'
          - 'ruby:2.4'
          - 'ruby:2.5'
          - # ...
    runs-on: ubuntu-latest
    container: ${{ matrix.container }}
    name: ${{ matrix.container }}
    steps:
      - # ...