From 5c30aff337e22c1a47a69c2d1fb916e5c7b183a6 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 20:35:16 -0700 Subject: [PATCH 01/11] Use standardized job name for "Check License" workflow This is the naming convention established in the standardized template workflow. Even though it was never realized, the original idea was for the scope of this workflow to be for linting of the repository's documentation files. However, that approach leads to inefficient workflow trigger path filters. The better approach is to scope workflows to a file type. So it is more appropriate to scope the workflow to any checks specific to the license, and the workflow name should reflect that purpose. --- .github/workflows/lint-documentation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-documentation.yml b/.github/workflows/lint-documentation.yml index 52de4894..651dc3fb 100644 --- a/.github/workflows/lint-documentation.yml +++ b/.github/workflows/lint-documentation.yml @@ -1,4 +1,4 @@ -name: Lint documentation files +name: Check License on: push: From 8209fd5196358db9b20bc4ba673faeafaf672e84 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 20:39:00 -0700 Subject: [PATCH 02/11] Use standardized filename for "Check License" workflow This is the template workflow filename, which is intended to serve as a unique identifier, and thus should be used by all deployments of the template. --- .../workflows/{lint-documentation.yml => check-license.yml} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{lint-documentation.yml => check-license.yml} (91%) diff --git a/.github/workflows/lint-documentation.yml b/.github/workflows/check-license.yml similarity index 91% rename from .github/workflows/lint-documentation.yml rename to .github/workflows/check-license.yml index 651dc3fb..d12d01ca 100644 --- a/.github/workflows/lint-documentation.yml +++ b/.github/workflows/check-license.yml @@ -3,7 +3,7 @@ name: Check License on: push: paths: - - ".github/workflows/lint-documentation.yml" + - ".github/workflows/check-license.ya?ml" - "Taskfile.yml" # Recognized license files. See: https://github.com/licensee/licensee/blob/master/docs/what-we-look-at.md#detecting-the-license-file - "COPYING*" @@ -11,7 +11,7 @@ on: - "LICENSE*" pull_request: paths: - - ".github/workflows/lint-documentation.yml" + - ".github/workflows/check-license.ya?ml" - "Taskfile.yml" - "COPYING*" - "LICENCE*" From 735768c442cf1c9ae9fab8cde28c9019da7589f9 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 20:49:36 -0700 Subject: [PATCH 03/11] Don't use Task for license check Task provides a convenient way to run common development processes locally with a single command. But I don't think the need to check the license file is common, nor something anyone would bother running. Instead, it's something that can be added to the repository and forgotten until the day comes that someone mucks around with the license file. That person likely would not have been aware of the existence of the task. --- .github/workflows/check-license.yml | 31 ++++++++++++++++++++--------- Taskfile.yml | 29 --------------------------- 2 files changed, 22 insertions(+), 38 deletions(-) diff --git a/.github/workflows/check-license.yml b/.github/workflows/check-license.yml index d12d01ca..52d1136d 100644 --- a/.github/workflows/check-license.yml +++ b/.github/workflows/check-license.yml @@ -1,10 +1,14 @@ name: Check License +env: + EXPECTED_LICENSE_FILENAME: LICENSE.txt + # SPDX identifier: https://spdx.org/licenses/ + EXPECTED_LICENSE_TYPE: GPL-3.0 + on: push: paths: - ".github/workflows/check-license.ya?ml" - - "Taskfile.yml" # Recognized license files. See: https://github.com/licensee/licensee/blob/master/docs/what-we-look-at.md#detecting-the-license-file - "COPYING*" - "LICENCE*" @@ -12,7 +16,6 @@ on: pull_request: paths: - ".github/workflows/check-license.ya?ml" - - "Taskfile.yml" - "COPYING*" - "LICENCE*" - "LICENSE*" @@ -25,12 +28,6 @@ jobs: - name: Checkout local repository uses: actions/checkout@v2 - - name: Install Taskfile - uses: arduino/setup-task@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - version: 3.x - - uses: ruby/setup-ruby@v1 with: ruby-version: ruby # Install latest version @@ -40,4 +37,20 @@ jobs: # See: https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/licensing-a-repository - name: Check license file - run: task --silent docs:check-license + 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 diff --git a/Taskfile.yml b/Taskfile.yml index 07a8ae50..0329f82d 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -224,35 +224,6 @@ tasks: - task: markdown:fix - task: markdown:check-links - docs:lint: - desc: Lint documentation files - cmds: - - task: docs:check-license - - docs:check-license: - desc: Check if the license file is correctly formatted - cmds: - - | - EXPECTED_LICENSE_FILE="\"LICENSE.txt\"" - EXPECTED_LICENSE_TYPE="\"GPL-3.0\"" # https://spdx.org/licenses/ - - # 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_FILE" ]; then - echo "ERROR: detected license file doesn't match expected: $EXPECTED_LICENSE_FILE" - 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 - # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-shell-task/Taskfile.yml shell:check: desc: Check for problems with shell scripts From ab724e05e92634e621d456fa7b9220bf58915663 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 20:53:46 -0700 Subject: [PATCH 04/11] Make "Check License" workflow's path triggers case insensitive The license detection system is case insensitive, so the workflow should be also. --- .github/workflows/check-license.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/check-license.yml b/.github/workflows/check-license.yml index 52d1136d..840023b0 100644 --- a/.github/workflows/check-license.yml +++ b/.github/workflows/check-license.yml @@ -9,16 +9,16 @@ on: push: paths: - ".github/workflows/check-license.ya?ml" - # Recognized license files. See: https://github.com/licensee/licensee/blob/master/docs/what-we-look-at.md#detecting-the-license-file - - "COPYING*" - - "LICENCE*" - - "LICENSE*" + # 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]*" pull_request: paths: - ".github/workflows/check-license.ya?ml" - - "COPYING*" - - "LICENCE*" - - "LICENSE*" + - "[cC][oO][pP][yY][iI][nN][gG]*" + - "[cC][oO][pP][yY][rR][iI][gG][hH][tH]*" + - "[lL][iI][cC][eE][nN][cCsS][eE]*" jobs: check-license: From a6ef28a5bfdf885ee855f590ff0c052d21d789c5 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 20:55:35 -0700 Subject: [PATCH 05/11] Add all recognized license file names to "Check License" workflow path trigger These have lower priority, but they are recognized and so should be covered in order for the check to be completely comprehensive. --- .github/workflows/check-license.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/check-license.yml b/.github/workflows/check-license.yml index 840023b0..d9964626 100644 --- a/.github/workflows/check-license.yml +++ b/.github/workflows/check-license.yml @@ -13,12 +13,16 @@ on: - "[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.ya?ml" - "[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]*" jobs: check-license: From f5aa02dc4274d764ccf906b51e36947cce717a09 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 20:57:43 -0700 Subject: [PATCH 06/11] Add manual events as "Check License" workflow triggers The `workflow_dispatch` event allows triggering the workflow via the GitHub web interface. This makes it easy to trigger an immediate workflow run after some relevant external change. The `repository_dispatch` event allows triggering workflows via the GitHub API. This might be useful for triggering an immediate check in multiple relevant repositories after an external change, or some automated process. Although we don't have any specific need for this event at the moment, the event has no impact on the workflow, so there is no reason against having it. It is the sort of thing that can end up being useful if it is already in consistently in place, but not worth setting up on demand, since the effort to set it up is greater than the effort to trigger all the workflows manually. --- .github/workflows/check-license.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/check-license.yml b/.github/workflows/check-license.yml index d9964626..4b8f6886 100644 --- a/.github/workflows/check-license.yml +++ b/.github/workflows/check-license.yml @@ -5,6 +5,7 @@ env: # 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: @@ -23,6 +24,8 @@ on: - "[lL][iI][cC][eE][nN][cCsS][eE]*" - "[oO][fF][lL]*" - "[pP][aA][tT][eE][nN][tT][sS]*" + workflow_dispatch: + repository_dispatch: jobs: check-license: From fe1f5286ed6dd1cb01912529bcc0030ea1058bd5 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 20:59:50 -0700 Subject: [PATCH 07/11] Use standardized job/step names in "Check License" workflow These are the naming conventions established in the standardized template workflow. --- .github/workflows/check-license.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-license.yml b/.github/workflows/check-license.yml index 4b8f6886..d3c70512 100644 --- a/.github/workflows/check-license.yml +++ b/.github/workflows/check-license.yml @@ -32,10 +32,11 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout local repository + - name: Checkout repository uses: actions/checkout@v2 - - uses: ruby/setup-ruby@v1 + - name: Install Ruby + uses: ruby/setup-ruby@v1 with: ruby-version: ruby # Install latest version From 62cc059cc25162f9a94e06d2a5874b3541e2ae63 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 21:03:50 -0700 Subject: [PATCH 08/11] Always check both license filename and type in "Check License" workflow This might provide some additional useful information to the reader in the event of a failure. --- .github/workflows/check-license.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-license.yml b/.github/workflows/check-license.yml index d3c70512..eb958274 100644 --- a/.github/workflows/check-license.yml +++ b/.github/workflows/check-license.yml @@ -46,6 +46,7 @@ jobs: # See: https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/licensing-a-repository - name: Check license file run: | + EXIT_STATUS=0 # See: https://github.com/licensee/licensee LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)" @@ -53,12 +54,14 @@ jobs: 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 + EXIT_STATUS=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 + EXIT_STATUS=1 fi + + exit $EXIT_STATUS From f0afd3e39f367174fe7c4c1ac8c5365b049599e3 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 21:05:17 -0700 Subject: [PATCH 09/11] Enhance "Check License" workflow's error output The use of the `error` workflow command will cause the important error message output to be surfaced prominently in the workflow run summary and log. The workflow run logs can be somewhat labyrinthine to those who don't work with them regularly, so finding the previous output to determine what caused the failure might have been challenging. --- .github/workflows/check-license.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-license.yml b/.github/workflows/check-license.yml index eb958274..597ebfbb 100644 --- a/.github/workflows/check-license.yml +++ b/.github/workflows/check-license.yml @@ -53,14 +53,14 @@ jobs: 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" + echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: $EXPECTED_LICENSE_FILENAME" EXIT_STATUS=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" + echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${EXPECTED_LICENSE_TYPE}\"" EXIT_STATUS=1 fi From 1f0b3046b0784a93d9ce33d441bf30b221c9b00b Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 21:09:06 -0700 Subject: [PATCH 10/11] Remove reference comment from "Check License" workflow Although very useful information, it doesn't apply directly to the licensee commands being run in this workflow step, and thus might be confusing. --- .github/workflows/check-license.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/check-license.yml b/.github/workflows/check-license.yml index 597ebfbb..34111892 100644 --- a/.github/workflows/check-license.yml +++ b/.github/workflows/check-license.yml @@ -43,7 +43,6 @@ jobs: - name: Install licensee run: gem install licensee - # See: https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/licensing-a-repository - name: Check license file run: | EXIT_STATUS=0 From 2ba684452f029dcabc27b83c8f31b3395b629d39 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 1 Aug 2021 21:10:26 -0700 Subject: [PATCH 11/11] Add source URL comment to "Check License" workflow This will make it easier for the maintainers to sync fixes and improvements in either direction between the upstream "template" workflow and its installation in this repository. --- .github/workflows/check-license.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/check-license.yml b/.github/workflows/check-license.yml index 34111892..d93c4d7c 100644 --- a/.github/workflows/check-license.yml +++ b/.github/workflows/check-license.yml @@ -1,3 +1,4 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-license.md name: Check License env: