|
42 | 42 | if: github.event_name != 'issue_comment' || ( github.event.issue.pull_request != '' && (github.event.comment.body == '/request-license-review') ) |
43 | 43 | # Run on all non-comment events specified by the calling workflow and for comments on PRs that have a corresponding body. |
44 | 44 | runs-on: ubuntu-latest |
| 45 | + permissions: |
| 46 | + contents: read |
| 47 | + pull-requests: write |
45 | 48 | steps: |
46 | 49 | - uses: actions/checkout@v7 |
47 | 50 | if: github.event_name == 'push' || github.event_name == 'pull_request' |
|
94 | 97 | echo "request-review=1" >> $GITHUB_ENV |
95 | 98 | # Always request a review so unvetted licenses are submitted automatically. |
96 | 99 | - name: NPM Deps License check |
| 100 | + id: license-check |
97 | 101 | shell: bash {0} |
98 | 102 | run: | |
99 | 103 | set +x |
@@ -142,6 +146,58 @@ jobs: |
142 | 146 | fi |
143 | 147 | echo "" |
144 | 148 |
|
| 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 | +
|
145 | 201 | - uses: actions/upload-artifact@v7 |
146 | 202 | if: always() && env.request-review |
147 | 203 | with: |
|
0 commit comments