File: spdx-ensure

package info (click to toggle)
golang-github-tillitis-tkeysign 1.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 128 kB
  • sloc: sh: 70; makefile: 10
file content (90 lines) | stat: -rwxr-xr-x 1,814 bytes parent folder | download | duplicates (2)
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
#!/bin/bash
# SPDX-FileCopyrightText: 2023 Tillitis AB <tillitis.se>
# SPDX-License-Identifier: BSD-2-Clause
set -eu

# Check for the SPDX tag in all files in the repo. Exit with a non-zero code if
# some is missing. The missingok arrays below contain files and directories
# with files where the the tag is not required.

cd "${0%/*}"
cd ..

tag="SPDX-License-Identifier:"

missingok_dirs=(
.github/workflows/
)

missingok_files=(
.editorconfig
.gitignore
.golangci.yml
LICENSE
LICENSES/BSD-2-Clause.txt
Makefile
README.md
RELEASE.md
go.mod
go.sum
)

is_missingok() {
  item="$1"
  # ok for empty files
  [[ -f "$item" ]] && [[ ! -s "$item" ]] && return 0
  for fileok in "${missingok_files[@]}"; do
    [[ "$item" = "$fileok" ]] && return 0
  done
  for dirok in "${missingok_dirs[@]}"; do
    [[ "$item" =~ ^$dirok ]] && return 0
  done
  return 1
}

printf "* Checking for SPDX tags in %s\n" "$PWD"

mapfile -t repofiles < <(git ls-files || true)
if [[ -z "${repofiles[*]}" ]]; then
  printf "* No files in the repo?!\n"
  exit 1
fi

failed=0

printed=0
for fileok in "${missingok_files[@]}"; do
  [[ -f "$fileok" ]] && continue
  if (( !printed )); then
    printf "* Some files in missingok_files are themselves missing:\n"
    printed=1
    failed=1
  fi
  printf "%s\n" "$fileok"
done

printed=0
for dirok in "${missingok_dirs[@]}"; do
  [[ -d "$dirok" ]] && continue
  if (( !printed )); then
    printf "* Some dirs in missingok_dirs are themselves missing:\n"
    printed=1
    failed=1
  fi
  printf "%s\n" "$dirok"
done

printed=0
for file in "${repofiles[@]}"; do
  is_missingok "$file" && continue
  if ! grep -q "$tag" "$file"; then
    if (( !printed )); then
      printf "* Files missing the SPDX tag:\n"
      printed=1
      failed=1
    fi
    printf "%s\n" "$file"
  fi
done

exit "$failed"