Skip to content

Commit fb49847

Browse files
authored
Merge pull request #21 from per1234/check-license
Add template workflow to check the license file
2 parents bfd34ba + 32da0ef commit fb49847

File tree

4 files changed

+207
-6
lines changed

4 files changed

+207
-6
lines changed

.github/workflows/check-license.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,22 @@ jobs:
4747

4848
- name: Check license file
4949
run: |
50+
EXIT_STATUS=0
5051
# See: https://github.com/licensee/licensee
5152
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
5253
5354
DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
5455
echo "Detected license file: $DETECTED_LICENSE_FILE"
55-
if [ "$DETECTED_LICENSE_FILE" != "\"$EXPECTED_LICENSE_FILENAME\"" ]; then
56-
echo "ERROR: detected license file doesn't match expected: $EXPECTED_LICENSE_FILENAME"
57-
exit 1
56+
if [ "$DETECTED_LICENSE_FILE" != "\"${EXPECTED_LICENSE_FILENAME}\"" ]; then
57+
echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: $EXPECTED_LICENSE_FILENAME"
58+
EXIT_STATUS=1
5859
fi
5960
6061
DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
6162
echo "Detected license type: $DETECTED_LICENSE_TYPE"
62-
if [ "$DETECTED_LICENSE_TYPE" != "\"$EXPECTED_LICENSE_TYPE\"" ]; then
63-
echo "ERROR: detected license type doesn't match expected $EXPECTED_LICENSE_TYPE"
64-
exit 1
63+
if [ "$DETECTED_LICENSE_TYPE" != "\"${EXPECTED_LICENSE_TYPE}\"" ]; then
64+
echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${EXPECTED_LICENSE_TYPE}\""
65+
EXIT_STATUS=1
6566
fi
67+
68+
exit $EXIT_STATUS

workflow-templates/check-license.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# "Check License" workflow
2+
3+
Workflow file: [check-license.yml](check-license.yml)
4+
5+
Check whether the repository's license file is recognizable by GitHub's [automated license detection system](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/licensing-a-repository#detecting-a-license) and whether it is recognized as the correct type. In order to be detected (and to ensure it remains a valid legal instrument), the license text must not be modified. GitHub supports multiple license filenames, so it's also possible that the license type could be inadvertently changed by the addition of a file to the repository.
6+
7+
Please always use the exact license text from the links at https://choosealicense.com/appendix/
8+
9+
## Readme badge
10+
11+
Markdown badge:
12+
13+
```markdown
14+
[![Check License status](https://github.com/REPO_OWNER/REPO_NAME/actions/workflows/check-license.yml/badge.svg)](https://github.com/REPO_OWNER/REPO_NAME/actions/workflows/check-license.yml)
15+
```
16+
17+
Replace the `REPO_OWNER` and `REPO_NAME` placeholders in the URLs with the final repository owner and name ([example](https://raw.githubusercontent.com/arduino-libraries/ArduinoIoTCloud/master/README.md)).
18+
19+
---
20+
21+
Asciidoc badge:
22+
23+
```adoc
24+
image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-license.yml/badge.svg["Check License status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-license.yml"]
25+
```
26+
27+
Define the `{repository-owner}` and `{repository-name}` attributes and use them throughout the readme ([example](https://raw.githubusercontent.com/arduino-libraries/WiFiNINA/master/README.adoc)).
28+
29+
## Commit message
30+
31+
```
32+
Add CI workflow to check the license file
33+
34+
Whenever one of the recognized license file names are modified in the repository, the workflow runs to check whether the
35+
license can be recognized and whether it is of the expected type.
36+
37+
GitHub has a useful automated license detection system that determines the license type used by a repository, and
38+
surfaces that information in the repository home page, the search web interface, and the GitHub API. This license
39+
detection system requires that the license be defined by a dedicated file with one of several standardized filenames and
40+
paths.
41+
42+
GitHub's license detection system uses the popular licensee tool, so this file also serves to define the license type
43+
for any other usages of licensee, as well as to human readers of the file.
44+
45+
For this reason, and to ensure it remains a valid legal instrument, it's important that there be no non-standard
46+
modifications to the license file or collisions with other supported licence files. This workflow ensures that any
47+
changes which would change the license type or which license file is used by the detection are caught automatically.
48+
```
49+
50+
## PR message
51+
52+
```markdown
53+
Whenever one of the recognized license file names are modified in the repository, the workflow runs [licensee](https://github.com/licensee/licensee) to check whether the license can be recognized and whether it is of the expected type.
54+
55+
GitHub has a useful [automated license detection system](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/licensing-a-repository#detecting-a-license) that determines the license type used by a repository, and surfaces that information in the repository home page, the search web interface, and the GitHub API. This license detection system requires that the license be defined by a dedicated file with one of several standardized filenames and paths.
56+
57+
GitHub's license detection system uses the popular licensee tool, so this file also serves to define the license type for any other usages of licensee, as well as to human readers of the file.
58+
59+
For this reason, and to ensure it remains a valid legal instrument, it's important that there be no non-standard modifications to the license file or collisions with other supported licence files. This workflow ensures that any changes which would change the license type or which license file is used by the detection are caught automatically.
60+
```

workflow-templates/check-license.yml

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

0 commit comments

Comments
 (0)