Breno Calazans

How to setup Danger JS with GitHub Actions

2020-03-221 Min Read — In dangerjs, ci, github

Make sure you add danger as a devDependency:

1yarn add danger -D

A dangerfile.js in the root directory. Example:

1// Add a CHANGELOG entry for app changes
2const hasChangelog = danger.git.modified_files.includes("changelog.md");
3const isTrivial = (danger.github.pr.body + danger.github.pr.title).includes(
4 "#trivial"
5);
6
7if (!hasChangelog && !isTrivial) {
8 warn("Please add a changelog entry for your changes.");
9}

Lastly, create a workflow file at .github/workflow/ and give it any name, example: cy.yml:

1name: CI Pull Requests
2
3on:
4 pull_request:
5 branches: [master]
6
7jobs:
8 build:
9 runs-on: ubuntu-latest
10 steps:
11 - uses: actions/checkout@master
12 - name: Use Node.js 12.x
13 uses: actions/setup-node@master
14 with:
15 node-version: 12.x
16
17 - name: yarn install
18 run: yarn install
19
20 - name: Danger
21 run: yarn danger ci
22 env:
23 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Discuss on TwitterEdit post on GitHub

EOF