Skip to content

Add support to "Check License" for checking license files in multiple paths #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions .github/workflows/check-license.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# 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/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
on:
create:
Expand Down Expand Up @@ -58,12 +53,23 @@ jobs:
echo "result=$RESULT" >> $GITHUB_OUTPUT

check-license:
name: ${{ matrix.check-license.path }}
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
fail-fast: false

matrix:
check-license:
- path: ./
expected-filename: LICENSE.txt
# SPDX identifier: https://spdx.org/licenses/
expected-type: GPL-3.0

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -76,23 +82,27 @@ jobs:
- name: Install licensee
run: gem install licensee

- name: Check license file
- name: Check license file for ${{ matrix.check-license.path }}
run: |
EXIT_STATUS=0

# Go into folder path
cd ./${{ matrix.check-license.path }}

# 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"
if [ "$DETECTED_LICENSE_FILE" != "\"${{ matrix.check-license.expected-filename }}\"" ]; then
echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: ${{ matrix.check-license.expected-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}\""
if [ "$DETECTED_LICENSE_TYPE" != "\"${{ matrix.check-license.expected-type }}\"" ]; then
echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${{ matrix.check-license.expected-type }}\""
EXIT_STATUS=1
fi

Expand Down
Loading