Skip to content

Commit

Permalink
feat: whitelist packages on check-licenses action (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobPasMue authored Oct 7, 2024
1 parent e40b18d commit 7d20f45
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
9 changes: 9 additions & 0 deletions build-wheelhouse/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ inputs:
default: true
type: boolean

whitelist-license-check:
description: |
Optional list of packages to ignore during the license check. Separated by a comma.
Only used when ``check-licenses`` is set to ``true``.
required: false
default: ''
type: string

checkout:
description: |
Whether to do a checkout step or not. If ``true``, the checkout step is performed.
Expand Down Expand Up @@ -188,3 +196,4 @@ runs:
python-version: ${{ inputs.python-version }}
skip-install: true
checkout: false
whitelist-license-check: ${{ inputs.whitelist-license-check }}
53 changes: 49 additions & 4 deletions check-licenses/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ inputs:
default: ''
type: string

whitelist-license-check:
description: |
Optional list of packages to ignore during the license check. Separated by a comma.
required: false
default: ''
type: string

skip-install:
description: |
Whether to skip the installation of the project. The default is ``false``.
Expand Down Expand Up @@ -161,22 +168,60 @@ runs:
wget https://raw.githubusercontent.com/ansys/actions/main/check-licenses/accepted-licenses.txt
wget https://raw.githubusercontent.com/ansys/actions/main/check-licenses/ignored-packages.txt
- name: "Process whitelisted packages provided on input"
shell: bash
run: |
if [[ -n "${{ inputs.whitelist-license-check }}" ]]; then
echo "Whitelisted packages: ${{ inputs.whitelist-license-check }}"
# Split the input string by comma, trim values and append them to the ignored-packages.txt file
IFS=',' read -ra whitelist <<< "${{ inputs.whitelist-license-check }}"
for package in "${whitelist[@]}"; do
echo "Ignoring whitelisted package: $package"
echo "$package" >> ignored-packages.txt
done
fi
- name: "Logging licenses and packages"
shell: bash
run: |
# Load accepted licenses
mapfile licenses_from_txt < accepted-licenses.txt
accepted_licenses='Accepted licenses:\n'
for license in ${licenses_from_txt[*]}; do accepted_licenses+="$license\n"; done
echo "LOG_ACCEPTED_LICENSES=$accepted_licenses" >> $GITHUB_ENV
# Load accepted packages
mapfile ignored_packages_from_txt < ignored-packages.txt
ignored_packages='Ignored packages:\n'
for pckg in ${ignored_packages_from_txt[*]}; do ignored_packages+="$pckg\n"; done
echo "LOG_IGNORED_PACKAGES=$ignored_packages" >> $GITHUB_ENV
- name: Log ignored packages and accepted licenses
uses: ansys/actions/_logging@main
with:
level: "INFO"
message: |
Licenses accepted and packages ignored
----------------------------------------------
${{ env.LOG_ACCEPTED_LICENSES }}
${{ env.LOG_IGNORED_PACKAGES }}
- name: "Check licences of packages"
shell: bash
run: |
# Load accepted licenses
mapfile licenses_from_txt < accepted-licenses.txt
accepted_licenses=''
for license in ${licenses_from_txt[*]}; do accepted_licenses+="$license\|"; done
accepted_licenses=${accepted_licenses::-2}
echo "Accepted licenses: $accepted_licenses"
accepted_licenses=${accepted_licenses::-2}
# Load accepted packages
mapfile ignored_packages_from_txt < ignored-packages.txt
ignored_packages=''
for pckg in ${ignored_packages_from_txt[*]}; do ignored_packages+="$pckg "; done
ignored_packages_from_txt=${ignored_packages_from_txt::-1}
echo "Ignored packages: $ignored_packages"
ignored_packages_from_txt=${ignored_packages_from_txt::-1}
# Verify if the Python environment contains invalid licenses
if [[ -z $(pip-licenses --summary --ignore-packages $ignored_packages | grep -v $accepted_licenses | tail -n+2) ]]; then
Expand Down

0 comments on commit 7d20f45

Please sign in to comment.