@@ -11,6 +11,29 @@ set -o pipefail
11
11
ROOT=" $( realpath " $( dirname " $0 " ) " /../) "
12
12
GITHUB_STEP_SUMMARY=${GITHUB_STEP_SUMMARY:-/ dev/ stdout}
13
13
14
+ # Check if we're in GitHub context
15
+ IN_GITHUB_CONTEXT=false
16
+ if [[ $GITHUB_STEP_SUMMARY != " /dev/stdout" ]]; then
17
+ IN_GITHUB_CONTEXT=true
18
+ fi
19
+
20
+ # Standard color definitions
21
+ GREEN=" \033[32m"
22
+ RED=" \033[31m"
23
+ BLUE=" \033[94m"
24
+ BOLD=" \033[1m"
25
+ NORMAL=" \033[0m"
26
+
27
+ info ()
28
+ {
29
+ printf " %b %b\n" " ${GREEN} ✓" " ${NORMAL}${* } "
30
+ }
31
+
32
+ error ()
33
+ {
34
+ printf " %b %b\n" " ${RED} ✗" " ${NORMAL}${* } "
35
+ }
36
+
14
37
checkerr ()
15
38
{
16
39
local code=$?
@@ -22,44 +45,92 @@ checkerr()
22
45
fi
23
46
24
47
if [[ ${# out} != 0 ]]; then
25
- echo " $out " | while read -r file line; do
26
- echo " ::error file=$file ,line=${line:- 1} ,title=Format error::$file require to be formatted"
27
- done
48
+ if $IN_GITHUB_CONTEXT ; then
49
+ echo " $out " | while read -r file line; do
50
+ echo " ::error file=$file ,line=${line:- 1} ,title=Format error::$file require to be formatted"
51
+ done
52
+ fi
28
53
success=false
29
54
fi
30
55
31
56
if $success ; then
32
- echo " :white_check_mark: $title " >> " $GITHUB_STEP_SUMMARY "
57
+ info " $title "
58
+ gh_summary_success " $title "
33
59
else
60
+ error " $title "
34
61
SUCCESS=false
35
- echo " :x: $title " >> " $GITHUB_STEP_SUMMARY "
62
+ gh_summary_failure " $title "
63
+ fi
64
+ }
65
+
66
+ gh_group_start ()
67
+ {
68
+ if $IN_GITHUB_CONTEXT ; then
69
+ echo " ::group::$1 "
70
+ fi
71
+ }
72
+
73
+ gh_group_end ()
74
+ {
75
+ if $IN_GITHUB_CONTEXT ; then
76
+ echo " ::endgroup::"
77
+ fi
78
+ }
79
+
80
+ gh_summary_success ()
81
+ {
82
+ if $IN_GITHUB_CONTEXT ; then
83
+ echo " :white_check_mark: $1 " >> " $GITHUB_STEP_SUMMARY "
84
+ fi
85
+ }
86
+
87
+ gh_summary_failure ()
88
+ {
89
+ if $IN_GITHUB_CONTEXT ; then
90
+ echo " :x: $1 " >> " $GITHUB_STEP_SUMMARY "
91
+ fi
92
+ }
93
+
94
+ gh_error ()
95
+ {
96
+ if $IN_GITHUB_CONTEXT ; then
97
+ echo " ::error file=$1 ,line=${2:- 1} ,title=$3 ::$4 "
98
+ fi
99
+ }
100
+
101
+ gh_error_simple ()
102
+ {
103
+ if $IN_GITHUB_CONTEXT ; then
104
+ echo " ::error title=$1 ::$2 "
36
105
fi
37
106
}
38
107
39
108
# Formatting
40
109
SUCCESS=true
41
110
42
- echo " ::group:: Linting nix files with nixpkgs-fmt"
111
+ gh_group_start " Linting nix files with nixpkgs-fmt"
43
112
checkerr " Lint nix" " $( nixpkgs-fmt --check " $ROOT " ) "
44
- echo " ::endgroup:: "
113
+ gh_group_end
45
114
46
- # echo "::group:: Linting shell scripts with shfmt"
47
- # checkerr "Lint shell" "$(shfmt -s -l -i 2 -ci -fn $(shfmt -f $(git grep -l '' :/)))"
48
- # echo "::endgroup::"
115
+ gh_group_start " Linting shell scripts with shfmt"
116
+ checkerr " Lint shell" " $( shfmt -s -l -i 2 -ci -fn $( shfmt -f $( git grep -l ' ' :/) ) ) "
117
+ gh_group_end
49
118
50
- echo " ::group:: Linting python scripts with black"
119
+ gh_group_start " Linting python scripts with black"
51
120
if ! diff=$( black --check --diff -q --include " (scripts/tests|scripts/simpasm|scripts/autogen|scripts/check-namespace|\.py$)" " $ROOT " ) ; then
52
- echo " ::error title=Format error::$diff "
121
+ gh_error_simple " Format error" " $diff "
122
+ error " Lint python"
53
123
SUCCESS=false
54
- echo " :x: Lint python" >> " $GITHUB_STEP_SUMMARY "
124
+ gh_summary_failure " Lint python"
55
125
else
56
- echo " :white_check_mark: Lint Python" >> " $GITHUB_STEP_SUMMARY "
126
+ info " Lint Python"
127
+ gh_summary_success " Lint Python"
57
128
fi
58
- echo " ::endgroup:: "
129
+ gh_group_end
59
130
60
- echo " ::group:: Linting c files with clang-format"
131
+ gh_group_start " Linting c files with clang-format"
61
132
checkerr " Lint C" " $( clang-format $( git ls-files " :/*.c" " :/*.h" ) --Werror --dry-run 2>&1 | grep " error:" | cut -d ' :' -f 1,2 | tr ' :' ' ' ) "
62
- echo " ::endgroup:: "
133
+ gh_group_end
63
134
64
135
check-eol-dry-run ()
65
136
{
@@ -71,52 +142,64 @@ check-eol-dry-run()
71
142
fi
72
143
done
73
144
}
74
- echo " ::group:: Checking eol"
145
+ gh_group_start " Checking eol"
75
146
checkerr " Check eol" " $( check-eol-dry-run) "
76
- echo " ::endgroup:: "
147
+ gh_group_end
77
148
78
149
check-spdx ()
79
150
{
80
151
local success=true
81
152
for file in $( git ls-files -- " :/" " :/!:*.json" " :/!:*.png" " :/!:*LICENSE*" " :/!:.git*" " :/!:flake.lock" ) ; do
82
153
# Ignore symlinks
83
154
if [[ ! -L $file && $( grep " SPDX-License-Identifier:" $file | wc -l) == 0 ]]; then
84
- echo " ::error file= $file ,line= ${line:- 1} ,title= Missing license header error:: $file is missing SPDX License header"
155
+ gh_error " $file " " ${line:- 1} " " Missing license header error" " $file is missing SPDX License header"
85
156
success=false
86
157
fi
87
158
done
88
159
for file in $( git ls-files -- " *.[chsS]" " *.py" " :/!proofs/cbmc/*.py" ) ; do
89
160
# Ignore symlinks
90
161
if [[ ! -L $file && $( grep " Copyright (c) The mldsa-native project authors" $file | wc -l) == 0 ]]; then
91
- echo " ::error file=$file ,line=${line:- 1} ,title=Missing copyright header error::$file is missing copyright header"
162
+ gh_error " $file " " ${line:- 1} " " Missing copyright header error" " $file is missing copyright header"
163
+ success=false
164
+ fi
165
+ done
166
+ # For source files in dev/* and mldsa/*, we enforce `Apache-2.0 OR ISC OR MIT`
167
+ for file in $( git ls-files -- " *.[chsSi]" | grep " ^dev/\|^mlkem/" ) ; do
168
+ # Ignore symlinks
169
+ if [[ ! -L $file && $( grep " SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT" $file | wc -l) == 0 ]]; then
170
+ gh_error " $file " " ${line:- 1} " " Missing license header error" " $file is not licensed under 'Apache-2.0 OR ISC OR MIT'"
92
171
success=false
93
172
fi
94
173
done
95
174
96
175
if $success ; then
97
- echo " :white_check_mark: Check SPDX + Copyright" >> " $GITHUB_STEP_SUMMARY "
176
+ info " Check SPDX + Copyright"
177
+ gh_summary_success " Check SPDX + Copyright"
98
178
else
179
+ error " Check SPDX + Copyright"
99
180
SUCCESS=false
100
- echo " :x: Check SPDX + Copyright" >> " $GITHUB_STEP_SUMMARY "
181
+ gh_summary_failure " Check SPDX + Copyright"
101
182
fi
102
183
}
103
- echo " ::group:: Checking SPDX + Copyright headers"
184
+ gh_group_start " Checking SPDX + Copyright headers"
104
185
check-spdx
105
- echo " ::endgroup:: "
186
+ gh_group_end
106
187
107
188
check-autogenerated-files ()
108
189
{
109
190
if python3 $ROOT /scripts/autogen --dry-run; then
110
- echo " :white_check_mark: Check native auto-generated files" >> " $GITHUB_STEP_SUMMARY "
191
+ info " Check native auto-generated files"
192
+ gh_summary_success " Check native auto-generated files"
111
193
else
112
- echo " :x: Check native auto-generated files" >> " $GITHUB_STEP_SUMMARY "
194
+ error " Check native auto-generated files"
195
+ gh_summary_failure " Check native auto-generated files"
113
196
SUCCESS=false
114
197
fi
115
198
}
116
199
117
- echo " ::group:: Check native auto-generated files"
200
+ gh_group_start " Check native auto-generated files"
118
201
check-autogenerated-files
119
- echo " ::endgroup:: "
202
+ gh_group_end
120
203
121
204
if ! $SUCCESS ; then
122
205
exit 1
0 commit comments