diff --git a/.github/workflows/danger-js.yml b/.github/workflows/danger-js.yml index a9ef5d65affe..85ff4069d3c6 100644 --- a/.github/workflows/danger-js.yml +++ b/.github/workflows/danger-js.yml @@ -22,11 +22,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version-file: ".nvmrc" - name: Danger JS - uses: danger/danger-js@11.2.6 + uses: docker://ghcr.io/danger/danger-js:13.0.5 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: diff --git a/scripts/dangerfile.ts b/scripts/dangerfile.ts index 2219e1b6c398..4fdadbba2438 100644 --- a/scripts/dangerfile.ts +++ b/scripts/dangerfile.ts @@ -1,16 +1,13 @@ -import { execSync } from 'child_process'; import { danger, fail } from 'danger'; +import pkg from '../code/package.json' assert { type: 'json' }; -execSync('npm install lodash'); +const intersection = (a: readonly string[], b: readonly string[]) => + a.filter((v) => b.includes(v)); -// eslint-disable-next-line depend/ban-dependencies -const flatten = require('lodash/flatten.js'); -// eslint-disable-next-line depend/ban-dependencies -const intersection = require('lodash/intersection.js'); -// eslint-disable-next-line depend/ban-dependencies -const isEmpty = require('lodash/isEmpty.js'); - -const pkg = require('../code/package.json'); +type PrLogConfig = { + skipLabels?: string[]; + validLabels?: [string, string][]; +}; const prLogConfig = pkg['pr-log']; const Versions = { @@ -24,20 +21,20 @@ const ciLabels = ['ci:normal', 'ci:merged', 'ci:daily', 'ci:docs']; const branchVersion = Versions.MINOR; const checkRequiredLabels = (labels: string[]) => { - const forbiddenLabels = flatten([ + const forbiddenLabels = [ 'ci: do not merge', 'in progress', - branchVersion !== Versions.MAJOR ? 'BREAKING CHANGE' : [], - branchVersion === Versions.PATCH ? 'feature request' : [], - ]); + ...(branchVersion !== Versions.MAJOR ? ['BREAKING CHANGE'] : []), + ...(branchVersion === Versions.PATCH ? ['feature request'] : []), + ]; - const requiredLabels = flatten([ - prLogConfig.skipLabels || [], - (prLogConfig.validLabels || []).map((keyVal: string) => keyVal[0]), - ]); + const requiredLabels = [ + ...(prLogConfig?.skipLabels ?? []), + ...(prLogConfig?.validLabels ?? []).map(([label]) => label), + ]; const blockingLabels = intersection(forbiddenLabels, labels); - if (!isEmpty(blockingLabels)) { + if (blockingLabels.length > 0) { fail( `PR is marked with ${blockingLabels.map((label: string) => `"${label}"`).join(', ')} label${ blockingLabels.length > 1 ? 's' : '' @@ -46,14 +43,14 @@ const checkRequiredLabels = (labels: string[]) => { } const foundRequiredLabels = intersection(requiredLabels, labels); - if (isEmpty(foundRequiredLabels)) { + if (foundRequiredLabels.length === 0) { fail(`PR is not labeled with one of: ${JSON.stringify(requiredLabels)}`); } else if (foundRequiredLabels.length > 1) { fail(`Please choose only one of these labels: ${JSON.stringify(foundRequiredLabels)}`); } const foundCILabels = intersection(ciLabels, labels); - if (isEmpty(foundCILabels)) { + if (foundCILabels.length === 0) { fail(`PR is not labeled with one of: ${JSON.stringify(ciLabels)}`); } else if (foundCILabels.length > 1) { fail(`Please choose only one of these labels: ${JSON.stringify(foundCILabels)}`);