GitHub recently added CI/CD to their pipeline service, Actions. I was very excited to be invited into the Actions beta and have been using it in a couple private projects, and I was added to the CI/CD beta today. The first thing I wanted to do was move Killed by Google off of Travis CI and into GitHub Actions.

Features • GitHub Actions
Easily build, package, release, update, and deploy your project in any language—on GitHub or any external system—without having to run code yourself.

GitHub makes it easy to get started with Node environments by following the prompts in the Actions area, I was given their starter-node workflow example. This example workflow is perfect for projects using NPM, but I primarily use Yarn as my package manager.

name: Node CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [8.x, 10.x, 12.x]

    steps:
    - uses: actions/checkout@v1
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - name: npm install, build, and test
      run: |
        npm install
        npm run build --if-present
        npm test

How do I run yarn on GitHub Actions CI/CD?

Start with the starter workflow above provided by GitHub. First, modify the workflow to install Yarn before it runs the build and test process.

...
steps:
- uses: actions/checkout@v1
- name: Uses Node.js ${{ matrix.node-version }}
  uses: actions/setup-node@v1
  with:
  	node-version: ${{ matrix.node-version }}
- run: npm install -g yarn # Extra Step
...

Next, modify the build and test process to be handled by yarn instead of npm.

Default using npm

...
- name: npm install, build, and test
  run: |
    npm install
    npm run build --if-present
    npm test

Changed to use yarn

...
- name: yarn install, build, and test
  run: |
    yarn install
    yarn run build
    yarn test

And that's it! It's that simple to get GitHub Actions with CI/CD using yarn to build and test your project. There are a couple other changes that I made to Killed by Google's workflow to make it more efficient.


I don't need to test across multiple versions of Node, so I modified the CI to run only on one version, 10.x. I also want CI to run on every push and pull request made to my repo, this makes it easy to avoid errors in our manually managed JSON file. Take a look at the commented changes below from nodejs.yml in Killed by Google's GitHub repo.

# .github/workflows/nodejs.yml
name: Node CI

on: [push, pull_request] # Run on Push and Pull Requests

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x] # Only run the 10.x build

    steps:
    - uses: actions/checkout@v1
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm install -g yarn
    - name: yarn install, build, and test
      run: |
        yarn
        yarn build
        yarn test