From 3c3a2e0e66a3bf2f55ff97f766836be76040ef84 Mon Sep 17 00:00:00 2001 From: "Wendy(Pengyin) Shan" Date: Thu, 16 Jan 2025 17:29:49 -0500 Subject: [PATCH] test npx and update dangerfile to javascript syntax --- .github/workflows/danger.yml | 14 ++++++++++---- dangerfile.js | 29 ++++++++++------------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml index b36e5b0..0959882 100644 --- a/.github/workflows/danger.yml +++ b/.github/workflows/danger.yml @@ -9,14 +9,20 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Use Node.js 20.x - uses: actions/setup-node@master + uses: actions/setup-node@v3 with: node-version: 20.x + cache: 'npm' + - name: Install Dependencies run: npm ci - - name: Danger - run: npm danger ci + + - name: Run Danger + run: npx danger ci env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/dangerfile.js b/dangerfile.js index 2e20abb..207ade4 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -1,16 +1,16 @@ -const hasChangelog = danger.git.modified_files.includes("CHANGELOG.md"); -const isTrivial = (danger.github.pr.body + danger.github.pr.title).includes( - "#trivial" -); -const has_app_changes = !git.modified_files.grep(/src/).empty +import { danger, warn, fail } from 'danger' + +const hasAppChanges = danger.git.modified_files.some(file => file.includes('src')) +const hasChangelog = danger.git.modified_files.includes("CHANGELOG.md") +const isDeclaredTrivial = (danger.github.pr.title + danger.github.pr.body).includes('#trivial') || !hasAppChanges //Make sure we add changelog -if (!hasChangelog && !isTrivial) { +if (!hasChangelog && !isDeclaredTrivial) { warn("Please add a changelog entry for your changes."); } //Mainly to encourage writing up some reasoning about the PR, rather than just leaving a title -if (github.pr_body.length < 3) { +if (danger.github.pr.body.length < 3) { warn('Please add a detailed summary in the description.') } @@ -20,22 +20,13 @@ if (github.pr_body.length < 3) { // } //Make it more obvious that a PR is a work in progress and shouldn't be merged yet -if (github.pr_title.includes('[WIP]')) { +if (danger.github.pr.title.includes('[WIP]')) { warn('PR is classed as Work in Progress') } -//Let people say that this isn't worth a CHANGELOG entry in the PR if they choose -declared_trivial = (github.pr_title + github.pr_body).includes('#trivial') || !has_app_changes -if (!git.modified_files.include?('CHANGELOG.md') && !declared_trivial){ - raise( - 'Please include a CHANGELOG entry. You can find it at [CHANGELOG.md](https://github.com/policy-design-lab/pdl-frontend/blob/develop/CHANGELOG.md).', - sticky: false - ) -} - //Detect .eslintrc changes and set warnings -if (git.modified_files.include?('.eslintrc')) { - warn('Changes were made to .eslintrc. Please ensure that the you have notified team to change the existing ESLine rule.') +if (danger.git.modified_files.includes('.eslintrc')) { + warn('Changes were made to .eslintrc. Please ensure that you have notified the team to change the existing ESLint rule.') } // In the future: make sure non-trivial amounts of code changes come with corresponding tests