diff --git a/.travis.yml b/.travis.yml index 80bbbd1e0f9d5..e7d8d6cd46312 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ jobs: - stage: test script: - npm install || exit 1 - - npm run license-check || exit 1 + - ./bin/check-npm-licenses.sh || exit 1 - npm run ci || exit 1 - stage: test diff --git a/bin/check-npm-licenses.sh b/bin/check-npm-licenses.sh new file mode 100755 index 0000000000000..eae4e891964ff --- /dev/null +++ b/bin/check-npm-licenses.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Include useful functions +. "$(dirname "$0")/includes.sh" + +ALLOWED_LICENSES=( + "GPL-2.0-or-later" + "GPL-2.0+" + "(GPL-2.0 OR MIT)" + "MIT" + "ISC" + "BSD" + "BSD-2-Clause" + "BSD-3-Clause" + "CC0-1.0" +) + +FOUND_INCOMPATIBLE_MODULE=false + + +for MODULE_DIR in $(npm ls --production --parseable); do + PACKAGE_JSON="${MODULE_DIR}/package.json" + + PACKAGE_NAME=$(jq --raw-output '.name' $PACKAGE_JSON) + PACKAGE_LICENSE=$(jq --raw-output '( .license // .licenses[0].type )' $PACKAGE_JSON) + + if ! in_array "${PACKAGE_LICENSE}" "${ALLOWED_LICENSES[@]}"; then + if ! $FOUND_INCOMPATIBLE_MODULE; then + FOUND_INCOMPATIBLE_MODULE=true; + echo "These modules have incompatible licences:" + fi + echo "${PACKAGE_NAME}: ${PACKAGE_LICENSE}" + fi +done + +if ! $FOUND_INCOMPATIBLE_MODULE; then + echo "All module licenses are compatible." +else + exit 1; +fi diff --git a/package.json b/package.json index a096d14de93f5..3809fa3a7b457 100644 --- a/package.json +++ b/package.json @@ -129,7 +129,7 @@ "test": "npm run lint && npm run test-unit", "test-php": "npm run lint-php && npm run test-unit-php", "ci": "concurrently \"npm run lint && npm run build\" \"npm run test-unit:coverage-ci\"", - "license-check": "! npm ls --production --parseable | xargs -I {} jq --raw-output '.name + \" \" + ( .license // .licenses[0].type )' '{}/package.json' | grep -v -E '^.* .*(MIT|GPL-2|ISC|BSD|CC0).*$'", + "check-licenses": "./bin/check-npm-licenses.sh", "fixtures:clean": "rimraf \"blocks/test/fixtures/*.+(json|serialized.html)\"", "fixtures:server-registered": "docker-compose run -w /var/www/html/wp-content/plugins/gutenberg --rm wordpress ./bin/get-server-blocks.php > core-blocks/test/server-registered.json", "fixtures:generate": "npm run fixtures:server-registered && cross-env GENERATE_MISSING_FIXTURES=y npm run test-unit",