-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1024 from lumaxis/add-workflow-update-licensedb-m…
…apping Add Actions workflow to regularly update LicenseDB mapping
- Loading branch information
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
name: Run tests | ||
|
||
on: | ||
push: | ||
branches: | ||
|
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,41 @@ | ||
name: Update mapping from ScanCode LicenseDB data | ||
|
||
on: | ||
schedule: | ||
- cron: '43 5 * * 0' | ||
workflow_dispatch: # This allows for manual triggering of the workflow | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
update-database: | ||
name: Update mapping | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4.1.1 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4.0.1 | ||
|
||
- name: Fetch ScanCode LicenseDB | ||
run: | | ||
curl -o scancode-licensedb.json https://scancode-licensedb.aboutcode.org/index.json | ||
- name: Transform JSON and Update scancodeMap.js | ||
run: | | ||
node ./scripts/transform-scancode-licensedb.js | ||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v5 | ||
with: | ||
add-paths: lib/scancodeMap.js | ||
commit-message: Update ScanCode license mapping | ||
branch: update-scancode-licensedb | ||
title: Update license mapping with latest ScanCode LicenseDB data | ||
body: | | ||
This pull request updates the license mapping with the latest ScanCode LicenseDB data. | ||
For more information, see https://github.com/nexB/scancode-licensedb |
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,55 @@ | ||
// Script to transform the scancode-licensedb data and write it to scancodeMap.js | ||
|
||
/** | ||
* @typedef {Object} LicenseEntry | ||
* @property {string} license_key - Unique key for the license. | ||
* @property {string} category - Category of the license. | ||
* @property {string} spdx_license_key - Corresponding SPDX license key. | ||
* @property {string[]} other_spdx_license_keys - Array of other SPDX license keys, if any. | ||
* @property {boolean} is_exception - Indicates if the entry is an exception. | ||
* @property {boolean} is_deprecated - Indicates if the license is deprecated. | ||
* @property {string} json - Relative path to the JSON file for the license. | ||
* @property {string} yaml - Relative path to the YAML file for the license. | ||
* @property {string} html - Relative path to the HTML file for the license. | ||
* @property {string} license - Relative path to the LICENSE file for the license. | ||
*/ | ||
|
||
const fs = require('fs') | ||
|
||
// Read the downloaded JSON file | ||
const rawData = fs.readFileSync('scancode-licensedb.json') | ||
const scancodeData = JSON.parse(rawData.toString()) | ||
|
||
// Transform the data | ||
const transformedData = transformScancodeData(scancodeData) | ||
|
||
// Write the transformed data to scancodeMap.js | ||
fs.writeFileSync('lib/scancodeMap.js', generateScancodeMapContent(transformedData)) | ||
|
||
/** | ||
* @param {LicenseEntry[]} data | ||
* @returns {string[][]} | ||
*/ | ||
function transformScancodeData(data) { | ||
// Map the data to the required format | ||
return data.map(entry => [entry.license_key, entry.spdx_license_key]) | ||
} | ||
|
||
/** | ||
* @param {string[][]} data | ||
*/ | ||
function generateScancodeMapContent(data) { | ||
// Convert the array pairs into string format | ||
const content = data.map(([licenseKey, spdxLicenseKey]) => ` ['${licenseKey}', '${spdxLicenseKey}']`) | ||
return `// Copyright (c) Microsoft Corporation and others. Licensed under the MIT license. | ||
// SPDX-License-Identifier: MIT | ||
// *** THIS FILE IS AUTO-GENERATED by service/.github/workflows/transform-scancode-licensedb.js *** | ||
// *** DO NOT EDIT MANUALLY *** | ||
// | ||
// This is a mapping from scancode key to SPDX identifier based on https://scancode-licensedb.aboutcode.org/index.json | ||
// See licenses in https://github.com/nexB/scancode-toolkit/blob/develop/src/licensedcode/data/licenses/ | ||
module.exports = new Map([ | ||
${content.join(',\n')} | ||
]);` | ||
} |