11# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-license.md
22name : 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-
9- # See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
4+ # See: https://docs.github.com/actions/reference/workflows-and-actions/events-that-trigger-workflows
105on :
6+ create :
117 push :
128 paths :
139 - " .github/workflows/check-license.ya?ml"
2521 - " [lL][iI][cC][eE][nN][cCsS][eE]*"
2622 - " [oO][fF][lL]*"
2723 - " [pP][aA][tT][eE][nN][tT][sS]*"
24+ schedule :
25+ # Run periodically to catch breakage caused by external changes.
26+ - cron : " 0 6 * * WED"
2827 workflow_dispatch :
2928 repository_dispatch :
3029
3130jobs :
31+ run-determination :
32+ runs-on : ubuntu-latest
33+ permissions : {}
34+ outputs :
35+ result : ${{ steps.determination.outputs.result }}
36+ steps :
37+ - name : Determine if the rest of the workflow should run
38+ id : determination
39+ run : |
40+ RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
41+ # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
42+ if [[
43+ "${{ github.event_name }}" != "create" ||
44+ "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
45+ ]]; then
46+ # Run the other jobs.
47+ RESULT="true"
48+ else
49+ # There is no need to run the other jobs.
50+ RESULT="false"
51+ fi
52+
53+ echo "result=$RESULT" >>$GITHUB_OUTPUT
54+
3255 check-license :
56+ name : ${{ matrix.check-license.path }}
57+ needs : run-determination
58+ if : needs.run-determination.outputs.result == 'true'
3359 runs-on : ubuntu-latest
60+ permissions :
61+ contents : read
62+
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
3472
3573 steps :
3674 - name : Checkout repository
@@ -42,25 +80,43 @@ jobs:
4280 ruby-version : ruby # Install latest version
4381
4482 - name : Install licensee
45- run : gem install licensee
83+ run : |
84+ gem install \
85+ licensee
4686
47- - name : Check license file
87+ - name : Check license file for ${{ matrix.check-license.path }}
4888 run : |
4989 EXIT_STATUS=0
90+
91+ # Go into folder path
92+ cd ./${{ matrix.check-license.path }}
93+
5094 # See: https://github.com/licensee/licensee
5195 LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
5296
53- DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
97+ DETECTED_LICENSE_FILE="$(
98+ echo "$LICENSEE_OUTPUT" \
99+ | \
100+ jq .matched_files[0].filename \
101+ | \
102+ tr --delete '\r'
103+ )"
54104 echo "Detected license file: $DETECTED_LICENSE_FILE"
55- if [ "$DETECTED_LICENSE_FILE" != "\"${EXPECTED_LICENSE_FILENAME }\"" ]; then
56- echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: $EXPECTED_LICENSE_FILENAME "
105+ if [ "$DETECTED_LICENSE_FILE" != "\"${{ matrix.check-license.expected-filename } }\"" ]; then
106+ echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: ${{ matrix.check-license.expected-filename }} "
57107 EXIT_STATUS=1
58108 fi
59109
60- DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
110+ DETECTED_LICENSE_TYPE="$(
111+ echo "$LICENSEE_OUTPUT" \
112+ | \
113+ jq .matched_files[0].matched_license \
114+ | \
115+ tr --delete '\r'
116+ )"
61117 echo "Detected license type: $DETECTED_LICENSE_TYPE"
62- if [ "$DETECTED_LICENSE_TYPE" != "\"${EXPECTED_LICENSE_TYPE }\"" ]; then
63- echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${EXPECTED_LICENSE_TYPE }\""
118+ if [ "$DETECTED_LICENSE_TYPE" != "\"${{ matrix.check-license.expected-type } }\"" ]; then
119+ echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${{ matrix.check-license.expected-type } }\""
64120 EXIT_STATUS=1
65121 fi
66122
0 commit comments