Migrate gem tests from Travis CI to Github Actions with gemika

Updated . Posted . Visible to the public.

We currently test most of our gems on Travis CI, but want to migrate those tests to Github Actions. This is a step-by-step guide on how to do this.

Note that this guide requires the gem to use gemika Show archive.org snapshot .

  1. Go to a new "ci" branch:

    git checkout -b ci
    
  2. Update gemika to version >= 0.5.0 in all your Gemfiles.

  3. Have gemika generate a Github Actions workflow definition by running

    mkdir -p .github/workflows; bundle exec rake gemika:generate_github_actions_workflow > .github/workflows/test.yml
    
  4. Gemika tried to detect which of your Gemfiles needed which database, but is not currently very smart about it. If your test.yml does not set up the database correctly, please adjust it by comparing it with https://github.com/makandra/active_type/blob/master/.github/workflows/test.yml Show archive.org snapshot .

  5. If necessary (i.e. the tests use databases), add a spec/support/database.github.yml file with this content:

    mysql:
      database: test
      username: root
      password: password
      host: 127.0.0.1
      port: 3306
    
    postgresql:
      database: test
      host: localhost
      username: postgres
      password: postgres
      port: 5432
    
  6. Remove the .travis.yml file, and the spec/support/database.travis.yml.

  7. Push the branch, and make a PR against master. In the PR you can now see the CI run. Check if it passes.

  8. Most likely it will not. Fix the issues. Common issues are

    • You're using Ruby versions that are not supported on Github Actions.
      • The error messages will show you which versions are supported.
      • There is no support for any Ruby version < 2.2. Just drop those, we do not have to support them any longer.
      • Remember to remove unused Gemfiles.
      • Remember to update the .ruby-version file to a version that is actually in the matrix.
    • You might run into issues with the mysql2 gem, including issues bundling, and even segfaults.
  9. When tests pass, merge to master and delete the CI branch.

  10. Replace the Travis CI badge in the README with one like this:

    # MyGem  [![Tests](https://github.com/makandra/my-gem/workflows/Tests/badge.svg)](https://github.com/makandra/my-gem/actions)
    
  11. Uninstall the Travis webhook in the Github repo (go to Settings => Webhooks)

Tobias Kraze
Last edit
Judith Roth
License
Source code in this card is licensed under the MIT License.
Posted by Tobias Kraze to makandra dev (2020-10-09 14:53)