Skip to content

Commit 04fadc6

Browse files
committed
NEW Check that all dependency licesnes are permissive
1 parent 752055a commit 04fadc6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

action.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,14 @@ runs:
281281
echo "Running yarn lint"
282282
yarn run lint
283283
fi
284+
# Validate licenses of all dependencies are permissive
285+
echo "Checking licenses of all dependencies"
286+
npm install -g license-checker
287+
# A list of allowed software licesnses that are permissive - see https://spdx.org/licenses/ for a list of SPDX identifiers
288+
# IMPORTANT! If this is updated also update the same variable in the "Run PHP linting" step
289+
SPDX_ALLOWED_DELIMITED="MIT;MIT-0;ISC;0BSD;BSD-2-Clause;BSD-3-Clause;Apache-2.0;Python-2.0;CC0-1.0;CC-BY-3.0;CC-BY-4.0;Public Domain;Unlicense"
290+
license-checker --production --unknown --out /dev/null --onlyAllow "$SPDX_ALLOWED_DELIMITED"
291+
# If we get to this point, everything was successful
284292
echo "Passed"
285293
286294
- name: "Run PHP linting"
@@ -302,6 +310,32 @@ runs:
302310
echo "Running PHPStan"
303311
vendor/bin/phpstan analyse
304312
fi
313+
# Validate licenses of all dependencies are permissive
314+
echo "Checking licenses of all dependencies"
315+
composer global require madewithlove/license-checker
316+
COMPOSER_GLOBAL_HOME=$(composer -q -n config --global home)
317+
# A list of allowed software licesnses that are permissive - see https://spdx.org/licenses/ for a list of SPDX identifiers
318+
# IMPORTANT! If this is updated also update the same variable in the "Run JS tests" step
319+
SPDX_ALLOWED_DELIMITED="MIT;MIT-0;ISC;0BSD;BSD-2-Clause;BSD-3-Clause;Apache-2.0;Python-2.0;CC0-1.0;CC-BY-3.0;CC-BY-4.0;Public Domain;Unlicense"
320+
# translate " " to "__" (and back again later) in case any dependencies have a space in them
321+
# otherwise the bash for loop will split on the space
322+
SPDX_ALLOWED_LIST=$(echo $SPDX_ALLOWED_DELIMITED | tr " " "__" | tr ";" "\n")
323+
SPDX_USED_LIST=$($COMPOSER_GLOBAL_HOME/vendor/bin/license-checker --no-dev used)
324+
for SPDX_USED in $SPDX_USED_LIST; do
325+
IS_ALLOWED=0
326+
for SPDX_ALLOWED in $SPDX_ALLOWED_LIST; do
327+
SPDX_ALLOWED=$(echo $SPDX_ALLOWED | tr "__" " ")
328+
if [[ $SPDX_USED == $SPDX_ALLOWED ]]; then
329+
IS_ALLOWED=1
330+
break
331+
fi
332+
done
333+
if [[ $IS_ALLOWED == 0 ]]; then
334+
echo "License $SPDX_USED found in composer dependecies is not allowed"
335+
exit 1
336+
fi
337+
done
338+
# If we get to this point, everything was successful
305339
echo "Passed"
306340
307341
- name: "Run PHP coverage"

0 commit comments

Comments
 (0)