Skip to content

Commit 6c26c70

Browse files
authored
Merge pull request #17 from arduino/license-ci
Add CI workflow to check the license file
2 parents 06b0502 + 312bcc3 commit 6c26c70

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

.github/workflows/check-license.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Check License
2+
3+
env:
4+
EXPECTED_LICENSE_FILENAME: LICENSE.txt
5+
# SPDX identifier: https://spdx.org/licenses/
6+
EXPECTED_LICENSE_TYPE: AGPL-3.0
7+
8+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
9+
on:
10+
push:
11+
paths:
12+
- ".github/workflows/check-license.yml"
13+
# See: https://github.com/licensee/licensee/blob/master/docs/what-we-look-at.md#detecting-the-license-file
14+
- "[cC][oO][pP][yY][iI][nN][gG]*"
15+
- "[cC][oO][pP][yY][rR][iI][gG][hH][tH]*"
16+
- "[lL][iI][cC][eE][nN][cCsS][eE]*"
17+
- "[oO][fF][lL]*"
18+
- "[pP][aA][tT][eE][nN][tT][sS]*"
19+
pull_request:
20+
paths:
21+
- ".github/workflows/check-license.yml"
22+
- "[cC][oO][pP][yY][iI][nN][gG]*"
23+
- "[cC][oO][pP][yY][rR][iI][gG][hH][tH]*"
24+
- "[lL][iI][cC][eE][nN][cCsS][eE]*"
25+
- "[oO][fF][lL]*"
26+
- "[pP][aA][tT][eE][nN][tT][sS]*"
27+
workflow_dispatch:
28+
repository_dispatch:
29+
30+
jobs:
31+
check-license:
32+
runs-on: ubuntu-latest
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v2
37+
38+
- name: Install Ruby
39+
uses: ruby/setup-ruby@v1
40+
with:
41+
ruby-version: ruby # Install latest version
42+
43+
- name: Install licensee
44+
run: gem install licensee
45+
46+
- name: Check license file
47+
run: |
48+
# See: https://github.com/licensee/licensee
49+
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
50+
51+
DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
52+
echo "Detected license file: $DETECTED_LICENSE_FILE"
53+
if [ "$DETECTED_LICENSE_FILE" != "\"$EXPECTED_LICENSE_FILENAME\"" ]; then
54+
echo "ERROR: detected license file doesn't match expected: $EXPECTED_LICENSE_FILENAME"
55+
exit 1
56+
fi
57+
58+
DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
59+
echo "Detected license type: $DETECTED_LICENSE_TYPE"
60+
if [ "$DETECTED_LICENSE_TYPE" != "\"$EXPECTED_LICENSE_TYPE\"" ]; then
61+
echo "ERROR: detected license type doesn't match expected $EXPECTED_LICENSE_TYPE"
62+
exit 1
63+
fi

0 commit comments

Comments
 (0)