| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | # Copyright (c) The mldsa-native project authors |
| 3 | # SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT |
| 4 | |
| 5 | set -o errexit |
| 6 | set -o errtrace |
| 7 | set -o nounset |
| 8 | set -o pipefail |
| 9 | |
| 10 | # consts |
| 11 | ROOT="$(realpathscip-shell system . . realpath. "$(dirnamescip-shell system . . dirname. "$0")"/../)" |
| 12 | GITHUB_STEP_SUMMARY=${GITHUB_STEP_SUMMARY:-/dev/stdout} |
| 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 | infoscip-shell shell shell-project 0.0.0 info().() |
| 28 | { |
| 29 | printfscip-shell system . . printf. "%b %b\n" "${GREEN}✓" "${NORMAL}${*}" |
| 30 | } |
| 31 | |
| 32 | errorscip-shell shell shell-project 0.0.0 error().() |
| 33 | { |
| 34 | printfscip-shell system . . printf. "%b %b\n" "${RED}✗" "${NORMAL}${*}" |
| 35 | } |
| 36 | |
| 37 | checkerrscip-shell shell shell-project 0.0.0 checkerr().() |
| 38 | { |
| 39 | local code=$? |
| 40 | local title="$1" |
| 41 | local out="$2" |
| 42 | local success=true |
| 43 | if [[ $code == 127 ]]; then |
| 44 | success=false |
| 45 | fi |
| 46 | |
| 47 | if [[ ${#out} != 0 ]]; then |
| 48 | if $IN_GITHUB_CONTEXT; then |
| 49 | echoscip-shell system . . echo. "$out" | while read -r file line; do |
| 50 | echoscip-shell system . . echo. "::error file=$file,line=${line:-1},title=Format error::$file require to be formatted" |
| 51 | done |
| 52 | fi |
| 53 | success=false |
| 54 | fi |
| 55 | |
| 56 | if $success; then |
| 57 | infoscip-shell shell shell-project 0.0.0 info(). "$title" |
| 58 | gh_summary_successscip-shell shell shell-project 0.0.0 gh_summary_success(). "$title" |
| 59 | else |
| 60 | errorscip-shell shell shell-project 0.0.0 error(). "$title" |
| 61 | SUCCESS=false |
| 62 | gh_summary_failurescip-shell shell shell-project 0.0.0 gh_summary_failure(). "$title" |
| 63 | fi |
| 64 | } |
| 65 | |
| 66 | gh_group_startscip-shell shell shell-project 0.0.0 gh_group_start().() |
| 67 | { |
| 68 | if $IN_GITHUB_CONTEXT; then |
| 69 | echoscip-shell system . . echo. "::group::$1" |
| 70 | fi |
| 71 | } |
| 72 | |
| 73 | gh_group_endscip-shell shell shell-project 0.0.0 gh_group_end().() |
| 74 | { |
| 75 | if $IN_GITHUB_CONTEXT; then |
| 76 | echoscip-shell system . . echo. "::endgroup::" |
| 77 | fi |
| 78 | } |
| 79 | |
| 80 | gh_summary_successscip-shell shell shell-project 0.0.0 gh_summary_success().() |
| 81 | { |
| 82 | if $IN_GITHUB_CONTEXT; then |
| 83 | echoscip-shell system . . echo. ":white_check_mark: $1" >>"$GITHUB_STEP_SUMMARY" |
| 84 | fi |
| 85 | } |
| 86 | |
| 87 | gh_summary_failurescip-shell shell shell-project 0.0.0 gh_summary_failure().() |
| 88 | { |
| 89 | if $IN_GITHUB_CONTEXT; then |
| 90 | echoscip-shell system . . echo. ":x: $1" >>"$GITHUB_STEP_SUMMARY" |
| 91 | fi |
| 92 | } |
| 93 | |
| 94 | gh_errorscip-shell shell shell-project 0.0.0 gh_error().() |
| 95 | { |
| 96 | errorscip-shell shell shell-project 0.0.0 error(). "$4" |
| 97 | if $IN_GITHUB_CONTEXT; then |
| 98 | echoscip-shell system . . echo. "::error file=$1,line=${2:-1},title=$3::$4" |
| 99 | fi |
| 100 | } |
| 101 | |
| 102 | gh_error_simplescip-shell shell shell-project 0.0.0 gh_error_simple().() |
| 103 | { |
| 104 | if $IN_GITHUB_CONTEXT; then |
| 105 | echoscip-shell system . . echo. "::error title=$1::$2" |
| 106 | fi |
| 107 | } |
| 108 | |
| 109 | # Formatting |
| 110 | SUCCESS=true |
| 111 | |
| 112 | gh_group_startscip-shell shell shell-project 0.0.0 gh_group_start(). "Linting nix files with nixpkgs-fmt" |
| 113 | checkerrscip-shell shell shell-project 0.0.0 checkerr(). "Lint nix" "$(nixpkgs-fmt --check "$ROOT")" |
| 114 | gh_group_endscip-shell shell shell-project 0.0.0 gh_group_end(). |
| 115 | |
| 116 | gh_group_startscip-shell shell shell-project 0.0.0 gh_group_start(). "Linting shell scripts with shfmt" |
| 117 | checkerrscip-shell shell shell-project 0.0.0 checkerr(). "Lint shell" "$(shfmt -s -l -i 2 -ci -fn $(shfmt -f $(gitscip-shell system . . git. grep -l '' :/)))" |
| 118 | gh_group_endscip-shell shell shell-project 0.0.0 gh_group_end(). |
| 119 | |
| 120 | gh_group_startscip-shell shell shell-project 0.0.0 gh_group_start(). "Linting python scripts with black" |
| 121 | if ! diff=$(black --check --diff -q --include "(scripts/tests|scripts/simpasm|scripts/cfify|scripts/autogen|scripts/check-namespace|\.py$)" "$ROOT"); then |
| 122 | gh_error_simplescip-shell shell shell-project 0.0.0 gh_error_simple(). "Format error" "$diff" |
| 123 | errorscip-shell shell shell-project 0.0.0 error(). "Lint python" |
| 124 | SUCCESS=false |
| 125 | gh_summary_failurescip-shell shell shell-project 0.0.0 gh_summary_failure(). "Lint python" |
| 126 | else |
| 127 | infoscip-shell shell shell-project 0.0.0 info(). "Lint Python" |
| 128 | gh_summary_successscip-shell shell shell-project 0.0.0 gh_summary_success(). "Lint Python" |
| 129 | fi |
| 130 | gh_group_endscip-shell shell shell-project 0.0.0 gh_group_end(). |
| 131 | |
| 132 | gh_group_startscip-shell shell shell-project 0.0.0 gh_group_start(). "Linting c files with clang-format" |
| 133 | checkerrscip-shell shell shell-project 0.0.0 checkerr(). "Lint C" "$(clang-format $(gitscip-shell system . . git. ls-files ":/*.c" ":/*.h") --Werror --dry-run 2>&1 | grepscip-shell system . . grep. "error:" | cutscip-shell system . . cut. -d ':' -f 1,2 | trscip-shell system . . tr. ':' ' ')" |
| 134 | gh_group_endscip-shell shell shell-project 0.0.0 gh_group_end(). |
| 135 | |
| 136 | check-eol-dry-runscip-shell shell shell-project 0.0.0 check-eol-dry-run().() |
| 137 | { |
| 138 | for file in $(gitscip-shell system . . git. ls-files -- ":/" ":/!:*.png"); do |
| 139 | # Ignore symlinks |
| 140 | if [[ ! -L $file && $(tail -c1 "$file" | wc -l) == 0 ]]; then |
| 141 | l=$(wcscip-shell system . . wc. -l <"$file") |
| 142 | echoscip-shell system . . echo. "$file $l" |
| 143 | fi |
| 144 | done |
| 145 | } |
| 146 | gh_group_startscip-shell shell shell-project 0.0.0 gh_group_start(). "Checking eol" |
| 147 | checkerrscip-shell shell shell-project 0.0.0 checkerr(). "Check eol" "$(check-eol-dry-runscip-shell shell shell-project 0.0.0 check-eol-dry-run().)" |
| 148 | gh_group_endscip-shell shell shell-project 0.0.0 gh_group_end(). |
| 149 | |
| 150 | check-spdxscip-shell shell shell-project 0.0.0 check-spdx().() |
| 151 | { |
| 152 | local success=true |
| 153 | for file in $(gitscip-shell system . . git. ls-files -- ":/" ":/!:*.json" ":/!:*.png" ":/!:*LICENSE*" ":/!:.git*" ":/!:flake.lock"); do |
| 154 | # Ignore symlinks |
| 155 | if [[ ! -L $file && $(grep "SPDX-License-Identifier:" $file | wc -l) == 0 ]]; then |
| 156 | gh_errorscip-shell shell shell-project 0.0.0 gh_error(). "$file" "${line:-1}" "Missing license header error" "$file is missing SPDX License header" |
| 157 | success=false |
| 158 | fi |
| 159 | done |
| 160 | for file in $(gitscip-shell system . . git. ls-files -- "*.[chsS]" "*.py" "*.mk" "*.yml" "**/Makefile*" ":/!proofs/cbmc/*.py" ":/!examples/bring_your_own_fips202/custom_fips202/tiny_sha3/*" ":/!examples/custom_backend/mldsa_native/src/fips202/native/custom/src/*"); do |
| 161 | # Ignore symlinks |
| 162 | if [[ ! -L $file && $(grep "Copyright (c) The mldsa-native project authors" $file | wc -l) == 0 ]]; then |
| 163 | gh_errorscip-shell shell shell-project 0.0.0 gh_error(). "$file" "${line:-1}" "Missing copyright header error" "$file is missing copyright header" |
| 164 | success=false |
| 165 | fi |
| 166 | done |
| 167 | # For source files in dev/* and mldsa/*, we enforce `Apache-2.0 OR ISC OR MIT` |
| 168 | for file in $(gitscip-shell system . . git. ls-files -- "*.[chsSi]" | grepscip-shell system . . grep. "^dev/\|^mldsa/"); do |
| 169 | # Ignore symlinks |
| 170 | if [[ ! -L $file && $(grep "SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT" $file | wc -l) == 0 ]]; then |
| 171 | gh_errorscip-shell shell shell-project 0.0.0 gh_error(). "$file" "${line:-1}" "Missing license header error" "$file is not licensed under 'Apache-2.0 OR ISC OR MIT'" |
| 172 | success=false |
| 173 | fi |
| 174 | done |
| 175 | |
| 176 | if $success; then |
| 177 | infoscip-shell shell shell-project 0.0.0 info(). "Check SPDX + Copyright" |
| 178 | gh_summary_successscip-shell shell shell-project 0.0.0 gh_summary_success(). "Check SPDX + Copyright" |
| 179 | else |
| 180 | errorscip-shell shell shell-project 0.0.0 error(). "Check SPDX + Copyright" |
| 181 | SUCCESS=false |
| 182 | gh_summary_failurescip-shell shell shell-project 0.0.0 gh_summary_failure(). "Check SPDX + Copyright" |
| 183 | fi |
| 184 | } |
| 185 | gh_group_startscip-shell shell shell-project 0.0.0 gh_group_start(). "Checking SPDX + Copyright headers" |
| 186 | check-spdxscip-shell shell shell-project 0.0.0 check-spdx(). |
| 187 | gh_group_endscip-shell shell shell-project 0.0.0 gh_group_end(). |
| 188 | |
| 189 | check-autogenerated-filesscip-shell shell shell-project 0.0.0 check-autogenerated-files().() |
| 190 | { |
| 191 | if python3scip-shell system . . python3. $ROOT/scripts/autogen --dry-run; then |
| 192 | infoscip-shell shell shell-project 0.0.0 info(). "Check native auto-generated files" |
| 193 | gh_summary_successscip-shell shell shell-project 0.0.0 gh_summary_success(). "Check native auto-generated files" |
| 194 | else |
| 195 | errorscip-shell shell shell-project 0.0.0 error(). "Check native auto-generated files" |
| 196 | gh_summary_failurescip-shell shell shell-project 0.0.0 gh_summary_failure(). "Check native auto-generated files" |
| 197 | SUCCESS=false |
| 198 | fi |
| 199 | } |
| 200 | |
| 201 | gh_group_startscip-shell shell shell-project 0.0.0 gh_group_start(). "Check native auto-generated files" |
| 202 | check-autogenerated-filesscip-shell shell shell-project 0.0.0 check-autogenerated-files(). |
| 203 | gh_group_endscip-shell shell shell-project 0.0.0 gh_group_end(). |
| 204 | |
| 205 | check-magicscip-shell shell shell-project 0.0.0 check-magic().() |
| 206 | { |
| 207 | if python3scip-shell system . . python3. $ROOT/scripts/check-magic >/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 208 | infoscip-shell shell shell-project 0.0.0 info(). "Check magic constants" |
| 209 | gh_summary_successscip-shell shell shell-project 0.0.0 gh_summary_success(). "Check magic constants" |
| 210 | else |
| 211 | errorscip-shell shell shell-project 0.0.0 error(). "Check magic constants" |
| 212 | gh_summary_failurescip-shell shell shell-project 0.0.0 gh_summary_failure(). "Check magic constants" |
| 213 | SUCCESS=false |
| 214 | fi |
| 215 | } |
| 216 | |
| 217 | gh_group_startscip-shell shell shell-project 0.0.0 gh_group_start(). "Check magic constants" |
| 218 | check-magicscip-shell shell shell-project 0.0.0 check-magic(). |
| 219 | gh_group_endscip-shell shell shell-project 0.0.0 gh_group_end(). |
| 220 | |
| 221 | if ! $SUCCESS; then |
| 222 | exit 1 |
| 223 | fi |
| 224 | |
| 225 | check-contractsscip-shell shell shell-project 0.0.0 check-contracts().() |
| 226 | { |
| 227 | if python3scip-shell system . . python3. $ROOT/scripts/check-contracts >/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 228 | infoscip-shell shell shell-project 0.0.0 info(). "Check contracts" |
| 229 | gh_summary_successscip-shell shell shell-project 0.0.0 gh_summary_success(). "Check contracts" |
| 230 | else |
| 231 | errorscip-shell shell shell-project 0.0.0 error(). "Check contracts" |
| 232 | gh_summary_failurescip-shell shell shell-project 0.0.0 gh_summary_failure(). "Check contracts" |
| 233 | SUCCESS=false |
| 234 | fi |
| 235 | } |
| 236 | |
| 237 | gh_group_startscip-shell shell shell-project 0.0.0 gh_group_start(). "Check contracts" |
| 238 | check-contractsscip-shell shell shell-project 0.0.0 check-contracts(). |
| 239 | gh_group_endscip-shell shell shell-project 0.0.0 gh_group_end(). |
| 240 | |
| 241 | if ! $SUCCESS; then |
| 242 | exit 1 |
| 243 | fi |