Debian Codegraph @

.github/workflows/check-license.yml

raw
1 # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-license.md
2 name: Check License
3
4 # See: https://docs.github.com/actions/reference/workflows-and-actions/events-that-trigger-workflows
5 on:
6 create:
7 push:
8 paths:
9 - ".github/workflows/check-license.ya?ml"
10 # See: https://github.com/licensee/licensee/blob/master/docs/what-we-look-at.md#detecting-the-license-file
11 - "[cC][oO][pP][yY][iI][nN][gG]*"
12 - "[cC][oO][pP][yY][rR][iI][gG][hH][tH]*"
13 - "[lL][iI][cC][eE][nN][cCsS][eE]*"
14 - "[oO][fF][lL]*"
15 - "[pP][aA][tT][eE][nN][tT][sS]*"
16 pull_request:
17 paths:
18 - ".github/workflows/check-license.ya?ml"
19 - "[cC][oO][pP][yY][iI][nN][gG]*"
20 - "[cC][oO][pP][yY][rR][iI][gG][hH][tH]*"
21 - "[lL][iI][cC][eE][nN][cCsS][eE]*"
22 - "[oO][fF][lL]*"
23 - "[pP][aA][tT][eE][nN][tT][sS]*"
24 schedule:
25 # Run periodically to catch breakage caused by external changes.
26 - cron: "0 6 * * WED"
27 workflow_dispatch:
28 repository_dispatch:
29
30 jobs:
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
55 check-license:
56 name: ${{ matrix.check-license.path }}
57 needs: run-determination
58 if: needs.run-determination.outputs.result == 'true'
59 runs-on: ubuntu-latest
60 permissions:
61 contents: read
62
63 strategy:
64 fail-fast: false
65
66 matrix:
67 check-license:
68 # TODO: Add additional paths where license files should be
69 - path: .
70 # TODO: Define the project's license file name here:
71 expected-filename: LICENSE.txt
72 # SPDX identifier: https://spdx.org/licenses/
73 # TODO: Define the project's license type here
74 expected-type: GPL-2.0
75
76 steps:
77 - name: Checkout repository
78 uses: actions/checkout@v7
79
80 - name: Install Ruby
81 uses: ruby/setup-ruby@v1
82 with:
83 ruby-version: ruby # Install latest version
84
85 - name: Install licensee
86 run: |
87 gem install \
88 licensee
89
90 - name: Check license file for ${{ matrix.check-license.path }}
91 run: |
92 EXIT_STATUS=0
93
94 # Go into folder path
95 cd ./${{ matrix.check-license.path }}
96
97 # See: https://github.com/licensee/licensee
98 LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
99
100 DETECTED_LICENSE_FILE="$(
101 echo "$LICENSEE_OUTPUT" \
102 | \
103 jq .matched_files[0].filename \
104 | \
105 tr --delete '\r'
106 )"
107 echo "Detected license file: $DETECTED_LICENSE_FILE"
108 if [ "$DETECTED_LICENSE_FILE" != "\"${{ matrix.check-license.expected-filename }}\"" ]; then
109 echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: ${{ matrix.check-license.expected-filename }}"
110 EXIT_STATUS=1
111 fi
112
113 DETECTED_LICENSE_TYPE="$(
114 echo "$LICENSEE_OUTPUT" \
115 | \
116 jq .matched_files[0].matched_license \
117 | \
118 tr --delete '\r'
119 )"
120 echo "Detected license type: $DETECTED_LICENSE_TYPE"
121 if [ "$DETECTED_LICENSE_TYPE" != "\"${{ matrix.check-license.expected-type }}\"" ]; then
122 echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${{ matrix.check-license.expected-type }}\""
123 EXIT_STATUS=1
124 fi
125
126 exit $EXIT_STATUS