forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_changelog_fragments.sh
More file actions
executable file
·76 lines (58 loc) · 2.54 KB
/
check_changelog_fragments.sh
File metadata and controls
executable file
·76 lines (58 loc) · 2.54 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
#!/usr/bin/env bash
# This script is intended to run during CI, however it can be run locally by
# committing changelog fragments before executing the script. If the script
# finds an issue with your changelog fragment, you can un-stage the fragment
# from being committed and fix the issue.
CHANGELOG_DIR="changelog.d"
# NOTE: If these are altered, update both the 'changelog.d/README.md' and
# 'scripts/generate-release-cue.rb' accordingly.
FRAGMENT_TYPES="breaking|security|deprecation|feature|enhancement|fix"
if [ ! -d "${CHANGELOG_DIR}" ]; then
echo "No ./${CHANGELOG_DIR} found. This tool must be invoked from the root of the repo."
exit 1
fi
# diff-filter=A lists only added files
FRAGMENTS=$(git diff --name-only --diff-filter=A --merge-base "${MERGE_BASE:-origin/master}" ${CHANGELOG_DIR})
if [ -z "$FRAGMENTS" ]; then
echo "No changelog fragments detected"
echo "If no changes necessitate user-facing explanations, add the GH label 'no-changelog'"
echo "Otherwise, add changelog fragments to changelog.d/"
echo "For details, see 'changelog.d/README.md'"
exit 1
fi
[[ "$(wc -l <<< "$FRAGMENTS")" -gt "${MAX_FRAGMENTS:-1000}" ]] && exit 1
# extract the basename from the file path
FRAGMENTS=$(xargs -n1 basename <<< "${FRAGMENTS}")
# validate the fragments
while IFS= read -r fname; do
if [[ ${fname} == "README.md" ]]; then
continue
fi
echo "validating '${fname}'"
IFS="." read -r -a arr <<< "${fname}"
if [ "${#arr[@]}" -ne 3 ]; then
echo "invalid fragment filename: wrong number of period delimiters. expected '<unique_name>.<fragment_type>.md'. (${fname})"
exit 1
fi
if ! [[ "${arr[1]}" =~ ^(${FRAGMENT_TYPES})$ ]]; then
echo "invalid fragment filename: fragment type must be one of: (${FRAGMENT_TYPES}). (${fname})"
exit 1
fi
if [[ "${arr[2]}" != "md" ]]; then
echo "invalid fragment filename: extension must be markdown (.md): (${fname})"
exit 1
fi
# Each fragment should have a properly formatted authors line at the end of the file.
last=$( tail -n 1 "${CHANGELOG_DIR}/${fname}" )
if [[ "${last}" == "authors: "*@* ]]; then
echo "invalid fragment contents: author should not be prefixed with @"
exit 1
elif [[ "${last}" == "authors: "*,* ]]; then
echo "invalid fragment contents: authors should be space delimited, not comma delimited."
exit 1
elif ! [[ "${last}" =~ ^(authors: .*)$ ]]; then
echo "invalid fragment contents: author option was specified but fragment ${fname} contains no authors."
exit 1
fi
done <<< "$FRAGMENTS"
echo "changelog additions are valid."