Skip to content

Commit 1ce6627

Browse files
akurtakovCopilot
andcommitted
Comment on PR and fail run when NPM license review is required
Previously the license check only printed a message and exited successfully when unvetted NPM dependencies were found. Now the workflow parses the dash-licenses review summary, posts the list of dependencies requiring review as a PR comment, and marks the run as failed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 55ecce6 commit 1ce6627

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

.github/workflows/licensecheck.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ jobs:
4242
if: github.event_name != 'issue_comment' || ( github.event.issue.pull_request != '' && (github.event.comment.body == '/request-license-review') )
4343
# Run on all non-comment events specified by the calling workflow and for comments on PRs that have a corresponding body.
4444
runs-on: ubuntu-latest
45+
permissions:
46+
contents: read
47+
pull-requests: write
4548
steps:
4649
- uses: actions/checkout@v7
4750
if: github.event_name == 'push' || github.event_name == 'pull_request'
@@ -94,6 +97,7 @@ jobs:
9497
echo "request-review=1" >> $GITHUB_ENV
9598
# Always request a review so unvetted licenses are submitted automatically.
9699
- name: NPM Deps License check
100+
id: license-check
97101
shell: bash {0}
98102
run: |
99103
set +x
@@ -142,6 +146,58 @@ jobs:
142146
fi
143147
echo ""
144148
149+
- name: Report required license reviews and fail
150+
if: always() && steps.license-check.outputs.build-succeeded == '0'
151+
uses: actions/github-script@v9
152+
with:
153+
script: |
154+
const fs = require('fs');
155+
const summaryPath = 'target/dash/npm-review-summary';
156+
let summary = '';
157+
try {
158+
summary = fs.readFileSync(summaryPath, 'utf8');
159+
} catch (err) {
160+
core.setFailed(`Could not read NPM review summary at '${summaryPath}': ${err}`);
161+
return;
162+
}
163+
// The summary is a CSV produced by dash-licenses: "id, license, status, source".
164+
// Dependencies whose status is "restricted" still require a license review.
165+
const needsReview = summary
166+
.split('\n')
167+
.map(line => line.trim())
168+
.filter(line => line.length > 0)
169+
.map(line => line.split(',').map(field => field.trim()))
170+
.filter(fields => fields[2] === 'restricted');
171+
if (needsReview.length === 0) {
172+
core.setFailed('The NPM license check failed but no restricted dependencies were found in the review summary.');
173+
return;
174+
}
175+
const list = needsReview
176+
.map(fields => `- \`${fields[0]}\` (license: ${fields[1] || 'unknown'}, source: ${fields[3] || 'none'})`)
177+
.join('\n');
178+
const body = [
179+
'## :warning: NPM dependency license review required',
180+
'',
181+
'The following NPM dependencies have licenses that are not yet vetted and require a review before they can be used:',
182+
'',
183+
list,
184+
'',
185+
'A review request has been submitted automatically to the Eclipse IP team. These dependencies must be approved before this change can be merged.',
186+
].join('\n');
187+
core.summary.addRaw(body).write();
188+
const prNumber = context.issue && context.issue.number;
189+
if (prNumber) {
190+
await github.rest.issues.createComment({
191+
owner: context.repo.owner,
192+
repo: context.repo.repo,
193+
issue_number: prNumber,
194+
body,
195+
});
196+
} else {
197+
core.info('No pull request context available; skipping PR comment.');
198+
}
199+
core.setFailed('Some NPM dependencies require a license review.');
200+
145201
- uses: actions/upload-artifact@v7
146202
if: always() && env.request-review
147203
with:

0 commit comments

Comments
 (0)