Skip to content

Commit b76b188

Browse files
committed
cherry-pick: Clean up docker/build.sh
From DOMjudge/domjudge-packaging#197
1 parent c11aed7 commit b76b188

File tree

1 file changed

+30
-43
lines changed

1 file changed

+30
-43
lines changed

docker/build.sh

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,59 @@
1-
#!/bin/sh -eux
1+
#!/bin/sh -eu
22

3-
# Placeholders to annotate the Github actions logs
4-
trace_on () { true; }
5-
trace_off () { true; }
6-
section_start () { true; }
7-
section_end () { true; }
3+
if [ "$#" -eq 0 ] || [ "$#" -gt 2 ]
4+
then
5+
echo "Usage: $0 domjudge-version <namespace>"
6+
echo " For example: $0 5.3.0"
7+
echo " or: $0 5.3.0 otherNamespace"
8+
exit 1
9+
fi
10+
11+
# Placeholders for grouping log lines
12+
# (the body is a nested function declaration so it won't appear in the trace when using `set -x`)
13+
section_start() { _() { :; }; }
14+
section_end() { _() { :; }; }
815

916
if [ -n "${CI+x}" ]
1017
then
1118
if [ -n "${GITHUB_ACTION+x}" ]
12-
set -x
1319
then
14-
# Functions to annotate the Github actions logs
15-
trace_on () { set -x; }
16-
trace_off () {
17-
{ set +x; } 2>/dev/null
18-
}
19-
20-
section_start_internal () {
20+
# Functions for grouping log lines on GitHub Actions
21+
trace_on() { set -x; }
22+
# trace_off is manually inlined so it won't appear in the trace
23+
section_start() {
24+
{ set +x; } 2>/dev/null # trace_off
2125
echo "::group::$1"
2226
trace_on
2327
}
24-
25-
section_end_internal () {
28+
section_end() {
29+
{ set +x; } 2>/dev/null # trace_off
2630
echo "::endgroup::"
2731
trace_on
2832
}
29-
30-
section_start () {
31-
trace_off
32-
section_start_internal "$@"
33-
}
34-
section_end () {
35-
trace_off
36-
section_end_internal
37-
}
38-
else
39-
export PS4='(${0}:${LINENO}): - [$?] $ '
33+
# Redirect stderr to stdout as a workaround so they won't be out-of-order; see
34+
# https://github.com/orgs/community/discussions/116552
35+
# https://web.archive.org/web/20220430214837/https://github.community/t/stdout-stderr-output-not-in-correct-order-in-logs/16335
36+
# (GitHub Actions displays stderr in the same style as stdout anyway, so
37+
# there is no harm in us merging them.)
38+
exec 2>&1
4039
fi
40+
set -x
4141
fi
4242

43-
if [ "$#" -eq 0 ] || [ "$#" -gt 2 ]
44-
then
45-
echo "Usage: $0 domjudge-version <namespace>"
46-
echo " For example: $0 5.3.0"
47-
echo " or: $0 5.3.0 otherNamespace"
48-
exit 1
49-
fi
50-
43+
section_start "Variables"
5144
VERSION="$1"
52-
NAMESPACE="domjudge"
53-
if [ -n "${2+x}" ]
54-
then
55-
NAMESPACE="$2"
56-
fi
57-
45+
NAMESPACE="${2-domjudge}"
5846
URL=https://www.domjudge.org/releases/domjudge-${VERSION}.tar.gz
5947
FILE=domjudge.tar.gz
48+
section_end
6049

6150
section_start "Download DOMjudge tarball"
6251
echo "[..] Downloading DOMjudge version ${VERSION}..."
63-
6452
if ! wget --quiet "${URL}" -O ${FILE}
6553
then
6654
echo "[!!] DOMjudge version ${VERSION} file not found on https://www.domjudge.org/releases"
6755
exit 1
6856
fi
69-
7057
echo "[ok] DOMjudge version ${VERSION} downloaded as domjudge.tar.gz"; echo
7158
section_end
7259

0 commit comments

Comments
 (0)