Skip to content

Commit b8c5ece

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. 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 5327ff5 commit b8c5ece

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

Diff for: .github/workflows/check-license.yml

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
outputs:
39+
result: ${{ steps.determination.outputs.result }}
40+
steps:
41+
- name: Determine if the rest of the workflow should run
42+
id: determination
43+
run: |
44+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
45+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
46+
if [[
47+
"${{ github.event_name }}" != "create" ||
48+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
49+
]]; then
50+
# Run the other jobs.
51+
RESULT="true"
52+
else
53+
# There is no need to run the other jobs.
54+
RESULT="false"
55+
fi
56+
57+
echo "::set-output name=result::$RESULT"
58+
59+
check-license:
60+
needs: run-determination
61+
if: needs.run-determination.outputs.result == 'true'
62+
runs-on: ubuntu-latest
63+
64+
steps:
65+
- name: Checkout repository
66+
uses: actions/checkout@v3
67+
68+
- name: Install Ruby
69+
uses: ruby/setup-ruby@v1
70+
with:
71+
ruby-version: ruby # Install latest version
72+
73+
- name: Install licensee
74+
run: gem install licensee
75+
76+
- name: Check license file
77+
run: |
78+
EXIT_STATUS=0
79+
# See: https://github.com/licensee/licensee
80+
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
81+
82+
DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
83+
echo "Detected license file: $DETECTED_LICENSE_FILE"
84+
if [ "$DETECTED_LICENSE_FILE" != "\"${EXPECTED_LICENSE_FILENAME}\"" ]; then
85+
echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: $EXPECTED_LICENSE_FILENAME"
86+
EXIT_STATUS=1
87+
fi
88+
89+
DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
90+
echo "Detected license type: $DETECTED_LICENSE_TYPE"
91+
if [ "$DETECTED_LICENSE_TYPE" != "\"${EXPECTED_LICENSE_TYPE}\"" ]; then
92+
echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${EXPECTED_LICENSE_TYPE}\""
93+
EXIT_STATUS=1
94+
fi
95+
96+
exit $EXIT_STATUS

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
[![Test Go status](https://github.com/arduino/arduino-create-agent/actions/workflows/test-go-task.yml/badge.svg)](https://github.com/arduino/arduino-create-agent/actions/workflows/test-go-task.yml)
33
[![Codecov](https://codecov.io/gh/arduino/arduino-create-agent/branch/main/graph/badge.svg)](https://codecov.io/gh/arduino/arduino-create-agent)
44
[![Test Integration status](https://github.com/arduino/arduino-create-agent/actions/workflows/test-go-integration-task.yml/badge.svg)](https://github.com/arduino/arduino-create-agent/actions/workflows/test-go-integration-task.yml)
5+
[![Check License status](https://github.com/arduino/arduino-create-agent/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/arduino-create-agent/actions/workflows/check-license.yml)
56

67
arduino-create-agent
78
====================

0 commit comments

Comments
 (0)