Skip to content

Commit 2cb3a84

Browse files
committed
Add template 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. GitHub has a useful automated license detection system 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. 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. 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.
1 parent 27e0b6a commit 2cb3a84

File tree

3 files changed

+192
-0
lines changed

3 files changed

+192
-0
lines changed

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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
# See: https://github.com/licensee/licensee
52+
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
53+
54+
DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
55+
echo "Detected license file: $DETECTED_LICENSE_FILE"
56+
if [ "$DETECTED_LICENSE_FILE" != "\"$EXPECTED_LICENSE_FILENAME\"" ]; then
57+
echo "ERROR: detected license file doesn't match expected: $EXPECTED_LICENSE_FILENAME"
58+
exit 1
59+
fi
60+
61+
DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
62+
echo "Detected license type: $DETECTED_LICENSE_TYPE"
63+
if [ "$DETECTED_LICENSE_TYPE" != "\"$EXPECTED_LICENSE_TYPE\"" ]; then
64+
echo "ERROR: detected license type doesn't match expected $EXPECTED_LICENSE_TYPE"
65+
exit 1
66+
fi
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
# See: https://github.com/licensee/licensee
52+
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
53+
54+
DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
55+
echo "Detected license file: $DETECTED_LICENSE_FILE"
56+
if [ "$DETECTED_LICENSE_FILE" != "\"$EXPECTED_LICENSE_FILENAME\"" ]; then
57+
echo "ERROR: detected license file doesn't match expected: $EXPECTED_LICENSE_FILENAME"
58+
exit 1
59+
fi
60+
61+
DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
62+
echo "Detected license type: $DETECTED_LICENSE_TYPE"
63+
if [ "$DETECTED_LICENSE_TYPE" != "\"$EXPECTED_LICENSE_TYPE\"" ]; then
64+
echo "ERROR: detected license type doesn't match expected $EXPECTED_LICENSE_TYPE"
65+
exit 1
66+
fi

0 commit comments

Comments
 (0)