Skip to content

Commit 81afcbc

Browse files
committed
Add check for copyright headers
It runs in parallel with the clang-format check, and makes sure the copyright notice of any changed .cxx or .h files is OK.
1 parent 71e9dc2 commit 81afcbc

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

.github/workflows/code-formatting.yml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
name: Check PR with clang-format
1+
name: PR formatting
22

33
on: [pull_request_target]
44

55
jobs:
66
clang-format:
7+
name: clang-format
78
# We need at least 20.04 to install clang-format-11.
89
runs-on: ubuntu-20.04
910

@@ -99,3 +100,53 @@ jobs:
99100
true) echo 'PR clean' ; exit 0 ;;
100101
false) echo 'PR not clean' ; exit 1 ;;
101102
esac
103+
104+
copyright:
105+
name: copyright headers
106+
runs-on: ubuntu-latest
107+
108+
steps:
109+
- uses: actions/checkout@v2
110+
with:
111+
ref: ${{ github.event.pull_request.head.sha }}
112+
persist-credentials: false
113+
# We need the history of the dev branch all the way back to where the PR
114+
# diverged. We're fetching everything here, as we don't know how many
115+
# commits back that point is.
116+
fetch-depth: 0
117+
118+
- name: Check copyright headers
119+
env:
120+
# The expected copyright notice.
121+
COPYRIGHT: |
122+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
123+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
124+
// All rights not expressly granted are reserved.
125+
//
126+
// This software is distributed under the terms of the GNU General Public
127+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
128+
//
129+
// In applying this license CERN does not waive the privileges and immunities
130+
// granted to it by virtue of its status as an Intergovernmental Organization
131+
// or submit itself to any jurisdiction.
132+
run: |
133+
# Run copyright notice check
134+
copyright_lines=$(echo "$COPYRIGHT" | wc -l)
135+
base_commit=$(git merge-base HEAD ${{ github.event.pull_request.base.sha }})
136+
have_err=
137+
git diff --diff-filter d --name-only "$base_commit" -- '*.cxx' '*.h' | while read -r file; do
138+
if [ "$(head -n "$copyright_lines" "$file")" != "$COPYRIGHT" ]; then
139+
echo "::error::$file: missing or malformed copyright notice" >&2
140+
have_err=1
141+
fi
142+
done
143+
144+
# Tell user what to do in case of copyright notice error
145+
if [ -n "$have_err" ]; then
146+
cat << EOF >&2
147+
::error::The files listed above are missing the correct copyright notice.
148+
::error::Make sure all your source files begin with the following exact lines:
149+
$COPYRIGHT
150+
EOF
151+
exit 1
152+
fi

0 commit comments

Comments
 (0)