GitHub Actions is aContinuous Integration tool built into GitHub that provides an easy way to automate code testing and more.
The Setup
I setup a new action to runJest tests on"ubuntu-latest" using bothNode 14 andNode 16 every time a new Pull Request is created or a new commit is added.
I tested it with a newPR and this is what showed up at the bottom:
This worked very well so I decided to also add actions to runPrettier andESLint automatically. I looked through howTelescope implements Continuous Integration and I created a similar setup forstatic-dodo.
Here is my full GitHub Actions code (created in.github/workflows/
:
name:Node.js CIon:push:branches:[main]pull_request:branches:[main]jobs:prettier:name:Prettier Checkruns-on:ubuntu-lateststeps:-uses:actions/checkout@v2-uses:actions/setup-node@v2-name:Install dependencies and run prettier-checkrun:|npm installnpm run prettier-checkeslint:name:ESLint Checkruns-on:ubuntu-lateststeps:-uses:actions/checkout@v2-uses:actions/setup-node@v2-name:Install dependencies and run eslintrun:|npm installnpm run eslintbuild:runs-on:ubuntu-lateststrategy:matrix:node-version:[14.x,16.x]steps:-uses:actions/checkout@v2-name:Use Node.js ${{ matrix.node-version }}uses:actions/setup-node@v2with:node-version:${{ matrix.node-version }}cache:"npm"-run:npm ci-run:npm test
The code is written inYAML 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.
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!
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse