-
Notifications
You must be signed in to change notification settings - Fork 14
59 lines (50 loc) · 1.9 KB
/
check-license.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: Check License
env:
EXPECTED_LICENSE_FILENAME: LICENSE
# SPDX identifier: https://spdx.org/licenses/
EXPECTED_LICENSE_TYPE: MIT
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
on:
push:
paths:
- ".github/workflows/check-license.yml"
# See: https://github.com/licensee/licensee/blob/master/docs/what-we-look-at.md#detecting-the-license-file
- "COPYING*"
- "LICENCE*"
- "LICENSE*"
pull_request:
paths:
- ".github/workflows/check-license.yml"
- "COPYING*"
- "LICENCE*"
- "LICENSE*"
workflow_dispatch:
repository_dispatch:
jobs:
check-license:
runs-on: ubuntu-latest
steps:
- name: Checkout local repository
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ruby # Install latest version
- name: Install licensee
run: gem install licensee
- name: Check license file
run: |
# See: https://github.com/licensee/licensee
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
echo "Detected license file: $DETECTED_LICENSE_FILE"
if [ "$DETECTED_LICENSE_FILE" != "\"$EXPECTED_LICENSE_FILENAME\"" ]; then
echo "ERROR: detected license file doesn't match expected: $EXPECTED_LICENSE_FILENAME"
exit 1
fi
DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
echo "Detected license type: $DETECTED_LICENSE_TYPE"
if [ "$DETECTED_LICENSE_TYPE" != "\"$EXPECTED_LICENSE_TYPE\"" ]; then
echo "ERROR: detected license type doesn't match expected $EXPECTED_LICENSE_TYPE"
exit 1
fi