Skip to content

Commit e404798

Browse files
felickzCopilot
andcommitted
Merge upstream actions/dependency-review-action main
Syncs fork with upstream, resolving conflicts in package.json (keeping semver + upgrading spdx-expression-parse to ^4.0.0), regenerating package-lock.json and dist/ folder. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2 parents a6c34d8 + dea54b4 commit e404798

File tree

11 files changed

+1376
-233
lines changed

11 files changed

+1376
-233
lines changed

CONTRIBUTING.md

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ Before you begin, you need to have [Node.js](https://nodejs.org/en/) installed,
5050

5151
#### Manually testing for vulnerabilities
5252

53-
We have a script to scan a given PR for vulnerabilities, this will
54-
help you test your local changes. Make sure to [grab a Personal Access Token (PAT)](https://github.com/settings/tokens) before proceeding (you'll need `repo` permissions for private repos):
53+
We have a script to scan a given PR for vulnerabilities, which will help you test your local changes. Make sure to [grab a Personal Access Token (PAT)](https://github.com/settings/tokens) before proceeding (you'll need `repo` permissions for private repos):
5554

5655
<img width="480" alt="Screen to create a PAT with a note of `dr-token`, 30 day duration (expiring Jun 11, 2022), with `repo` scopes selected" src="https://user-images.githubusercontent.com/2161/168026161-16788a0a-b6c8-428e-bb6a-83ea2a403070.png">
5756

@@ -106,38 +105,34 @@ Here are a few things you can do that will increase the likelihood of your pull
106105

107106
_Note: these instructions are for maintainers_
108107

109-
1. Update the version number in [package.json](https://github.com/actions/dependency-review-action/blob/main/package.json) and run `npm i` to update the lockfile.
110-
1. Update the dist files by running `npm run build` and `npm run package`
111-
1. Go to [Draft a new
112-
release](https://github.com/actions/dependency-review-action/releases/new)
113-
in the Releases page.
114-
1. Make sure that the `Publish this Action to the GitHub Marketplace`
115-
checkbox is enabled
108+
- Create a local branch based on the `main` of the upstream repo.
109+
- Update the version number in [package.json](https://github.com/actions/dependency-review-action/blob/main/package.json) and run `npm i` to update the lockfile.
110+
- Update the dist files by running `npm run build` and `npm run package`
111+
- Go to [Draft a new release](https://github.com/actions/dependency-review-action/releases/new) in the Releases page.
112+
- Make sure that the `Publish this Action to the GitHub Marketplace` checkbox is enabled
116113

117114
<img width="481" alt="Screen showing Release Action with Publish this Action to the GitHub Marketplace checked" src="https://user-images.githubusercontent.com/2161/173822484-4b60d8b4-c674-4bff-b5ff-b0c4a3650ab7.png">
118115

119-
3. Click "Choose a tag" and then "Create new tag", where the tag name
120-
will be your version prefixed by a `v` (e.g. `v1.2.3`).
121-
4. Use a version number for the release title (e.g. "1.2.3").
116+
- Click "Choose a tag" and then "Create new tag", where the tag name
117+
will be your version prefixed by a `v` (e.g. `v1.2.3`).
118+
- Use a version number for the release title (e.g. "1.2.3").
122119

123120
<img width="700" alt="Create an action release in categories Security + Dependency management from branch main creating tag v2.0.0 on publish" src="https://user-images.githubusercontent.com/2161/173822548-33ab3432-d679-4dc1-adf8-b50fdaf47de3.png">
124121

125-
5. Add your release notes. If this is a major version make sure to
126-
include a small description of the biggest changes in the new version.
127-
6. Click "Publish Release".
122+
- Add your release notes. If this is a major version make sure to include details about any breaking changes in the new version.
123+
- Click "Publish Release".
128124

129-
You now have a tag and release using the semver version you used
130-
above. The last remaining thing to do is to move the dynamic version
131-
identifier to match the current SHA. This allows users to adopt a
132-
major version number (e.g. `v1`) in their workflows while
133-
automatically getting all the
134-
minor/patch updates.
125+
You now have a tag and release using the semver version you used above. The last remaining thing to do is to update the major version branch to match the current release. This allows users to adopt a major version number (e.g. `v4`) in their workflows while automatically getting all the minor/patch updates.
135126

136-
To do this just checkout `main`, force-create a new annotated tag, and push it:
127+
As of v4.8.3, we use a **branch** (not a force-pushed tag) for the major version pointer. This is important because force-pushing tags breaks GitHub's auto-generated release changelog links (see [#1035](https://github.com/actions/dependency-review-action/issues/1035)) and violates git's (unenforced) expectation that tags are immutable.
128+
129+
To update the major version branch:
137130

138131
```
139-
git tag -fa v4 -m "Updating v4 to 4.0.1"
140-
git push origin v4 --force
132+
git checkout main
133+
git pull origin main
134+
git branch -f v4 HEAD
135+
git push origin v4
141136
```
142137

143138
</details>

__tests__/licenses.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,33 @@ test('it does not filter out changes that are on the exclusions list', async ()
253253
expect(invalidLicenses.forbidden.length).toEqual(0)
254254
})
255255

256+
test('it excludes scoped npm packages when namespace separator is percent-encoded', async () => {
257+
const scopedNpmChange: Change = {
258+
manifest: 'package.json',
259+
change_type: 'added',
260+
ecosystem: 'npm',
261+
name: '@lancedb/lancedb',
262+
version: '0.14.3',
263+
package_url: 'pkg:npm/%40lancedb/lancedb@0.14.3',
264+
license: 'Apache-2.0',
265+
source_repository_url: 'github.com/lancedb/lancedb',
266+
scope: 'runtime',
267+
vulnerabilities: []
268+
}
269+
const changes: Changes = [scopedNpmChange, rubyChange]
270+
const licensesConfig = {
271+
allow: ['BSD-3-Clause'],
272+
// user provides %2F-encoded version
273+
licenseExclusions: ['pkg:npm/%40lancedb%2Flancedb']
274+
}
275+
const invalidLicenses = await getInvalidLicenseChanges(
276+
changes,
277+
licensesConfig
278+
)
279+
// scoped package should be excluded, only rubyChange remains (allowed)
280+
expect(invalidLicenses.forbidden.length).toEqual(0)
281+
})
282+
256283
test('it does not fail when the packages dont have a valid PURL', async () => {
257284
const emptyPurlChange = pipChange
258285
emptyPurlChange.package_url = ''

__tests__/main.test.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,13 @@ describe('handleLargeSummary', () => {
132132
expect(result).toContain('actions/runs/12345')
133133
})
134134

135-
test('returns original summary and logs a warning when artifact handling fails', async () => {
135+
test('returns truncated summary and replaces buffer when artifact upload fails', async () => {
136136
const warningMock = core.warning as jest.Mock
137+
const emptyBufferMock = core.summary.emptyBuffer as jest.Mock
138+
const addRawMock = core.summary.addRaw as jest.Mock
137139
warningMock.mockClear()
140+
emptyBufferMock.mockClear()
141+
addRawMock.mockClear()
138142
const largeSummary = 'b'.repeat(1024 * 1024 + 1)
139143

140144
DefaultArtifactClientMock.mockImplementation(() => ({
@@ -145,9 +149,16 @@ describe('handleLargeSummary', () => {
145149

146150
const result = await handleLargeSummary(largeSummary)
147151

148-
expect(result).toBe(largeSummary)
152+
// Should NOT return the original oversized content
153+
expect(result).not.toBe(largeSummary)
154+
// Should return a truncated summary
155+
expect(result).toContain('Dependency Review Summary')
156+
expect(result).toContain('too large to display')
157+
// Should replace the core.summary buffer to prevent write() from failing
158+
expect(emptyBufferMock).toHaveBeenCalled()
159+
expect(addRawMock).toHaveBeenCalledWith(result)
149160
expect(warningMock).toHaveBeenCalledWith(
150-
expect.stringContaining('Failed to handle large summary')
161+
expect.stringContaining('Failed to upload large summary as artifact')
151162
)
152163
})
153164
})

__tests__/purl.test.ts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {expect, test} from '@jest/globals'
2-
import {parsePURL} from '../src/purl'
2+
import {parsePURL, purlsMatch} from '../src/purl'
33

44
test('parsePURL returns an error if the purl does not start with "pkg:"', () => {
55
const purl = 'not-a-purl'
@@ -184,3 +184,66 @@ test('parsePURL table test', () => {
184184
expect(result).toEqual(example.expected)
185185
}
186186
})
187+
188+
test('purlsMatch matches identical PURLs', () => {
189+
const a = parsePURL('pkg:npm/@scope/name@1.0.0')
190+
const b = parsePURL('pkg:npm/@scope/name@2.0.0')
191+
expect(purlsMatch(a, b)).toBe(true)
192+
})
193+
194+
test('purlsMatch matches when namespace separator is percent-encoded', () => {
195+
// %2F-encoded separator puts everything in name with no namespace
196+
const encoded = parsePURL('pkg:npm/%40lancedb%2Flancedb')
197+
// literal / splits into namespace + name
198+
const literal = parsePURL('pkg:npm/%40lancedb/lancedb')
199+
expect(purlsMatch(encoded, literal)).toBe(true)
200+
})
201+
202+
test('purlsMatch matches scoped npm packages regardless of encoding', () => {
203+
const a = parsePURL('pkg:npm/%40lancedb%2Flancedb')
204+
const b = parsePURL('pkg:npm/@lancedb/lancedb')
205+
const c = parsePURL('pkg:npm/%40lancedb/lancedb@0.14.3')
206+
expect(purlsMatch(a, b)).toBe(true)
207+
expect(purlsMatch(a, c)).toBe(true)
208+
expect(purlsMatch(b, c)).toBe(true)
209+
})
210+
211+
test('purlsMatch does not match different packages', () => {
212+
const a = parsePURL('pkg:npm/@scope/foo')
213+
const b = parsePURL('pkg:npm/@scope/bar')
214+
expect(purlsMatch(a, b)).toBe(false)
215+
})
216+
217+
test('purlsMatch does not match different types', () => {
218+
const a = parsePURL('pkg:npm/@scope/name')
219+
const b = parsePURL('pkg:pypi/@scope/name')
220+
expect(purlsMatch(a, b)).toBe(false)
221+
})
222+
223+
test('purlsMatch matches packages without namespaces', () => {
224+
const a = parsePURL('pkg:npm/lodash@4.0.0')
225+
const b = parsePURL('pkg:npm/lodash@5.0.0')
226+
expect(purlsMatch(a, b)).toBe(true)
227+
})
228+
229+
test('purlsMatch is case-insensitive for GitHub Actions', () => {
230+
const a = parsePURL('pkg:githubactions/MyOrg/MyAction@1.0.0')
231+
const b = parsePURL('pkg:githubactions/myorg/myaction@1.0.0')
232+
expect(purlsMatch(a, b)).toBe(true)
233+
})
234+
235+
test('purlsMatch is case-insensitive for scoped npm packages', () => {
236+
const a = parsePURL('pkg:npm/@MyScope/MyPackage')
237+
const b = parsePURL('pkg:npm/@myscope/mypackage')
238+
expect(purlsMatch(a, b)).toBe(true)
239+
})
240+
241+
test('purlsMatch is case-insensitive for GitHub Actions with file paths', () => {
242+
const a = parsePURL(
243+
'pkg:githubactions/MyOrg/MyWorkflows/.github/workflows/general.yml'
244+
)
245+
const b = parsePURL(
246+
'pkg:githubactions/myorg/myworkflows/.github/workflows/general.yml'
247+
)
248+
expect(purlsMatch(a, b)).toBe(true)
249+
})

0 commit comments

Comments
 (0)