-
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
faee5c6
commit 96693b7
Showing
12 changed files
with
529 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,35 @@ | ||
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 = glob(["**/*.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 = ":update-package-golden.ts", | ||
) |
350 changes: 350 additions & 0 deletions
350
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,62 @@ | ||
/** | ||
* @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 { createPatch } from 'diff'; | ||
import { existsSync } from 'node:fs'; | ||
import { readFile } from 'node:fs/promises'; | ||
import { join } from 'node:path'; | ||
import { | ||
ANGULAR_SSR_PACKAGE_PATH, | ||
CRITTERS_ACTUAL_LICENSE_FILE_PATH, | ||
CRITTERS_GOLDEN_LICENSE_FILE_PATH, | ||
} from './utils'; | ||
|
||
describe('NPM Package Tests', () => { | ||
it('should not include the contents of third_party/critters/index.js in the FESM bundle', async () => { | ||
const fesmFilePath = join(ANGULAR_SSR_PACKAGE_PATH, 'fesm2022/ssr.mjs'); | ||
const fesmContent = await readFile(fesmFilePath, 'utf-8'); | ||
expect(fesmContent).toContain(`import Critters from '../third_party/critters/index.js'`); | ||
}); | ||
|
||
describe('third_party/critters/THIRD_PARTY_LICENSES.txt', () => { | ||
it('should exist', () => { | ||
expect(existsSync(CRITTERS_ACTUAL_LICENSE_FILE_PATH)).toBe(true); | ||
}); | ||
|
||
it('should match the expected golden file', async () => { | ||
const [expectedContent, actualContent] = await Promise.all([ | ||
readFile(CRITTERS_GOLDEN_LICENSE_FILE_PATH, 'utf-8'), | ||
readFile(CRITTERS_ACTUAL_LICENSE_FILE_PATH, 'utf-8'), | ||
]); | ||
|
||
if (expectedContent.trim() === actualContent.trim()) { | ||
return; | ||
} | ||
|
||
const patch = createPatch( | ||
CRITTERS_GOLDEN_LICENSE_FILE_PATH, | ||
expectedContent, | ||
actualContent, | ||
'Golden License File', | ||
'Current License File', | ||
{ context: 5 }, | ||
); | ||
|
||
const errorMessage = `The content of the actual license file differs from the expected golden reference. | ||
Diff: | ||
${patch} | ||
To accept the new golden file, execute: | ||
yarn bazel run ${process.env['BAZEL_TARGET']}.accept | ||
`; | ||
|
||
const error = new Error(errorMessage); | ||
error.stack = error.stack?.replace(` Diff:\n ${patch}`, ''); | ||
throw error; | ||
}); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/angular/ssr/test/npm_package/update-package-golden.ts
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,15 @@ | ||
/** | ||
* @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 { readFileSync, writeFileSync } from 'node:fs'; | ||
import { CRITTERS_ACTUAL_LICENSE_FILE_PATH, CRITTERS_GOLDEN_LICENSE_FILE_PATH } from './utils'; | ||
|
||
/** | ||
* Updates the golden reference license file. | ||
*/ | ||
writeFileSync(CRITTERS_GOLDEN_LICENSE_FILE_PATH, readFileSync(CRITTERS_ACTUAL_LICENSE_FILE_PATH)); |
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,32 @@ | ||
/** | ||
* @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 { dirname, join } from 'node:path'; | ||
|
||
/** | ||
* Resolve paths for the Critters license file and the golden reference file. | ||
*/ | ||
export const ANGULAR_SSR_PACKAGE_PATH = dirname( | ||
runfiles.resolve('angular_cli/packages/angular/ssr/npm_package/package.json'), | ||
); | ||
|
||
/** | ||
* Path to the actual license file for the Critters library. | ||
* This file is located in the `third_party/critters` directory of the Angular CLI npm package. | ||
*/ | ||
export const CRITTERS_ACTUAL_LICENSE_FILE_PATH = join( | ||
ANGULAR_SSR_PACKAGE_PATH, | ||
'third_party/critters/THIRD_PARTY_LICENSES.txt', | ||
); | ||
|
||
/** | ||
* Path to the golden reference license file for the Critters library. | ||
* This file is used as a reference for comparison and is located in the same directory as this script. | ||
*/ | ||
export const CRITTERS_GOLDEN_LICENSE_FILE_PATH = join(__dirname, 'THIRD_PARTY_LICENSES.txt.golden'); |
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