-
Notifications
You must be signed in to change notification settings - Fork 17
67 lines (65 loc) · 2.7 KB
/
license-checker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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/setup-python@v5.0.0
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}`);
}