Skip to content

Commit b67f437

Browse files
kellyguo11ooctipus
authored andcommitted
Adds automated job to check for dependency licensing (isaac-sim#2488)
# Description Automated job that runs on every PR to check for any dependencies that have non-permissive licenses. ## Type of change - Bug fix (non-breaking change which fixes an issue) ## Checklist - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file - [ ] I have added my name to the `CONTRIBUTORS.md` or my name already exists there <!-- As you go through the checklist above, you can mark something as done by putting an x character in it For example, - [x] I have done this task - [ ] I have not done this task --> --------- Signed-off-by: Kelly Guo <kellyguo123@hotmail.com>
1 parent be7a301 commit b67f437

File tree

2 files changed

+432
-0
lines changed

2 files changed

+432
-0
lines changed

.github/workflows/license-check.yaml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Check Python Dependency Licenses
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
license-check:
13+
runs-on: ubuntu-24.04
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
19+
# - name: Install jq
20+
# run: sudo apt-get update && sudo apt-get install -y jq
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: '3.10' # Adjust as needed
26+
27+
- name: Install dependencies using ./isaaclab.sh -i
28+
run: |
29+
# first install isaac sim
30+
pip install --upgrade pip
31+
pip install 'isaacsim[all,extscache]==4.5.0' --extra-index-url https://pypi.nvidia.com
32+
chmod +x ./isaaclab.sh # Make sure the script is executable
33+
# install all lab dependencies
34+
./isaaclab.sh -i
35+
36+
- name: Install pip-licenses
37+
run: |
38+
pip install pip-licenses
39+
pip install -r tools/template/requirements.txt
40+
pip install -r docs/requirements.txt
41+
42+
# Optional: Print the license report for visibility
43+
- name: Print License Report
44+
run: pip-licenses --from=mixed --format=markdown
45+
46+
- name: Check licenses against whitelist and exceptions
47+
run: |
48+
# Define the whitelist of allowed licenses
49+
ALLOWED_LICENSES="MIT Apache BSD ISC zlib"
50+
51+
# Load the exceptions list from the exceptions.json file
52+
EXCEPTIONS_FILE=".github/workflows/license-exceptions.json"
53+
54+
# Get the list of installed packages and their licenses
55+
pip-licenses --from=mixed --format=json > licenses.json
56+
57+
# Check the output of pip-licenses to ensure it is valid JSON
58+
if ! jq empty licenses.json; then
59+
echo "ERROR: Failed to parse pip-licenses output. Exiting..."
60+
exit 1
61+
fi
62+
63+
# Split ALLOWED_LICENSES into individual words
64+
IFS=' ' read -r -a allowed_licenses <<< "$ALLOWED_LICENSES"
65+
66+
# Loop through the installed packages and their licenses
67+
for pkg in $(jq -r '.[].Name' licenses.json); do
68+
LICENSE=$(jq -r --arg pkg "$pkg" '.[] | select(.Name == $pkg) | .License' licenses.json)
69+
70+
# Check if any of the allowed licenses are a substring of the package's license
71+
match_found=false
72+
for allowed_license in "${allowed_licenses[@]}"; do
73+
if [[ "$LICENSE" == *"$allowed_license"* ]]; then
74+
match_found=true
75+
break
76+
fi
77+
done
78+
79+
if [ "$match_found" = false ]; then
80+
# Check if the package is in the exceptions list
81+
EXCEPTION=$(jq -r --arg pkg "$pkg" --arg license "$LICENSE" \
82+
'.[] | select(.package == $pkg)' "$EXCEPTIONS_FILE")
83+
84+
# If the package is in the exceptions list
85+
if [ -n "$EXCEPTION" ]; then
86+
# If the license is provided in the exceptions list, check the license
87+
EXCEPTION_LICENSE=$(echo "$EXCEPTION" | jq -r '.license')
88+
89+
# echo "Comparing licenses for $pkg:"
90+
# echo " EXCEPTION_LICENSE='${EXCEPTION_LICENSE}' (len=${#EXCEPTION_LICENSE})"
91+
# echo " LICENSE='${LICENSE}' (len=${#LICENSE})"
92+
93+
# If the exceptions list has a license and doesn't match the current license
94+
if [ "$EXCEPTION_LICENSE" != "null" ] && [ "$EXCEPTION_LICENSE" != "$LICENSE" ]; then
95+
echo "ERROR: $pkg has license: $LICENSE"
96+
FAILED_PACKAGES=$((FAILED_PACKAGES + 1)) # Increment the counter
97+
fi
98+
else
99+
# If the package is not in the exceptions list
100+
echo "ERROR: $pkg has license: $LICENSE"
101+
FAILED_PACKAGES=$((FAILED_PACKAGES + 1)) # Increment the counter
102+
fi
103+
fi
104+
done
105+
106+
# After all packages are processed, check if there were any errors
107+
if [ "$FAILED_PACKAGES" -gt 0 ]; then
108+
echo "ERROR: $FAILED_PACKAGES packages were flagged."
109+
exit 1 # Fail the build
110+
else
111+
echo "All packages were checked."
112+
fi
113+
114+
# Print pipdeptree
115+
- name: Print pipdeptree
116+
run: |
117+
pip install pipdeptree
118+
pipdeptree

0 commit comments

Comments
 (0)