Skip to content

Commit e3cab86

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 ad800ef commit e3cab86

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

.github/workflows/check-license.yml

+20-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/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
105
on:
116
create:
@@ -58,12 +53,23 @@ 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
72+
6773
steps:
6874
- name: Checkout repository
6975
uses: actions/checkout@v4
@@ -76,23 +82,27 @@ jobs:
7682
- name: Install licensee
7783
run: gem install licensee
7884

79-
- name: Check license file
85+
- name: Check license file for ${{ matrix.check-license.path }}
8086
run: |
8187
EXIT_STATUS=0
88+
89+
# Go into folder path
90+
cd ./${{ matrix.check-license.path }}
91+
8292
# See: https://github.com/licensee/licensee
8393
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
8494
8595
DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
8696
echo "Detected license file: $DETECTED_LICENSE_FILE"
87-
if [ "$DETECTED_LICENSE_FILE" != "\"${EXPECTED_LICENSE_FILENAME}\"" ]; then
88-
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 }}"
8999
EXIT_STATUS=1
90100
fi
91101
92102
DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
93103
echo "Detected license type: $DETECTED_LICENSE_TYPE"
94-
if [ "$DETECTED_LICENSE_TYPE" != "\"${EXPECTED_LICENSE_TYPE}\"" ]; then
95-
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 }}\""
96106
EXIT_STATUS=1
97107
fi
98108

0 commit comments

Comments
 (0)