Skip to content

Fix license headers #21

Fix license headers

Fix license headers #21

Workflow file for this run

name: Check SPDX Licenses
on:
workflow_dispatch:
workflow_call:
pull_request:
branches:
- "main"
types:
- opened
- reopened
- synchronize
- assigned
- review_requested
jobs:
check-spdx-licenses:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
cache: "pip"
python-version: "3.8"
- name: Install check-copyright
run: pip install git+https://github.com/espressif/check-copyright.git@master
- name: Check SPDX licenses
id: check_spdx_licenses
run: |
set +e
output=$(python -m check_copyright --verbose --dry-run --config ./check_copyright_config.yaml . 2>&1)
exit_code=$?
clean_output=$(echo "$output" | sed 's/\x1b\[[0-9;]*m//g')
echo "$clean_output"
echo "clean_output<<EOF" >> $GITHUB_ENV
echo "$clean_output" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "exit_code=$exit_code" >> $GITHUB_ENV
exit 0
- name: Add PR comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const output = process.env.clean_output;
const failedFilesRegex = /Files which failed the copyright check:[\s\S]*?Additional information about this hook and copyright headers may be found here:/;
const failedFilesMatch = output.match(failedFilesRegex);
if (failedFilesMatch) {
const failedFiles = failedFilesMatch[0]
.replace('Files which failed the copyright check:', '')
.replace('Additional information about this hook and copyright headers may be found here:', '')
.replace(/Some files are without a copyright note and a license header needs to be added:/, '')
.trim()
.split('\n')
.map(file => file.trim())
.filter(file => file !== '');
const filesToComment = failedFiles.join('\n');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `The following files are not compliant with the required licensing standards :\n\`\`\`\n${filesToComment}\n\`\`\` \nPlease update the license header within them. Your attention and cooperation in this matter are greatly appreciated.\nThank you.`
});
}
if (process.env.exit_code != 0) {
core.setFailed(`Check SPDX licenses failed with exit code ${process.env.exit_code}`);
}