Skip to content

Commit

Permalink
Add CI workflow to check the license file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
per1234 committed May 4, 2021
1 parent 85ad4dc commit 5faa6b6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/check-license.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Check License

env:
EXPECTED_LICENSE_FILENAME: LICENSE
# SPDX identifier: https://spdx.org/licenses/
EXPECTED_LICENSE_TYPE: GPL-3.0

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
push:
paths:
- ".github/workflows/check-license.yml"
# See: https://github.com/licensee/licensee/blob/master/docs/what-we-look-at.md#detecting-the-license-file
- "[cC][oO][pP][yY][iI][nN][gG]*"
- "[cC][oO][pP][yY][rR][iI][gG][hH][tH]*"
- "[lL][iI][cC][eE][nN][cCsS][eE]*"
- "[oO][fF][lL]*"
- "[pP][aA][tT][eE][nN][tT][sS]*"
pull_request:
paths:
- ".github/workflows/check-license.yml"
- "[cC][oO][pP][yY][iI][nN][gG]*"
- "[cC][oO][pP][yY][rR][iI][gG][hH][tH]*"
- "[lL][iI][cC][eE][nN][cCsS][eE]*"
- "[oO][fF][lL]*"
- "[pP][aA][tT][eE][nN][tT][sS]*"
workflow_dispatch:
repository_dispatch:

jobs:
check-license:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ruby # Install latest version

- name: Install licensee
run: gem install licensee

- name: Check license file
run: |
# See: https://github.com/licensee/licensee
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
echo "Detected license file: $DETECTED_LICENSE_FILE"
if [ "$DETECTED_LICENSE_FILE" != "\"$EXPECTED_LICENSE_FILENAME\"" ]; then
echo "ERROR: detected license file doesn't match expected: $EXPECTED_LICENSE_FILENAME"
exit 1
fi
DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
echo "Detected license type: $DETECTED_LICENSE_TYPE"
if [ "$DETECTED_LICENSE_TYPE" != "\"$EXPECTED_LICENSE_TYPE\"" ]; then
echo "ERROR: detected license type doesn't match expected $EXPECTED_LICENSE_TYPE"
exit 1
fi
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# setup-taskfile

[![Check License status](https://github.com/arduino/setup-taskfile/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/setup-taskfile/actions/workflows/check-license.yml)

This action makes the `task` binary available to Workflows.

## Usage
Expand Down

0 comments on commit 5faa6b6

Please sign in to comment.