Github released the beta version of "actions" last year for creating a CI/CD pipeline for the projects. This feature enables us to create a pipeline easily with the web interface of Github. I want to run the tests for one of my public project in the Github before merging branches to the master. For testsozluk aka "test dictionary", which contains terms frequently used in the software industry with the meaning and usage of them in Turkish. For the project, tests are critical because JSON files in the Github project are the data source of the application so if any corruption in the data may break the android and the ios application. The tests in the project are written in Ruby by using Rspec to assert them so I used the Github actions to verify before merging code. In this post, I want to explain how this can be done.
Github's actions are very easy to apply. You can add it just go to the Actions tab in your project and then select one of the predefined options on the list. For Ruby projects, there is one for Ruby project and one for Ruby Gems project, or you can skip these predefined workflows and create your own workflow with create yourself option. Ruby Gems project is also including deployment part so you can easily push your gem to RubyGems with the credentials easily no need to push it in your local repository. Let's look at the Ruby projects, see the image below:
When you get the predefined Ruby workflow, you can add some tasks related to your pipeline and customize it. Basically, the workflow that I want to apply is to create a virtual Linux machine and install Ruby with the version of 2.6 and install requirements with the bundle. This workflow will run on push, but you can also set it on pull_request, or on schedule by defining a schedule with Cron syntax. It also has a webhook to trigger the workflow. I selected ubuntu-latest as a virtual machine but there are also other options as following:
runs-on:
ubuntu-latest
,ubuntu-18.04
, orubuntu-16.04
windows-latest
orwindows-2019
macos-latest
ormacos-10.15
For the project, tests are present in the `src/test` folder since I created the tests with RSpec it has its own structure, so I need to run tests in the test folder. Therefore running tests should have two steps; first I need to go to the test folder and then run the RSpec specs/test_spec.rb command to run them. The run command in the workflow supports multiple commands with adding pipe |. Let's look at the workflow as below: