53

First impression with Github Actions

 4 years ago
source link: https://medium.com/@shalithasuranga/first-impression-with-github-actions-70a3416346cd
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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,

  1. Fetching the pull request and testing on our local machines before merging the pull request.
  2. 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.

JvAJreq.png!web

Go to Actions tab of the repository to create a new workflow.

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).

Q7zM7vB.png!web

A green tick will be appeared when all jobs were completed successfully.

a6NVvu3.png!web

Log messages/output for each job in our workflow.

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 :sunglasses:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK