Integration of SPDX License Compliance Checker workflows #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Validate SPDX License year in currently changed Python Files | |
on: | |
pull_request: | |
branches: [main] | |
types: | |
- opened | |
- reopened | |
- synchronize | |
- assigned | |
- review_requested | |
jobs: | |
check-spdx-license: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Identify changed Python files and check licenses | |
id: check-licenses | |
run: | | |
missing_license_files="" | |
for file in $(git diff --name-only HEAD^ HEAD | grep '\.py$'); do | |
if ! grep -L "SPDX-License-Identifier: Apache-2.0" "$file" | grep -q "2024"; then | |
missing_license_files="$missing_license_files$file\n" | |
fi | |
done | |
if [ -n "$missing_license_files" ]; then | |
echo "::set-output name=missing_files::${missing_license_files}" | |
else | |
echo "::set-output name=missing_files::" | |
fi | |
- name: Comment on PR about missing SPDX licenses | |
if: steps.check-licenses.outputs.missing_files != '' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const issueNumber = context.issue.number; | |
const owner = context.repo.owner; | |
const repo = context.repo.repo; | |
const missingFiles = `${{ steps.check-licenses.outputs.missing_files }}`; | |
const commentBody = `The following Python files are missing the correct SPDX license year or do not contain the '2024 year' within thier license header:\n\`\`\`\n${missingFiles}\`\`\`\nPlease update the files accordingly. Your attention and cooperation in this matter are greatly appreciated.\n Thank you.`; | |
github.rest.issues.createComment({ | |
issue_number: issueNumber, | |
owner: owner, | |
repo: repo, | |
body: commentBody | |
}); | |
- name: Fail the workflow | |
if: steps.check-licenses.outputs.missing_files != '' | |
run: | | |
echo "Failing the workflow due to non-compliance with SPDX license requirements." | |
exit 1 |