Skip to content
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

ci: assert license compatibility #117

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,44 @@ jobs:
- name: test
run: yarn run test:lint

test-licenses:
needs: [ 'build' ]
name: test licenses
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: install flict
run: pip install flict
- name: Checkout
# see https://github.com/actions/checkout
uses: actions/checkout@v4
- name: Setup Node.js ${{ env.NODE_ACTIVE_LTS }}
# see https://github.com/actions/setup-node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_ACTIVE_LTS }}
# cache: 'yarn'
- name: Setup yarn ${{ env.YARN_VERSION }}
run: |
corepack enable yarn
yarn set version ${{ env.YARN_VERSION }}
- name: Setup subject
run: |
yarn install --no-immutable
yarn info --name-only --recursive
- name: fetch build artifact
# see https://github.com/actions/download-artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.BUNDLES_DIR }}
path: ${{ env.BUNDLES_DIR }}
- name: make NOTICE and summary
run: |
mkdir -p _tmp
yarn node tools/write-3rd-party-licenses.cjs _tmp/NOTICE _tmp/lsummary
- name: test license compatibility
run: flict display-compatibility $(cat _tmp/lsummary)

test-node:
needs: [ 'build' ]
name: test (node${{ matrix.node-version }} ${{ matrix.os }})
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/dist/
/release_assets/


_tmp/

# yarn stuff - for now, until setup is hardened
# see also: https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
Expand Down
14 changes: 12 additions & 2 deletions tools/write-3rd-party-licenses.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async function getPackageMP (filePath, cache) {
/**
* @param {string} outputFile
* @param {boolean} includeLicense
* @return {Promise.<Set.<string>>} used licenses
*/
async function main (outputFile, includeLicense) {
const metaData = JSON.parse(readFileSync(metaFile))
Expand Down Expand Up @@ -139,7 +140,8 @@ async function main (outputFile, includeLicense) {
'that are compatibly licensed. We list these here.\n')
for (const tpLicense of tpLicenses) {
writeSync(outputFH, `\n${'-'.repeat(80)}\n`)
writeSync(outputFH, `Library Name: ${tpLicense.name} (${tpLicense.version})\n`)
writeSync(outputFH, `Name: ${tpLicense.name}\n`)
writeSync(outputFH, `Version: ${tpLicense.version}\n`)
writeSync(outputFH, `Distribution: https://www.npmjs.com/package/${tpLicense.name.replaceAll('@', '%40')}/v/${tpLicense.version}\n`)
writeSync(outputFH, `License declared: ${tpLicense.licenseDeclared}\n`)
for (const licenseFile of tpLicense.licenseFiles) {
Expand All @@ -155,12 +157,20 @@ async function main (outputFile, includeLicense) {
}

closeSync(outputFH)

return new Set(tpLicenses.map(l => l.licenseDeclared))
}

if (require.main === module) {
const outputFile = process.argv[2] || `${metaFile}.NOTICE`
const lsummaryFile = process.argv[3] || `${outputFile}.lsummary`
const includeLicense = false
main(outputFile, includeLicense)
main(outputFile, includeLicense).then(licenses => {
const lsummaryFH = openSync(lsummaryFile, 'w')
writeSync(lsummaryFH, JSON.parse(readFileSync(join(projectRoot, 'package.json'))).license + '\n')
writeSync(lsummaryFH, Array.from(licenses).sort().join('\n'))
closeSync(lsummaryFH)
})
} else {
module.exports = main
}
Loading