Skip to content

Commit

Permalink
test npx and update dangerfile to javascript syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
pengyin-shan committed Jan 16, 2025
1 parent 54af781 commit 3c3a2e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/danger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
29 changes: 10 additions & 19 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -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.')
}

Expand All @@ -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
Expand Down

0 comments on commit 3c3a2e0

Please sign in to comment.