Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 14ca6ef

Browse files
committedAug 4, 2022
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 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 31207da commit 14ca6ef

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed
 

‎.github/workflows/check-license.yml

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

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![Check Taskfiles status](https://github.com/arduino/arduino-language-server/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/arduino-language-server/actions/workflows/check-taskfiles.yml)
66
[![Check Go status](https://github.com/arduino/arduino-language-server/actions/workflows/check-go-task.yml/badge.svg)](https://github.com/arduino/arduino-language-server/actions/workflows/check-go-task.yml)
77
[![Check Markdown status](https://github.com/arduino/arduino-language-server/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/arduino-language-server/actions/workflows/check-markdown-task.yml)
8+
[![Check License status](https://github.com/arduino/arduino-language-server/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/arduino-language-server/actions/workflows/check-license.yml)
89

910
The **Arduino Language Server** is the tool that powers the autocompletion of the new [Arduino IDE 2][arduino-ide-repo]. It implements the standard [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) so it can be used with other IDEs as well.
1011

0 commit comments

Comments
 (0)
Please sign in to comment.