Skip to content

Commit 8c08fa9

Browse files
Add CI workflow to check the license file (#10)
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 license 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 a20ab99 commit 8c08fa9

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

.github/workflows/check-license.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-license.md
2+
name: Check License
3+
4+
env:
5+
EXPECTED_LICENSE_FILENAME: LICENSE.txt
6+
# SPDX identifier: https://spdx.org/licenses/
7+
EXPECTED_LICENSE_TYPE: AGPL-3.0
8+
9+
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
10+
on:
11+
create:
12+
push:
13+
paths:
14+
- ".github/workflows/check-license.ya?ml"
15+
# See: https://github.com/licensee/licensee/blob/master/docs/what-we-look-at.md#detecting-the-license-file
16+
- "[cC][oO][pP][yY][iI][nN][gG]*"
17+
- "[cC][oO][pP][yY][rR][iI][gG][hH][tH]*"
18+
- "[lL][iI][cC][eE][nN][cCsS][eE]*"
19+
- "[oO][fF][lL]*"
20+
- "[pP][aA][tT][eE][nN][tT][sS]*"
21+
pull_request:
22+
paths:
23+
- ".github/workflows/check-license.ya?ml"
24+
- "[cC][oO][pP][yY][iI][nN][gG]*"
25+
- "[cC][oO][pP][yY][rR][iI][gG][hH][tH]*"
26+
- "[lL][iI][cC][eE][nN][cCsS][eE]*"
27+
- "[oO][fF][lL]*"
28+
- "[pP][aA][tT][eE][nN][tT][sS]*"
29+
schedule:
30+
# Run periodically to catch breakage caused by external changes.
31+
- cron: "0 6 * * WED"
32+
workflow_dispatch:
33+
repository_dispatch:
34+
35+
jobs:
36+
run-determination:
37+
runs-on: ubuntu-latest
38+
permissions: {}
39+
outputs:
40+
result: ${{ steps.determination.outputs.result }}
41+
steps:
42+
- name: Determine if the rest of the workflow should run
43+
id: determination
44+
run: |
45+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
46+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
47+
if [[
48+
"${{ github.event_name }}" != "create" ||
49+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
50+
]]; then
51+
# Run the other jobs.
52+
RESULT="true"
53+
else
54+
# There is no need to run the other jobs.
55+
RESULT="false"
56+
fi
57+
58+
echo "result=$RESULT" >> $GITHUB_OUTPUT
59+
60+
check-license:
61+
needs: run-determination
62+
if: needs.run-determination.outputs.result == 'true'
63+
runs-on: ubuntu-latest
64+
permissions:
65+
contents: read
66+
67+
steps:
68+
- name: Checkout repository
69+
uses: actions/checkout@v3
70+
71+
- name: Install Ruby
72+
uses: ruby/setup-ruby@v1
73+
with:
74+
ruby-version: ruby # Install latest version
75+
76+
- name: Install licensee
77+
run: gem install licensee
78+
79+
- name: Check license file
80+
run: |
81+
EXIT_STATUS=0
82+
# See: https://github.com/licensee/licensee
83+
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
84+
85+
DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
86+
echo "Detected license file: $DETECTED_LICENSE_FILE"
87+
if [ "$DETECTED_LICENSE_FILE" != "\"${EXPECTED_LICENSE_FILENAME}\"" ]; then
88+
echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: $EXPECTED_LICENSE_FILENAME"
89+
EXIT_STATUS=1
90+
fi
91+
92+
DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
93+
echo "Detected license type: $DETECTED_LICENSE_TYPE"
94+
if [ "$DETECTED_LICENSE_TYPE" != "\"${EXPECTED_LICENSE_TYPE}\"" ]; then
95+
echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${EXPECTED_LICENSE_TYPE}\""
96+
EXIT_STATUS=1
97+
fi
98+
99+
exit $EXIT_STATUS

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[![Sync Labels status](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/sync-labels.yml/badge.svg)](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/sync-labels.yml)
88
[![Test Go status](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/test-go-task.yml/badge.svg)](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/test-go-task.yml)
99
[![Check Markdown status](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-markdown-task.yml)
10+
[![Check License status](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-license.yml)
1011
[![Codecov](https://codecov.io/gh/arduino/uno-r4-wifi-fwuploader-plugin/branch/main/graph/badge.svg)](https://codecov.io/gh/arduino/uno-r4-wifi-fwuploader-plugin)
1112

1213
Be sure to have `libudev-dev` installed

0 commit comments

Comments
 (0)