DEV Community

Tuan Thanh Tan
Tuan Thanh Tan

Posted on

Adding Github Actions CI Workflow


Hello everyone, my name is Dustin, today I'd like to talk about my experience working with Github Actions and some testings in Javascript.

At a glance

Github Actions was easy to set up as it's written beforehand, I just needed to remove 1 line of building step because I don't need it yet. But making my code to run and pass all 3 node versions was quite difficult. I ran into trouble a lot of times.


First, I decided to migrate from Commander to Yargs in order to make the code clearer. And then I added some more tests for the e2e test to make sure that help option and version option are working as I expected. As I was running the tests, I found out there's some errors happening and needed to be fixed as soon as possible. So I created a separate branch to fix it. The problem involved resolve variable in promise because I accidentally added curly braces around them. As I progressed, I decided to clean up my code a little bit more so I moved from using sync functions to async functions in the produceFolder class.

After that, I pushed the code to my repo, and it seemed like Github wasn't very happy with my package-lock.json and __snapshots__ for some reason. So I had to npm install and delete __snapshots__ and run the test again.

What I have for my github actions is

name: Node.js CI

    branches: [ main ]
    branches: [ main ]


    runs-on: ubuntu-latest

        node-version: [12.x, 14.x, 16.x]
        # See supported Node.js release schedule at

    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
    - run: npm ci
    - run: npm test
Enter fullscreen mode Exit fullscreen mode

Unfortunately, it was only successful on the first 2 node versions, not the 16 one due to rm and mkdir. There was also a problem with rmdir because in Node 16, If I remember correctly, it won't be supported anymore so I had to only use mkdir to create a folder. I also had to add {recursive: true} just in case the folder already exists.

Wrap up

After a day struggling, I've successfully passed all 3 tests from Github actions and I've learnt a lot from it, especially using Git.

My testing still needs to be improved as it just covers some basics, not every edge case because testing takes a lot of time and thinking. More testing will be added later.

Discussion (0)