Skip to content

Commit

Permalink
tools/license.sh: script to generate LICENSE for product
Browse files Browse the repository at this point in the history
Runs from the project root directory.
That will generate LICENSE.prod, which should replace LICENSE
in the released product.

This script uses `yarn licenses generate-disclaimer`,
so this cl adds the dev dependency on yarn.

We call this during the release process.

And delete thirdpartynotices.txt - that is stale and was never updated after the first introduction. The autogenerated LICENSE file with tools/license.sh includes the license for json-rpc2.

Change-Id: I5c0869bc9a86aac1769441a663229eb4c5141b73
GitHub-Last-Rev: b561d4c
GitHub-Pull-Request: golang#240
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/238860
Reviewed-by: Rebecca Stambler <[email protected]>
  • Loading branch information
hyangah committed Jun 19, 2020
1 parent 38b056d commit a2147f7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 36 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
"sinon": "^9.0.2",
"tslint": "^6.1.1",
"typescript": "^3.8.3",
"vscode-test": "^1.3.0"
"vscode-test": "^1.3.0",
"yarn": "^1.22.4"
},
"engines": {
"vscode": "^1.41.0"
Expand Down
35 changes: 0 additions & 35 deletions thirdpartynotices.txt

This file was deleted.

70 changes: 70 additions & 0 deletions tools/license.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

# Copyright 2020 The Go Authors. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root for license information.

set -euo pipefail

root_dir() {
local script_name="${0}"
local script_dir=$(dirname "${script_name}")
local parent_dir=$(cd "${script_dir}/.." && pwd)
echo "${parent_dir}"
}

ROOT="$(root_dir)"
cd "${ROOT}" # always run from the root directory.

WORKTREE="$(mktemp -d)"
BRANCH="license-gen-$(date +%Y%m%d%H%M%S)"

git fetch
git worktree add --track -b "${BRANCH}" "${WORKTREE}" origin/master

cd "${WORKTREE}"
export GIT_GOFMT_HOOK=off

YARN="${ROOT}/node_modules/.bin/yarn"

ALL_LICENSES=$(
$YARN licenses list --json --no-progress 2>/dev/null|
jq 'select(.type == "table") | .data.body | map( {name: .[0], version: .[1], license: .[2], url: .[3], verndor: .[4], vendorName: .[5]} )')

NG=$(echo "${ALL_LICENSES}" | jq '
{
"Apache-2.0": 1,
"BSD-2-Clause": 1,
"BSD-3-Clause": 1,
"ISC": 1,
"MIT": 1,
"Unlicense": 1,
"0BSD": 1,
"(Unlicense OR Apache-2.0)": 1,
} as $allowed_licenses |
{
"[email protected]": 1,
} as $allow_list |
.[] | select(.license | in($allowed_licenses) | not)
| select((.name+"@"+.version) | in($allow_list) | not) ')

if [ -z "${NG}" ];
then
echo "PASSED license check"
else
echo "FAILED license check. The following dependencies need manual check: ${NG}" &&
echo "WORKTREE=${WORKTREE}" &&
exit 1
fi

LICENSEFILE="LICENSE.prod"
cat LICENSE > "${LICENSEFILE}"
printf "\n\n" >> "${LICENSEFILE}"
"${YARN}" licenses generate-disclaimer --prod >> "${LICENSEFILE}"

if [[ -f thirdpartynotices.txt ]]
then
printf "\n" >> "${LICENSEFILE}"
cat thirdpartynotices.txt >> "${LICENSEFILE}"
fi

cd - && mv "${WORKTREE}/${LICENSEFILE}" . && git worktree remove "${WORKTREE}" -f

0 comments on commit a2147f7

Please sign in to comment.