DEV Community

Francesco Menghi
Francesco Menghi

Posted on • Updated on

First look at GitHub Actions

GitHub Actions is a Continuous Integration tool built into GitHub that provides an easy way to automate code testing and more.

The Setup

I setup a new action to run Jest tests on "ubuntu-latest" using both Node 14 and Node 16 every time a new Pull Request is created or a new commit is added.
I tested it with a new PR and this is what showed up at the bottom:

GitHub Actions

This worked very well so I decided to also add actions to run Prettier and ESLint automatically. I looked through how Telescope implements Continuous Integration and I created a similar setup for static-dodo.

Here is my full GitHub Actions code (created in .github/workflows/:

name: Node.js CI
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
jobs:
  prettier:
    name: Prettier Check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
      - name: Install dependencies and run prettier-check
        run: |
          npm install
          npm run prettier-check
  eslint:
    name: ESLint Check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
      - name: Install dependencies and run eslint
        run: |
          npm install
          npm run eslint
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [14.x, 16.x]
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
          cache: "npm"
      - run: npm ci
      - run: npm test
Enter fullscreen mode Exit fullscreen mode

The code is written in YAML and even though it is my first time using it, it is very descriptive and easy to read and learn.
Every time I add a new commit to the repo, the GitHub actions now starts automatically and adds a nice green check mark when all the automated tests passed successfully.

GitHub Actions Done

Thoughts

GitHub Actions is an amazing tool: it allows programmers to setup automation to always be sure that everything still works as more and more lines of codes are added to a project. I just scratched the surface of what is possible to accomplish with it but I will definitely continue using it going forward and hopefully lean some new tricks along the way!

Discussion (0)