diff --git a/.github/workflows/check-license.yml b/.github/workflows/check-license.yml new file mode 100644 index 000000000..d93c4d7cd --- /dev/null +++ b/.github/workflows/check-license.yml @@ -0,0 +1,67 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-license.md +name: Check License + +env: + EXPECTED_LICENSE_FILENAME: LICENSE.txt + # 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.ya?ml" + # 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.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]*" + 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: | + EXIT_STATUS=0 + # 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 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 file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${EXPECTED_LICENSE_TYPE}\"" + EXIT_STATUS=1 + fi + + exit $EXIT_STATUS diff --git a/.github/workflows/lint-documentation.yml b/.github/workflows/lint-documentation.yml deleted file mode 100644 index 52de4894d..000000000 --- a/.github/workflows/lint-documentation.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Lint documentation files - -on: - push: - paths: - - ".github/workflows/lint-documentation.yml" - - "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*" - - "LICENSE*" - pull_request: - paths: - - ".github/workflows/lint-documentation.yml" - - "Taskfile.yml" - - "COPYING*" - - "LICENCE*" - - "LICENSE*" - -jobs: - check-license: - runs-on: ubuntu-latest - - steps: - - 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 - - - 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: task --silent docs:check-license diff --git a/Taskfile.yml b/Taskfile.yml index 07a8ae50a..0329f82d6 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