Skip to content

Commit

Permalink
autogen: update license overview
Browse files Browse the repository at this point in the history
  • Loading branch information
ory-bot committed Jan 2, 2025
1 parent b915812 commit 1fd0a6b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .bin/license-engine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ done

# remove pre-approved modules
for approved in "${APPROVED_MODULES[@]}"; do
input=$(echo "$input" | grep -v "\"${approved}\"")
input=$(echo "$input" | grep -v "\"Custom: ${approved}\"")
input=$(echo "$input" | grep -vE "\"${approved}\"")
input=$(echo "$input" | grep -vE "\"Custom: ${approved}\"")
done

# remove allowed licenses
Expand Down
5 changes: 4 additions & 1 deletion .bin/licenses
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/sh
set -e

# Get the directory where this script is located
bin_dir="$(cd "$(dirname "$0")" && pwd)"

{ echo "Checking licenses ..."; } 2>/dev/null
.bin/list-licenses | .bin/license-engine.sh
"${bin_dir}/list-licenses" | "${bin_dir}/license-engine.sh"
43 changes: 23 additions & 20 deletions .bin/list-licenses
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#!/bin/sh
set -e

bin_dir="$(cd "$(dirname "$0")" && pwd)"

# list Node licenses
if [ -f package.json ]; then
if grep -q '"dependencies":\s+{[^}]*"[^"]+":' package.json; then
# List all direct Go module dependencies, transform their paths to root module paths
# (e.g., github.com/ory/x instead of github.com/ory/x/foo/bar), and generate a license report
# for each unique root module. This ensures that the license report is generated for the root
# module of a repository, where licenses are typically defined.
go list -f "{{if not .Indirect}}{{.Path}}{{end}}" -m ... |
sort -u |
awk -F/ '{ if ($1 == "github.com" && NF >= 3) { print $1"/"$2"/"$3 } else { print } }' |
sort -u |
xargs -I {} sh -c '.bin/go-licenses report --template .bin/license-template-go.tpl {}' 2>/dev/null |
grep -v '^$'
if jq -e '.dependencies and (.dependencies | keys | length > 0)' package.json >/dev/null; then
npm install >/dev/null 2>&1
npm exec --yes license-checker -- --production --csv --excludePrivatePackages --customPath "${bin_dir}"/license-template-node.json | grep -v '^$'
{ echo; } 2>/dev/null
else
echo "No dependencies found in package.json" >&2
Expand All @@ -22,14 +16,23 @@ fi

# list Go licenses
if [ -f go.mod ]; then
module_name=$(grep "^module" go.mod | awk '{print $2}')
if [ -z "$module_name" ]; then
echo "Cannot determine the Go module name" >&2
exit 1
# List all direct Go module dependencies, transform their paths to root module paths
# (e.g., github.com/ory/x instead of github.com/ory/x/foo/bar), and generate a license report
# for each unique root module. This ensures that the license report is generated for the root
# module of a repository, where licenses are typically defined.
go_modules=$(
go list -f "{{if not .Indirect}}{{.Path}}{{end}}" -m ... |
sort -u |
awk -F/ '{ if ($1 == "github.com" && NF >= 3) { print $1"/"$2"/"$3 } else { print } }' |
sort -u
{ echo; } 2>/dev/null
)
if [ -z "$go_modules" ]; then
echo "No Go modules found" >&2
else
# Workaround until https://github.com/google/go-licenses/issues/307 is fixed
# .bin/go-licenses report "$module_name" --template .bin/license-template-go.tpl 2>/dev/null
#
echo "$go_modules" | xargs -I {} sh -c '.bin/go-licenses report --template .bin/license-template-go.tpl {}' 2>/dev/null | grep -v '^$'
fi

# Workaround until https://github.com/google/go-licenses/issues/307 is fixed
# .bin/go-licenses report "$module_name" --template .bin/license-template-go.tpl 2>/dev/null
go list -f "{{if not .Indirect}}{{.Path}}{{end}}" -m ... | xargs -I {} sh -c '.bin/go-licenses report --template .bin/license-template-go.tpl {}' 2>/dev/null | grep -v '^$'
{ echo; } 2>/dev/null
fi

0 comments on commit 1fd0a6b

Please sign in to comment.