Skip to content

Commit 66aa744

Browse files
committed
Add CI workflow to check the license file
Whenever one of the recognized license file names are modified in the repository, the workflow runs to check whether the license can be recognized and whether it is of the expected type.
1 parent b3a7ec7 commit 66aa744

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-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/actions/reference/events-that-trigger-workflows
9+
on:
10+
push:
11+
paths:
12+
- ".github/workflows/check-license.ya?ml"
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.ya?ml"
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

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
[![Check Go status](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-go.yml/badge.svg)](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-go.yml)
33
[![Check Prettier Formatting status](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-prettier-formatting-task.yml/badge.svg)](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-prettier-formatting-task.yml)
44
[![Spell Check status](https://github.com/arduino/libraries-repository-engine/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/libraries-repository-engine/actions/workflows/spell-check-task.yml)
5+
[![Check License status](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-license.yml)
56

67
## BUILD
78

0 commit comments

Comments
 (0)