| 1 | #!/usr/bin/env bash |
| 2 | # SPDX-License-Identifier: AGPL-3.0-or-later |
| 3 | # |
| 4 | # Every Go source file in this repo must carry an SPDX header |
| 5 | # identifying the license. The convention: |
| 6 | # |
| 7 | # // SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | # |
| 9 | # Exemptions: |
| 10 | # - sqlc-generated files under */sqlc/ — the sqlc tool emits a |
| 11 | # different header. We don't maintain those by hand. |
| 12 | # - Test fixtures under testdata/. |
| 13 | # - Vendored code (we don't vendor today; this is forward-looking). |
| 14 | # |
| 15 | # Run: ./scripts/verify-spdx-headers.sh |
| 16 | |
| 17 | set -euo pipefail |
| 18 | |
| 19 | ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 20 | cd "$ROOT" |
| 21 | |
| 22 | WANT='// SPDX-License-Identifier: AGPL-3.0-or-later' |
| 23 | missing=() |
| 24 | |
| 25 | # Find every committed .go file outside the exemptions, then |
| 26 | # check the first 3 lines for the header. |
| 27 | while IFS= read -r f; do |
| 28 | case "$f" in |
| 29 | */sqlc/*) continue ;; |
| 30 | */testdata/*) continue ;; |
| 31 | */vendor/*) continue ;; |
| 32 | esac |
| 33 | if ! head -n 3 "$f" | grep -qF "$WANT"; then |
| 34 | missing+=("$f") |
| 35 | fi |
| 36 | done < <(git ls-files '*.go') |
| 37 | |
| 38 | if [[ ${#missing[@]} -gt 0 ]]; then |
| 39 | echo "verify-spdx-headers: the following files are missing the SPDX header:" >&2 |
| 40 | printf ' %s\n' "${missing[@]}" >&2 |
| 41 | echo "" >&2 |
| 42 | echo "Add this line at the top (line 1 ideally, line 3 max):" >&2 |
| 43 | echo " $WANT" >&2 |
| 44 | exit 1 |
| 45 | fi |
| 46 | |
| 47 | # Also enforce the same on shell scripts in scripts/ and deploy/. |
| 48 | sh_missing=() |
| 49 | SH_WANT='# SPDX-License-Identifier: AGPL-3.0-or-later' |
| 50 | while IFS= read -r f; do |
| 51 | if ! head -n 5 "$f" | grep -qF "$SH_WANT"; then |
| 52 | sh_missing+=("$f") |
| 53 | fi |
| 54 | done < <(git ls-files 'scripts/*.sh' 'deploy/**/*.sh') |
| 55 | |
| 56 | if [[ ${#sh_missing[@]} -gt 0 ]]; then |
| 57 | echo "verify-spdx-headers: the following shell scripts are missing the SPDX header:" >&2 |
| 58 | printf ' %s\n' "${sh_missing[@]}" >&2 |
| 59 | echo "" >&2 |
| 60 | echo "Add this line within the first 5 lines:" >&2 |
| 61 | echo " $SH_WANT" >&2 |
| 62 | exit 1 |
| 63 | fi |
| 64 | |
| 65 | echo "verify-spdx-headers: ok" |