-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Create third party license file during production build, add CI #30360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bramkragten
wants to merge
2
commits into
dev
Choose a base branch
from
create-third-party-license-file
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,34 @@ | ||
| // Gulp task to generate third-party license notices. | ||
|
|
||
| import { generateLicenseFile } from "generate-license-file"; | ||
| import gulp from "gulp"; | ||
| import path from "path"; | ||
| import paths from "../paths.cjs"; | ||
|
|
||
| const OUTPUT_FILE = path.join( | ||
| paths.app_output_static, | ||
| "third-party-licenses.txt" | ||
| ); | ||
|
|
||
| // The echarts package ships an Apache-2.0 NOTICE file that must be | ||
| // redistributed alongside the compiled output per Apache License §4(d). | ||
| const NOTICE_FILES = [ | ||
| path.resolve(paths.root_dir, "node_modules/echarts/NOTICE"), | ||
| ]; | ||
|
|
||
| // type-fest ships two license files (MIT for code, CC0 for types). | ||
| // We use the MIT license since that covers the bundled code. | ||
| const LICENSE_OVERRIDES = { | ||
| "type-fest@5.4.4": path.resolve( | ||
| paths.root_dir, | ||
| "node_modules/type-fest/license-mit" | ||
| ), | ||
| }; | ||
|
|
||
| gulp.task("gen-licenses", async () => { | ||
| await generateLicenseFile( | ||
| path.resolve(paths.root_dir, "package.json"), | ||
| OUTPUT_FILE, | ||
| { append: NOTICE_FILES, replace: LICENSE_OVERRIDES } | ||
| ); | ||
| }); | ||
This file contains hidden or 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 hidden or 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,97 @@ | ||
| #!/usr/bin/env node | ||
| // Checks that all production dependencies use approved open-source licenses. | ||
| // | ||
| // To allow a new license type, add its SPDX identifier to ALLOWED_LICENSES. | ||
| // To allow a specific package that cannot be relicensed (e.g. a dual-license | ||
| // package where the reported identifier is non-standard), add it to | ||
| // ALLOWED_PACKAGES with a comment explaining why. | ||
|
|
||
| import checker from "license-checker"; | ||
| import { createRequire } from "module"; | ||
| import { fileURLToPath } from "url"; | ||
| import path from "path"; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
| const root = path.resolve(fileURLToPath(import.meta.url), "../../"); | ||
|
|
||
| // Permissive licenses that are compatible with distribution in a compiled wheel. | ||
| // Copyleft licenses (GPL, LGPL, AGPL, EUPL, etc.) must NOT be added here. | ||
| const ALLOWED_LICENSES = new Set([ | ||
| "MIT", | ||
| "MIT*", | ||
| "ISC", | ||
| "BSD-2-Clause", | ||
| "BSD-3-Clause", | ||
| "BSD*", | ||
| "Apache-2.0", | ||
| "0BSD", | ||
| "CC0-1.0", | ||
| "(MIT OR CC0-1.0)", | ||
| "(MIT AND Zlib)", | ||
| "Python-2.0", // argparse - Python Software Foundation License (permissive) | ||
| "Public Domain", | ||
| "W3C-20150513", // wicg-inert - W3C Software and Document License (permissive) | ||
| "Unlicense", | ||
| "CC-BY-4.0", | ||
| ]); | ||
|
|
||
| // Packages whose license identifier is ambiguous or non-standard but have been | ||
| // manually verified as permissive. Add only when strictly necessary. | ||
| const ALLOWED_PACKAGES = { | ||
| // No entries currently needed. | ||
| }; | ||
|
|
||
| checker.init( | ||
| { | ||
| start: root, | ||
| production: true, | ||
| excludePrivatePackages: true, | ||
| }, | ||
| (err, packages) => { | ||
| if (err) { | ||
| console.error("license-checker failed:", err); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const violations = []; | ||
|
|
||
| for (const [nameAtVersion, info] of Object.entries(packages)) { | ||
| if (nameAtVersion in ALLOWED_PACKAGES) { | ||
| continue; | ||
| } | ||
|
|
||
| const license = info.licenses; | ||
|
|
||
| if (!ALLOWED_LICENSES.has(license)) { | ||
| violations.push({ package: nameAtVersion, license }); | ||
| } | ||
| } | ||
|
|
||
| if (violations.length > 0) { | ||
| console.error( | ||
| "The following packages have licenses that are not on the allowlist:\n" | ||
| ); | ||
| for (const { package: pkg, license } of violations) { | ||
| console.error(` ${pkg}: ${license}`); | ||
| } | ||
| console.error( | ||
| "\nIf the license is permissive and appropriate for distribution, add it" | ||
| ); | ||
| console.error( | ||
| "to ALLOWED_LICENSES in script/check-licenses. If it is a specific" | ||
| ); | ||
| console.error( | ||
| "package with an ambiguous identifier, add it to ALLOWED_PACKAGES." | ||
| ); | ||
| console.error( | ||
| "\nDo NOT add copyleft licenses (GPL, LGPL, AGPL, etc.) to the allowlist." | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const count = Object.keys(packages).length; | ||
| console.log( | ||
| `License check passed: all ${count} production dependencies use approved licenses.` | ||
| ); | ||
| } | ||
| ); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing to consider is that this won't get updated by dependabot or renovate bot.