Skip to content

Commit 6cd73e4

Browse files
committed
Clean up docker/build.sh
- Move usage check to the top, to serve as documentation for people who read the script. - Remove `-x` from shebang line (#!), to only enable tracing in CI. - Fix `set -x` call (previously it was inside the `if` condition, which is wrong). - Include line numbers etc. in traces (using PS4) on GitHub Actions (previously they were only included on other CI platforms). - Inline `trace_off` into section_start and section_end to produce less noise in the trace. - Make the no-op placeholders for section_start and section_end produce less noise in the trace. - Redirect stderr to stdout as a workaround for a GitHub Actions issue that causes them to appear out-of-order. - Simplify initialisation of NAMESPACE variable to make the trace look nicer. - Fix the invocation of build.sh in the build-domjudge-container-* workflows to use `./build.sh` rather than `sh ./build.sh` so that the options in the shebang line will be respected. Also remove unnecessary calls to `set -x` in the workflows.
1 parent d1da7b7 commit 6cd73e4

File tree

3 files changed

+31
-46
lines changed

3 files changed

+31
-46
lines changed

.github/workflows/build-domjudge-container-PR.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ jobs:
6565
- name: Build the container
6666
run: |
6767
cd docker
68-
set -x
69-
sh ./build.sh "${{ env.DOMJUDGE_VERSION }}"
70-
set +x
68+
./build.sh "${{ env.DOMJUDGE_VERSION }}"
7169
7270
- name: Build and push
7371
run: |

.github/workflows/build-domjudge-container-release.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ jobs:
6565
- name: Build the container
6666
run: |
6767
cd docker
68-
set -x
69-
sh ./build.sh "${{ env.DOMJUDGE_VERSION }}"
70-
set +x
68+
./build.sh "${{ env.DOMJUDGE_VERSION }}"
7169
7270
- name: Build and push
7371
run: |

docker/build.sh

+29-40
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,48 @@
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://gh.loli.gardenmunity/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
41-
fi
42-
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
40+
export PS4='(${0}:${LINENO}): - [$?] $ '
41+
set -x
4942
fi
5043

5144
VERSION="$1"
52-
NAMESPACE="domjudge"
53-
if [ -n "${2+x}" ]
54-
then
55-
NAMESPACE="$2"
56-
fi
45+
NAMESPACE="${2-domjudge}"
5746

5847
URL=https://www.domjudge.org/releases/domjudge-${VERSION}.tar.gz
5948
FILE=domjudge.tar.gz

0 commit comments

Comments
 (0)