diff --git a/.github/workflows/build_and_deploy_dev.yml b/.github/workflows/build-and-deploy-dev.yml similarity index 100% rename from .github/workflows/build_and_deploy_dev.yml rename to .github/workflows/build-and-deploy-dev.yml diff --git a/.github/workflows/build.yml b/.github/workflows/test.yml similarity index 96% rename from .github/workflows/build.yml rename to .github/workflows/test.yml index 28c169766..5e0ae2971 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/test.yml @@ -1,3 +1,5 @@ +name: Run tests + on: push: branches: diff --git a/.github/workflows/update-scancode-licensedb.yml b/.github/workflows/update-scancode-licensedb.yml new file mode 100644 index 000000000..fa20bb8df --- /dev/null +++ b/.github/workflows/update-scancode-licensedb.yml @@ -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 diff --git a/scripts/transform-scancode-licensedb.js b/scripts/transform-scancode-licensedb.js new file mode 100644 index 000000000..25d6162ef --- /dev/null +++ b/scripts/transform-scancode-licensedb.js @@ -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')} +]);` +}