Skip to content

Commit d571e7f

Browse files
author
Allen Winter
committed
deploy/release-kdreports.sh - tool to help with pre-release tasks
1 parent 8e58f34 commit d571e7f

File tree

1 file changed

+241
-0
lines changed

1 file changed

+241
-0
lines changed

deploy/release-kdreports.sh

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
#!/bin/bash
2+
3+
# This file is part of the KD Reports library.
4+
#
5+
# SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6+
#
7+
# SPDX-License-Identifier: MIT
8+
#
9+
10+
#Exit if any undefined variable is used.
11+
set -u
12+
#Exit this script if it any subprocess exits non-zero.
13+
set -e
14+
#If any process in a pipeline fails, the return value is a failure.
15+
set -o pipefail
16+
17+
PROJECT=kdreports
18+
FORMAL_PROJECT=KDReports #also used for the CMake options
19+
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
20+
TOP=$(dirname "$SCRIPT_DIR")
21+
22+
#function HELP
23+
# print a help message and exit
24+
HELP() {
25+
echo
26+
echo "Usage: $(basename "$0") [-f] X.Y.Z"
27+
echo
28+
echo "Create the tars/zips and sign for project release X.Y.Z"
29+
echo " Options:"
30+
echo " -f Force everything to run, even if the tag for X.Y.Z has already been pushed."
31+
echo
32+
exit 0
33+
}
34+
35+
#git clone if needed, then update
36+
GIT_UPDATE() {
37+
mkdir -p "$1"
38+
pushd "$1"
39+
git init
40+
set +e
41+
git remote add origin "$3"
42+
set -e
43+
git fetch
44+
git checkout master
45+
git submodule update --init --recursive
46+
popd
47+
}
48+
49+
#compare 2 version strings
50+
verlte() {
51+
printf '%s\n' "$1" "$2" | sort -C -V
52+
}
53+
54+
#function SYNCECM: $1 is "KDAB" or "ECM"; $2 is the fullpath to the official version
55+
SYNCECM() {
56+
set +e
57+
echo -n "Comparing $1 cmake modules to upstream: "
58+
savepwd=$(pwd)
59+
if (test ! -d "$TOP/cmake/$1/modules"); then
60+
echo "FAIL"
61+
echo " This project does not have the $1 CMake modules collected under cmake/$1/modules. Please deal with this first"
62+
exit 1
63+
fi
64+
cd "$TOP/cmake/$1/modules"
65+
whiteList=""
66+
for m in *.cmake; do
67+
if [ -n "$whiteList" ]; then
68+
if [[ $m =~ $whiteList ]]; then
69+
echo "SKIPPING $m"
70+
continue
71+
fi
72+
fi
73+
if (test -f "$2/modules/$m"); then
74+
module="modules"
75+
diff "$m" "$2/modules/$m" 2>&1
76+
savestat=$?
77+
else
78+
if (test -f "$2/find-modules/$m"); then
79+
module="find-modules"
80+
diff "$m" "$2/find-modules/$m" 2>&1
81+
savestat=$?
82+
else
83+
echo "What is $m doing here?"
84+
exit 1
85+
fi
86+
fi
87+
if (test $savestat -ne 0); then
88+
echo "FAIL. Differences encountered in upstream $m"
89+
echo " Upstream: $2/$module/$m"
90+
echo " $PROJECT: cmake/$1/modules/$m"
91+
echo "Please sync the $PROJECT version before continuing (review changes first!)"
92+
exit 1
93+
fi
94+
done
95+
echo "OK"
96+
cd "$savepwd"
97+
set -e
98+
}
99+
100+
options=$(getopt -o "hf" --long "help,force" -- "$@")
101+
eval set -- "$options"
102+
force=0
103+
while true; do
104+
case "$1" in
105+
-h | --help)
106+
HELP
107+
;;
108+
-f | --force)
109+
force=1
110+
shift
111+
;;
112+
--)
113+
shift
114+
break
115+
;;
116+
*)
117+
echo "Internal error!"
118+
exit 1
119+
;;
120+
esac
121+
done
122+
123+
if (test $# -ne 1); then
124+
HELP
125+
fi
126+
127+
#compute X(major), Y(minor), Z(patchlevel)
128+
if [[ ! $1 =~ ^[0-9]*\.[0-9]*\.[0-9]*$ ]]; then
129+
echo "\"$1\" is not a valid version string of the form X.Y.Z"
130+
exit 1
131+
fi
132+
X=$(echo "$1" | cut -d. -f1)
133+
Y=$(echo "$1" | cut -d. -f2)
134+
Z=$(echo "$1" | cut -d. -f3)
135+
136+
#set the branch and tag
137+
branch=$PROJECT-$X.$Y
138+
tag=$branch.$Z
139+
release=$X.$Y.$Z
140+
141+
cd "$TOP" || exit 1
142+
tbranch=$(sed -e 's,.*/,,' "$TOP/.git/HEAD")
143+
if (test "$tbranch" != "$branch"); then
144+
echo "please git checkout $branch first"
145+
exit
146+
fi
147+
148+
#Sanity Checking
149+
150+
# Update doxyfile
151+
if ! command -v doxygen &>/dev/null; then
152+
echo "doxygen is not installed or not in your PATH. please fix."
153+
exit 1
154+
fi
155+
156+
#CI uses 1.12.0 at this time
157+
minDoxyVersion="1.12.0"
158+
export PATH=/usr/local/opt/doxygen-$minDoxyVersion/bin:$PATH
159+
doxyVersion=$(doxygen -version | awk '{print $1}')
160+
if ! verlte "$minDoxyVersion" "$doxyVersion"; then
161+
echo "please install doxygen version $minDoxyVersion or higher"
162+
exit 1
163+
fi
164+
165+
echo -n "Ensuring Doxyfile.cmake is up-to-date: "
166+
doxygen -u docs/api/Doxyfile.cmake >/dev/null 2>&1
167+
set +e
168+
diff docs/api/Doxyfile.cmake docs/api/Doxyfile.cmake.bak >/dev/null 2>&1
169+
if (test $? -ne 0); then
170+
echo "Doxyfile.cmake has been updated by 'doxygen -u'. Please deal with this first"
171+
exit 1
172+
else
173+
echo "OK"
174+
rm -f docs/api/Doxyfile.cmake.bak
175+
fi
176+
set -e
177+
178+
### KDAB cmake modules are synced
179+
kdabECM="$HOME/projects/kdecm"
180+
GIT_UPDATE "$kdabECM" "master" "ssh://codereview.kdab.com:29418/kdab/extra-cmake-modules"
181+
SYNCECM "KDAB" "$kdabECM"
182+
### KDE cmake modules are synced
183+
kdeECM="$HOME/projects/extra-cmake-modules"
184+
GIT_UPDATE "$kdeECM" "master" "git@invent.kde.org:frameworks/extra-cmake-modules"
185+
SYNCECM "ECM" "$kdeECM"
186+
187+
### pre-commit checking
188+
echo "Pre-commit checking: "
189+
pre-commit run --all-files
190+
if (test $? -ne 0); then
191+
echo "There are pre-commit issues. Please deal with this first"
192+
exit 1
193+
else
194+
echo "OK"
195+
fi
196+
197+
if (test "$(git tag -l | grep -c "$tag$")" -ne 1); then
198+
echo "please create the git tag $tag first:"
199+
echo "git tag -m \"$FORMAL_PROJECT $release\" $tag"
200+
exit
201+
fi
202+
203+
if (test $force -eq 0 -a "$(git ls-remote --tags origin | grep -c "refs/tags/$tag$")" -gt 0); then
204+
echo "The tag for $tag has already been pushed."
205+
echo "Change the release number you provided on the command line."
206+
echo 'Or, if you simply want to re-create the tar and zips use the "-f" option.'
207+
exit
208+
fi
209+
210+
# create the API documentation
211+
rm -rf build-docs "$PROJECT-$release-doc.zip"
212+
mkdir build-docs
213+
cd build-docs || exit 1
214+
cmake -G Ninja --warn-uninitialized -Werror=dev -D"$FORMAL_PROJECT"_DOCS=True ..
215+
cmake --build . --target=docs
216+
cd docs/api/html || exit 1
217+
7z a "$TOP/$PROJECT-$release-doc.zip" .
218+
cd "$TOP" || exit 1
219+
rm -rf build-docs
220+
221+
git archive --format=tar --prefix="$PROJECT-$release/" "$tag" | gzip >"$PROJECT-$release.tar.gz"
222+
git archive --format=zip --prefix="$PROJECT-$release/" "$tag" >"$PROJECT-$release.zip"
223+
224+
# sign the tarballs
225+
gpg --yes --local-user "KDAB Products" --armor --detach-sign "$PROJECT-$release.tar.gz"
226+
gpg --yes --local-user "KDAB Products" --armor --detach-sign "$PROJECT-$release.zip"
227+
228+
# final cleaning
229+
#anything to clean?
230+
231+
# sanity
232+
files="\
233+
$PROJECT-$release.tar.gz \
234+
$PROJECT-$release.tar.gz.asc \
235+
$PROJECT-$release.zip \
236+
$PROJECT-$release.zip.asc \
237+
$PROJECT-$release-doc.zip \
238+
"
239+
for f in $files; do
240+
ls -l "$f"
241+
done

0 commit comments

Comments
 (0)