Skip to content

Commit f0c9ef6

Browse files
committed
Add support to "Check License" for checking license files in multiple paths
In cases where a project contains distinct components in subfolders, multiple license files might be present. Previously the "Check License" workflow only supported checking the license file in the root of the repository. Support for validating an arbitrary number of license files with arbitrary locations, types, and filenames is added. A job matrix is used to provide this support in a manner that makes application-specific configuration of the workflow easy and without code duplication.
1 parent 2234926 commit f0c9ef6

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

Diff for: .github/workflows/check-license.yml

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-license.md
22
name: Check License
33

4-
env:
5-
EXPECTED_LICENSE_FILENAME: LICENSE.txt
6-
# SPDX identifier: https://spdx.org/licenses/
7-
EXPECTED_LICENSE_TYPE: GPL-3.0
8-
94
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
105
on:
116
create:
@@ -58,12 +53,22 @@ jobs:
5853
echo "result=$RESULT" >> $GITHUB_OUTPUT
5954
6055
check-license:
56+
name: ${{ matrix.check-license.path }}
6157
needs: run-determination
6258
if: needs.run-determination.outputs.result == 'true'
6359
runs-on: ubuntu-latest
6460
permissions:
6561
contents: read
6662

63+
strategy:
64+
fail-fast: false
65+
66+
matrix:
67+
check-license:
68+
- path: ./
69+
expected-filename: LICENSE.txt
70+
# SPDX identifier: https://spdx.org/licenses/
71+
expected-type: GPL-3.0
6772

6873
steps:
6974
- name: Checkout repository
@@ -77,23 +82,27 @@ jobs:
7782
- name: Install licensee
7883
run: gem install licensee
7984

80-
- name: Check license file
85+
- name: Check license file for ${{ matrix.check-license.path }}
8186
run: |
8287
EXIT_STATUS=0
88+
89+
# Go into folder path
90+
cd ./${{ matrix.check-license.path }}
91+
8392
# See: https://github.com/licensee/licensee
8493
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
8594
8695
DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
8796
echo "Detected license file: $DETECTED_LICENSE_FILE"
88-
if [ "$DETECTED_LICENSE_FILE" != "\"${EXPECTED_LICENSE_FILENAME}\"" ]; then
89-
echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: $EXPECTED_LICENSE_FILENAME"
97+
if [ "$DETECTED_LICENSE_FILE" != "\"${{ matrix.check-license.expected-filename }}\"" ]; then
98+
echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: ${{ matrix.check-license.expected-filename }}"
9099
EXIT_STATUS=1
91100
fi
92101
93102
DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
94103
echo "Detected license type: $DETECTED_LICENSE_TYPE"
95-
if [ "$DETECTED_LICENSE_TYPE" != "\"${EXPECTED_LICENSE_TYPE}\"" ]; then
96-
echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${EXPECTED_LICENSE_TYPE}\""
104+
if [ "$DETECTED_LICENSE_TYPE" != "\"${{ matrix.check-license.expected-type }}\"" ]; then
105+
echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${{ matrix.check-license.expected-type }}\""
97106
EXIT_STATUS=1
98107
fi
99108

0 commit comments

Comments
 (0)