Debian Codegraph @

dev/tools/generate-release-changelog.sh

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 #!/usr/bin/bash
2
3 set -e
4 set -o pipefail
5
6 if [ $# != 1 ]; then
7 echo "Usage: $0 BRANCH"
8 exit
9 fi
10
11 branch=$1
12
13 # Set SLOW_CONF to have the confirmation output wait for a newline
14 # Emacs doesn't send characters until the RET so we can't quick_conf
15 if [ -z ${SLOW_CONF+x} ] || [ -n "$INSIDE_EMACS" ]; then
16 quick_conf=(-n 1)
17 else
18 quick_conf=()
19 fi
20
21 ask_confirmation() {
22 read -p "Continue anyway? [y/N] " "${quick_conf[@]}" -r
23 echo
24 if [[ ! $REPLY =~ ^[Yy]$ ]]; then
25 exit 1
26 fi
27 }
28
29 if ! git diff --quiet; then
30 echo "Warning: current tree is dirty."
31 ask_confirmation
32 fi
33
34 remote=$(git config --get "branch.${branch}.remote" || true)
35
36 if [ -z "$remote" ]; then
37 echo "Warning: branch $branch has no associated remote."
38 ask_confirmation
39 else
40
41 if [[ "$remote" != $(git config --get "branch.master.remote") ]]; then
42 echo "Warning: branch master and branch $branch do not have the same remote."
43 ask_confirmation
44 fi
45
46 official_remote_git_url="[email protected]:rocq-prover/rocq"
47 official_remote_https_url="github.com/rocq-prover/rocq"
48 remote_url=$(git remote get-url "$remote" --all)
49
50 if [ "$remote_url" != "${official_remote_git_url}" ] && \
51 [ "$remote_url" != "${official_remote_git_url}.git" ] && \
52 [ "$remote_url" != "https://${official_remote_https_url}" ] && \
53 [ "$remote_url" != "https://${official_remote_https_url}.git" ] && \
54 [[ "$remote_url" != "https://"*"@${official_remote_https_url}" ]] && \
55 [[ "$remote_url" != "https://"*"@${official_remote_https_url}.git" ]] ; then
56 echo "Warning: remote $remote does not point to the official Rocq repo,"
57 echo "that is $official_remote_git_url"
58 echo "It points to $remote_url instead."
59 ask_confirmation
60 fi
61
62 git fetch "$remote"
63
64 if [[ $(git rev-parse master) != $(git rev-parse "${remote}/master") ]]; then
65 echo "Warning: branch master is not up-to-date with ${remote}/master."
66 ask_confirmation
67 fi
68
69 if [[ $(git rev-parse "$branch") != $(git rev-parse "${remote}/${branch}") ]]; then
70 echo "Warning: branch ${branch} is not up-to-date with ${remote}/${branch}."
71 ask_confirmation
72 fi
73
74 fi
75
76 git checkout "$branch" --detach > /dev/null 2>&1
77 changelog_entries_with_title=(doc/changelog/*/*.rst)
78 git checkout master > /dev/null 2>&1
79
80 tmp=$(mktemp)
81 for f in "${changelog_entries_with_title[@]}"; do
82 if ! [ -f "$f" ]; then
83 >&2 echo "Warning: $f is missing in master branch."
84 continue
85 fi
86
87 cat=${f%/*} # dirname
88 if [[ ${f##*/} = 00000-title.rst ]]; then
89 type=0
90 else
91 type_name=$(head -n 1 "$f" | cut -f 2 -d ' ')
92 type_name=${type_name%":**"}
93 type_name=${type_name#"**"}
94 case "$type_name" in
95 Changed) type=1;;
96 Removed) type=2;;
97 Deprecated) type=3;;
98 Added) type=4;;
99 Fixed) type=5;;
100 *) >&2 echo "Unknown changelog type $type_name in $f"; type=6;;
101 esac
102 fi
103 printf '%s %s %s\n' "$cat" "$type" "$f" >> "$tmp"
104 done
105
106 while read -r _ type f; do
107 cat "$f" >> released.rst
108 if ! [[ $type = 0 ]]; then git rm "$f" >> /dev/null; fi
109 done < <(sort "$tmp")
110
111 echo
112 echo "Changelog written in released.rst. Move its content to a new section in doc/sphinx/changes.rst."