Skip to content

Commit 538747f

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 538747f

1 file changed

Lines changed: 48 additions & 1 deletion

File tree

.github/workflows/code-formatting.yml

Lines changed: 48 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,49 @@ 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+
114+
- name: Check copyright headers
115+
env:
116+
# The expected copyright notice.
117+
COPYRIGHT: |
118+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
119+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
120+
// All rights not expressly granted are reserved.
121+
//
122+
// This software is distributed under the terms of the GNU General Public
123+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
124+
//
125+
// In applying this license CERN does not waive the privileges and immunities
126+
// granted to it by virtue of its status as an Intergovernmental Organization
127+
// or submit itself to any jurisdiction.
128+
run: |
129+
# Run copyright notice check
130+
copyright_lines=$(echo "$COPYRIGHT" | wc -l)
131+
base_commit=$(git merge-base HEAD ${{ github.event.pull_request.base.sha }})
132+
have_err=
133+
git diff --diff-filter d --name-only "$base_commit" -- '*.cxx' '*.h' | while read -r file; do
134+
if [ "$(head -n "$copyright_lines" "$file")" != "$COPYRIGHT" ]; then
135+
echo "::error::$file: missing or malformed copyright notice" >&2
136+
have_err=1
137+
fi
138+
done
139+
140+
# Tell user what to do in case of copyright notice error
141+
if [ -n "$have_err" ]; then
142+
cat << EOF >&2
143+
::error::The files listed above are missing the correct copyright notice.
144+
::error::Make sure all your source files begin with the following exact lines:
145+
$COPYRIGHT
146+
EOF
147+
exit 1
148+
fi

0 commit comments

Comments
 (0)