-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·108 lines (97 loc) · 3.02 KB
/
run-tests.sh
File metadata and controls
executable file
·108 lines (97 loc) · 3.02 KB
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
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
#
# This file is part of REANA.
# Copyright (C) 2024, 2025, 2026 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
set -o errexit
set -o nounset
format_prettier() {
prettier -c .
}
format_shfmt() {
shfmt -d .
}
lint_commitlint() {
from=${2:-master}
to=${3:-HEAD}
pr=${4:-[0-9]+}
if command -v commitlint >/dev/null 2>&1; then
commitlint --from="$from" --to="$to"
else
npx commitlint --from="$from" --to="$to"
fi
found=0
while IFS= read -r line; do
commit_hash=$(echo "$line" | cut -d ' ' -f 1)
commit_title=$(echo "$line" | cut -d ' ' -f 2-)
commit_number_of_parents=$(git rev-list --parents "$commit_hash" -n1 | awk '{print NF-1}')
# (i) skip checking release commits generated by Release Please
if [ "$commit_number_of_parents" -le 1 ] && echo "$commit_title" | grep -qE "^chore\(.*\): release"; then
continue
fi
# (ii) check presence of PR number
if ! echo "$commit_title" | grep -qE "\(#$pr\)$"; then
echo "✖ Headline does not end by '(#$pr)' PR number: $commit_title"
found=1
fi
# (iii) check absence of merge commits in feature branches
if [ "$commit_number_of_parents" -gt 1 ]; then
if echo "$commit_title" | grep -qE "^chore\(.*\): merge "; then
break # skip checking maint-to-master merge commits
else
echo "✖ Merge commits are not allowed in feature branches: $commit_title"
found=1
fi
fi
done < <(git log "$from..$to" --format="%H %s")
if [ $found -gt 0 ]; then
exit 1
fi
}
lint_markdownlint() {
markdownlint-cli2 "**/*.md"
}
lint_shellcheck() {
find . -name "*.sh" -exec shellcheck {} \+
}
lint_yamllint() {
yamllint .
}
all() {
format_prettier
format_shfmt
lint_commitlint
lint_markdownlint
lint_shellcheck
lint_yamllint
}
help() {
echo "Usage: $0 [options]"
echo "Options:"
echo " --all Perform all checks [default]"
echo " --format-prettier Check formatting of Markdown etc files"
echo " --format-shfmt Check formatting of shell scripts"
echo " --help Display this help message"
echo " --lint-commitlint Check linting of commit messages"
echo " --lint-markdownlint Check linting of Markdown files"
echo " --lint-shellcheck Check linting of shell scripts"
echo " --lint-yamllint Check linting of YAML files"
}
if [ $# -eq 0 ]; then
all
exit 0
fi
arg="$1"
case $arg in
--all) all ;;
--help) help ;;
--format-prettier) format_prettier ;;
--format-shfmt) format_shfmt ;;
--lint-commitlint) lint_commitlint "$@" ;;
--lint-markdownlint) lint_markdownlint ;;
--lint-shellcheck) lint_shellcheck ;;
--lint-yamllint) lint_yamllint ;;
*) echo "[ERROR] Invalid argument '$arg'. Exiting." && help && exit 1 ;;
esac