Skip to content

Commit 5faa6b6

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 85ad4dc commit 5faa6b6

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-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
5+
# SPDX identifier: https://spdx.org/licenses/
6+
EXPECTED_LICENSE_TYPE: GPL-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.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

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# setup-taskfile
22

3+
[![Check License status](https://github.com/arduino/setup-taskfile/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/setup-taskfile/actions/workflows/check-license.yml)
4+
35
This action makes the `task` binary available to Workflows.
46

57
## Usage

0 commit comments

Comments
 (0)