-
Notifications
You must be signed in to change notification settings - Fork 14
100 lines (86 loc) · 5.08 KB
/
check_license_header.yaml
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#
# Distributed Linear Algebra with Future (DLAF)
#
# Copyright (c) 2018-2023, ETH Zurich
# All rights reserved.
#
# Please, refer to the LICENSE file in the root directory.
# SPDX-License-Identifier: BSD-3-Clause
#
name: Check license
on: [pull_request]
jobs:
check-licenses:
runs-on: ubuntu-22.04
steps:
- uses: actions/javascript-action@v1
- uses: actions/checkout@v3
- name: Check file extensions
if: always() # needed so that it runs even if previous one fails
run: |
# Highlight if in these folders there are files with other extensions.
# Hidden files are excluded from the check.
find src include test miniapp ! -path 'miniapp/cmake/*' -type f \
! '(' \
-name '*.cpp' \
-o -name '*.h' \
-o -name '*.h.in' \
-o -name '*.tpp' \
-o -name '*.cu' \
-o -name '*.c' \
-o -name 'CMakeLists.txt' \
-o -name '.*' \
')' \
> result-extension.check
# Generate an error message for each file with an unkown extension
for filepath in `cat result-extension.check`; do \
echo "::error file=$filepath,line=1::check extension of $filepath"; \
done
test ! -s result-extension.check
- name: Check license in source code
if: always() # needed so that it runs even if previous one fails
run: |
# Compare first lines of each source file with reference in misc/HEADER
find src include test miniapp -type f \
'(' \
-name '*.cpp' \
-o -name '*.h' \
-o -name '*.h.in' \
-o -name '*.tpp' \
-o -name '*.cu' \
-o -name '*.c' \
')' \
| xargs -I{} sh -c \
".github/check_license.sh misc/HEADER {} > /dev/null || echo {}" \
> result-cpp.check
# Generate an error message for each offending file
for filepath in `cat result-cpp.check`; do \
echo "::error file=$filepath,line=1::check the license in $filepath"; \
done
test ! -s result-cpp.check
- name: Check license in files using "#" comments
if: always() # needed so that it runs even if previous one fails
run: |
# Generate header license CMake/Python compliant (with hashes)
sed 's|^//|#|g' misc/HEADER > HEADER_HASH
# Check license in files that should have the license at the very beginning
find '(' -type f ! -path './misc*' ')' \
'(' \
-name 'CMakeLists.txt' \
-o -name '*.cmake' \
-o -name '*.cmake.in' \
-o -name '*.yaml' \
')' \
| xargs -I{} sh -c \
".github/check_license.sh HEADER_HASH {} > /dev/null || echo {}" \
>> result.check
# Check license in scripts which may start with #! shebang and other directives
find -type f '(' -name '*.py' -o -name '*.sh' ')' \
| xargs -I{} sh -c \
".github/check_license.sh -r 4 HEADER_HASH {} > /dev/null || echo {}" \
>> result.check
# Generate an error message for each offending file
for filepath in `cat result.check`; do \
echo "::error file=$filepath,line=1::check the license in $filepath"; \
done
test ! -s result.check