From 78d0e3b62230405d10cce7116b603882e9f916e0 Mon Sep 17 00:00:00 2001 From: Vincenzo Pierro Date: Fri, 8 Nov 2024 14:32:26 +0100 Subject: [PATCH 1/3] Updated license report workflow --- .github/licenses-report.sh | 52 +++++++++++++++++++++++++++ .github/workflows/licenses-report.yml | 4 +-- 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100755 .github/licenses-report.sh diff --git a/.github/licenses-report.sh b/.github/licenses-report.sh new file mode 100755 index 00000000..139e9fea --- /dev/null +++ b/.github/licenses-report.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +# Initialize an empty JSON array for the report +report='[]' + +# Install dependencies in all workspaces +yarn install > /dev/null 2>&1 + +# Get the list of workspaces and extract their locations +workspaces=$(yarn workspaces list --json | awk -F\" '/location/ {print $4}') + +# Iterate through each workspace +for workspace in $workspaces; do + # Change to the workspace directory + cd "$workspace" || exit + + # Check if dependencies are listed in package.json + if grep -q '"dependencies"' package.json; then + # Get the list of production dependencies + dependencies=$(jq -r ' .dependencies | keys[]' package.json) + + # Iterate through each dependency + for dependency in $dependencies; do + # Path to the dependency's package.json file within the workspace's node_modules + depPath="node_modules/$dependency/package.json" + + # If not found, check the global node_modules directory + [[ ! -f $depPath ]] && depPath="../../node_modules/$dependency/package.json" + + # Check if the package.json file exists + if [[ -f $depPath ]]; then + # Get the repository, license, and version information + repo=$(jq -r '.repository? | if type == "object" then .url else . end // "null"' "$depPath") + license=$(jq -r '.license // "null"' "$depPath" | sed 's/AND/&/g') + version=$(jq -r '.version // "null"' "$depPath") + + # Add the information to the JSON array + report=$(echo $report | jq --arg dep "$dependency" --arg repo $repo --arg license "$license" --arg version "$version" '. + [{dependency: $dep, repository: $repo, license: $license, version: $version}]') + fi + done + fi + + # Change back to the root directory + # shellcheck disable=SC2164 + cd - > /dev/null +done + +# Deduplicate entries based on dependency name and version +report=$(echo "$report" | jq 'unique_by(.dependency, .version)') + +# Write the report to stdout +echo "$report" | jq '.' diff --git a/.github/workflows/licenses-report.yml b/.github/workflows/licenses-report.yml index 0f98cd7f..29c2aafe 100644 --- a/.github/workflows/licenses-report.yml +++ b/.github/workflows/licenses-report.yml @@ -1,8 +1,8 @@ name: Licenses report on: push: - branches: [main] - workflow_dispatch: + branches: + - "main" jobs: licenses_report: From 4863e634b7df4144652a447085fd6644c0f7b621 Mon Sep 17 00:00:00 2001 From: Vincenzo Pierro Date: Fri, 8 Nov 2024 14:51:34 +0100 Subject: [PATCH 2/3] Updated workflow triggers --- .github/workflows/licenses-report.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/licenses-report.yml b/.github/workflows/licenses-report.yml index 29c2aafe..2bb24cbd 100644 --- a/.github/workflows/licenses-report.yml +++ b/.github/workflows/licenses-report.yml @@ -2,7 +2,12 @@ name: Licenses report on: push: branches: - - "main" + - "ci/fix-license-report-workflow" + pull_request: + types: + - closed + branches: + - 'main' jobs: licenses_report: From 4f99992037095e3e2f0f50a42fda909a8a48b3bd Mon Sep 17 00:00:00 2001 From: Vincenzo Pierro Date: Fri, 8 Nov 2024 14:53:38 +0100 Subject: [PATCH 3/3] Removed test trigger --- .github/workflows/licenses-report.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/licenses-report.yml b/.github/workflows/licenses-report.yml index 2bb24cbd..3c502b52 100644 --- a/.github/workflows/licenses-report.yml +++ b/.github/workflows/licenses-report.yml @@ -1,8 +1,5 @@ name: Licenses report on: - push: - branches: - - "ci/fix-license-report-workflow" pull_request: types: - closed