|
| 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