-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: add function to validate and update 3rd party license files
- Implemented functionality to compare and update third-party license files - Added handling for '--accept' argument to update the golden license file - Included tests to ensure the Critters license file matches the golden reference This update ensures license file consistency and provides an easy way to update the reference file when necessary.
- Loading branch information
1 parent
5d45ecd
commit 17a0038
Showing
10 changed files
with
500 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") | ||
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test") | ||
load("//tools:defaults.bzl", "ts_library") | ||
|
||
ts_library( | ||
name = "unit_test_lib", | ||
testonly = True, | ||
srcs = ["package_spec.ts"], | ||
deps = [ | ||
"@npm//@bazel/runfiles", | ||
"@npm//@types/diff", | ||
], | ||
) | ||
|
||
jasmine_node_test( | ||
name = "test", | ||
srcs = [":unit_test_lib"], | ||
data = [ | ||
"THIRD_PARTY_LICENSES.txt.golden", | ||
"//packages/angular/ssr:npm_package", | ||
"@npm//diff", | ||
], | ||
) | ||
|
||
nodejs_binary( | ||
name = "test.accept", | ||
testonly = True, | ||
data = [ | ||
"THIRD_PARTY_LICENSES.txt.golden", | ||
":unit_test_lib", | ||
"//packages/angular/ssr:npm_package", | ||
"@npm//diff", | ||
], | ||
entry_point = ":package_spec.ts", | ||
templated_args = ["--accept"], | ||
) |
365 changes: 365 additions & 0 deletions
365
packages/angular/ssr/test/npm_package/THIRD_PARTY_LICENSES.txt.golden
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.dev/license | ||
*/ | ||
|
||
import { runfiles } from '@bazel/runfiles'; | ||
import { createPatch } from 'diff'; | ||
import { existsSync, readFileSync, writeFileSync } from 'node:fs'; | ||
import { readFile } from 'node:fs/promises'; | ||
import { dirname, join } from 'node:path'; | ||
|
||
// Resolve paths for the Critters license file and the golden reference file | ||
const angularSsrPackagePath = dirname( | ||
runfiles.resolve('angular_cli/packages/angular/ssr/npm_package/package.json'), | ||
); | ||
const crittersActualLicenseFilePath = join( | ||
angularSsrPackagePath, | ||
'third_party/critters/THIRD_PARTY_LICENSES.txt', | ||
); | ||
const crittersGoldenLicenseFilePath = join(__dirname, 'THIRD_PARTY_LICENSES.txt.golden'); | ||
|
||
// If '--accept' argument is provided, update the golden reference file | ||
if (process.argv.slice(2).includes('--accept')) { | ||
writeFileSync(crittersGoldenLicenseFilePath, readFileSync(crittersActualLicenseFilePath)); | ||
} else { | ||
describe('NPM Package', () => { | ||
it('Should have the third-party licenses file', () => { | ||
expect(existsSync(crittersActualLicenseFilePath)).toBe(true); | ||
}); | ||
|
||
it('Critters third-party licenses should match the golden reference', async () => { | ||
const [expectedContent, actualContent] = await Promise.all([ | ||
readFile(crittersGoldenLicenseFilePath, 'utf-8'), | ||
readFile(crittersActualLicenseFilePath, 'utf-8'), | ||
]); | ||
|
||
if (expectedContent.trim() === actualContent.trim()) { | ||
return; | ||
} | ||
|
||
const patch = createPatch( | ||
crittersGoldenLicenseFilePath, | ||
expectedContent, | ||
actualContent, | ||
'Golden License File', | ||
'Current License File', | ||
{ context: 5 }, | ||
); | ||
|
||
const failure = new Error(`Actual contents differ from the golden reference | ||
Diff: | ||
${patch} | ||
To accept the new golden file, run: | ||
yarn bazel run ${process.env['BAZEL_TARGET']}.accept | ||
`); | ||
|
||
failure.stack = failure.stack?.replace(` Diff:\n ${patch}`, ''); | ||
throw failure; | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters