Exploring Github Actions && Local Validation
• Mark Eschbach
Recently I released erraform-provider-twsaws which used Github Actions as a release platform based on the Hashicorp’s recommended provider release methods. Well, today I was asked to build out continuous delivery and continuous integration for an internal TypeScript project running on Node.
Just getting my toes wet in the pool, my current understanding of Github Action’s is:
- It’s a workflow engine specialized in code management. There can be several input triggers.
- Steps appear to be something similar to Docker containers which work against a shared volume.
There has been decent thought given to how these would work and overall pretty straight forward. Workflows are placed
into .github/workflows
defining the actions.
Testing a Github Actions
Ideally one would be able to test much fo the workflows before pushing up. The Github Actions community does not disappoint: Act does exactly that. (Insert mutterings about need HomeBrew for a Go Program)
Behind the scenes this drives Docker to run the Actions in your local Docker instance. My first shot of a pipeline looked like the following:
name: Unit Tests Pull Requests
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js $
uses: actions/setup-node@v2
with:
node-version: $
- run: yarn install --frozen-lockfile
- run: yarn tsc index.ts
This failed to run with act pull_request
due to yarn
not being found. Wrong container? From the debug output the
container downloads and installs the most recent version of Node 16 into a step. Checking various versions this seems
to not be the case. Switching to actions/setup-node@v1
also did not resolve the issue. According this blog
yarn
needs to be installed in a separate step.
This definitely was the missing step. A bit unfortunate this is installed very time. I think my understanding of the
steps might be a little flawed: actions/setup-node@v2
appears to actually install Node into the sandbox environment
instead of providing extensions to it. Anyway, here is the Github Actions file I found myself with:
name: Unit Tests Pull Requests
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js $
uses: actions/setup-node@v2
with:
node-version: $
- run: npm install -g
- run: yarn install --frozen-lockfile
- run: yarn tsc index.ts
This can be checked against a TypeScript project with the following: act pull_request
.