11# Copyright 2024-2025 New Vector Ltd
2+ # Copyright 2025 Element Creations Ltd
23#
34# SPDX-License-Identifier: AGPL-3.0-only
45
5- name : Licensing checks
6+ name : Licensing & Copyright checks
67
78on :
89 pull_request :
@@ -15,11 +16,13 @@ permissions:
1516 contents : read
1617
1718jobs :
18- reuse-compliance-check :
19+ reuse-licensing-and-copyright-checks :
1920 runs-on : ubuntu-latest
2021 steps :
2122 - name : Checkout
2223 uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
24+ with :
25+ fetch-depth : 0
2326
2427 - uses : matrix-org/setup-python-poetry@5bbf6603c5c930615ec8a29f1b5d7d258d905aa4 # v2
2528 with :
@@ -35,63 +38,25 @@ jobs:
3538 reuse --version
3639 reuse lint
3740
38- - name : SPDX checks
41+ - name : Generate SPDX
3942 run : |
4043 git config --global --add safe.directory "$GITHUB_WORKSPACE"
4144 reuse --version
42- reuse spdx | ./scripts/spdx_checks.py
45+ reuse spdx > "$RUNNER_TEMP/reuse.spdx"
4346
44- copyright-dates :
45- runs-on : ubuntu-latest
46- steps :
47- - name : Checkout
48- uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
49- with :
50- fetch-depth : 0
47+ - name : SPDX checks
48+ run : |
49+ ./scripts/spdx_check_all_files.py "$RUNNER_TEMP/reuse.spdx"
5150
52- # REUSE-IgnoreStart
5351 - name : Copyright dates
5452 env :
5553 BASE_REF : ${{ github.event.pull_request.base.sha }}
5654 HEAD_REF : ${{ github.event.pull_request.head.sha }}
5755 run : |
5856 echo "Comparing $BASE_REF against current branch HEAD $(git rev-parse "$HEAD_REF")"
59- error_flag="false"
6057
6158 # Get the list of changed files
6259 changed_files=$(git diff --diff-filter=rd --name-only "$BASE_REF...$HEAD_REF")
63- copyright_year_now=$(date +%Y)
64- # Function to check if the copyright header is present in the file
65- # We ignore files without copyrights as we only want to check if the copyright is correct
66- # The check-enterprise-licensing job will verify that all files are copyrighted
67- has_copyright_header() {
68- file="$1"
69- head -n 5 "$file" | grep -q "Copyright"
70- }
71- # Function to check if the copyright header is present with the correct date
72- check_copyright_header() {
73- file="$1"
74- head -n 5 "$file" | grep -qE "Copyright $2" "$file"
75- }
76-
7760 echo "Changed files to verify : $changed_files"
78- # Loop through each changed file
79- for file in $changed_files; do
80- if [ -e "$file" ]; then
81- if has_copyright_header "$file" && ! check_copyright_header "$file" "$copyright_year_now" && ! check_copyright_header "$file" "20[0-9]{2}-$copyright_year_now"; then
82- echo "Copyright header not found or incorrect in $file"
83- error_flag="true"
84- fi
85- else
86- echo "$file was removed"
87- fi
88- done
8961
90- if [ "$error_flag" = "true" ]; then
91- echo "errors happened"
92- exit 1
93- else
94- echo "no errors"
95- exit 0
96- fi
97- # REUSE-IgnoreEnd
62+ echo "$changed_files" | xargs ./scripts/spdx_check_changed_file.py "$RUNNER_TEMP/reuse.spdx"
0 commit comments