diff --git a/licenses/Makefile b/licenses/Makefile index 9b34f3c..39d6ca4 100644 --- a/licenses/Makefile +++ b/licenses/Makefile @@ -5,10 +5,7 @@ ifeq ($(ARCH),x86_64) ARCH_SHCK=x86_64 else ifeq ($(ARCH),arm64) ARCH=arm64 - ARCH_SHCK=arm64 -else ifeq ($(ARCH),aarch64) - ARCH=arm64 - ARCH_SHCK=arm64 + ARCH_SHCK=aarch64 else ifeq ($(ARCH),i386) ARCH=386 ARCH_SHCK=386 diff --git a/licenses/license-engine.sh b/licenses/license-engine.sh index f4eec1e..42a5951 100755 --- a/licenses/license-engine.sh +++ b/licenses/license-engine.sh @@ -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 diff --git a/licenses/licenses b/licenses/licenses index bbe6026..25d3c9d 100755 --- a/licenses/licenses +++ b/licenses/licenses @@ -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" diff --git a/licenses/list-licenses b/licenses/list-licenses index f5cd6e8..9a7cfa8 100755 --- a/licenses/list-licenses +++ b/licenses/list-licenses @@ -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 @@ -22,20 +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 - fi - - go_modules=$(go list -f "{{if not .Indirect}}{{.Path}}{{end}}" -m ... | sort -u) + # 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 - exit 0 + 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 - echo "$go_modules" | xargs -I {} sh -c '.bin/go-licenses report --template .bin/license-template-go.tpl {}' 2>/dev/null | grep -v '^$' - { echo; } 2>/dev/null fi diff --git a/licenses/setup/action.yml b/licenses/setup/action.yml index bccb7f2..ce774a7 100644 --- a/licenses/setup/action.yml +++ b/licenses/setup/action.yml @@ -19,6 +19,7 @@ runs: - uses: actions/setup-node@v2 with: node-version: "22" + - run: sudo apt-get install jq - name: Install license scanner run: curl https://raw.githubusercontent.com/ory/ci/master/licenses/install |