First impression with Github Actions
Continuous integration is a very important practice for software projects which consist of multiple contributors. Usually, just a code review is not enough to merge a pull request to the master branch since a very simple but a hidden mistake can occur errors during the actual build process. Therefore, what we could do is,
- Fetching the pull request and testing on our local machines before merging the pull request.
- Doing above 1) on a remote machine using a CI service. Eg:- Travis CI, Jenkins server.
But! how about having the CI part as a module of the source code hosting environment? Awesome right!. Github Actions offers a nice CI/CD solution inside the well known Github environment.
There was a task in Neutralinojs project in order to add CI support. Our project has three code bases (for Linux, Windows and MacOS) and each project has different build scripts.
I experimented Github Actions and added it to our project as per below.
How to implement custom CI actions
Step 1: There are many predefined CI workflows. Where as our project needs a custom workflow since there are multiple platforms and also some configurations.
Step 2: Write your workflow script. CI workflow may consist of more than one jobs. I have created two jobs for two different platforms (Linux and Windows).
name: C/C++ CIon: [push, pull_request]jobs:
build-linux:runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: configure
run: sudo apt-get install libgtk-3-dev -y && sudo apt-get update && sudo apt-get install libwebkit2gtk-4.0-37 libwebkit2gtk-4.0-dev
- name: build
run: bash build.shbuild-windows:runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: build
run: ./build
This workflow has two jobs. build-linux
will clone our project and run the required build script on Linux platform. build-windows
will do the same on Windows platform. Importantly, this workflow will be triggered when a new commit is pushed or when a new pull request is created.
Step 3: Eventually, test the workflow by triggering it (Eg:- by creating a pull request).
Conclusion
- Github Actions feature offers a nice CI/CD service which can be easily configured inside the Github environment itself.
- It supports Linux, Windows and MacOs platforms. Therefore, it is very useful for cross-platform projects.
- Github Actions can be used as a free feature for public repositories. Where as there is a pay-as-you-go pricing scheme for private repositories.
Happy Coding 😎