|
1 | | -#!/bin/sh -eux |
| 1 | +#!/bin/sh -eu |
2 | 2 |
|
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() { _() { :; }; } |
8 | 15 |
|
9 | 16 | if [ -n "${CI+x}" ] |
10 | 17 | then |
11 | 18 | if [ -n "${GITHUB_ACTION+x}" ] |
12 | | - set -x |
13 | 19 | 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 |
21 | 25 | echo "::group::$1" |
22 | 26 | trace_on |
23 | 27 | } |
24 | | - |
25 | | - section_end_internal () { |
| 28 | + section_end() { |
| 29 | + { set +x; } 2>/dev/null # trace_off |
26 | 30 | echo "::endgroup::" |
27 | 31 | trace_on |
28 | 32 | } |
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 |
40 | 39 | fi |
| 40 | + set -x |
41 | 41 | fi |
42 | 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 |
49 | | -fi |
50 | | - |
| 43 | +section_start "Variables" |
51 | 44 | VERSION="$1" |
52 | | -NAMESPACE="domjudge" |
53 | | -if [ -n "${2+x}" ] |
54 | | -then |
55 | | - NAMESPACE="$2" |
56 | | -fi |
57 | | - |
| 45 | +NAMESPACE="${2-domjudge}" |
58 | 46 | URL=https://www.domjudge.org/releases/domjudge-${VERSION}.tar.gz |
59 | 47 | FILE=domjudge.tar.gz |
| 48 | +section_end |
60 | 49 |
|
61 | 50 | section_start "Download DOMjudge tarball" |
62 | 51 | echo "[..] Downloading DOMjudge version ${VERSION}..." |
63 | | - |
64 | 52 | if ! wget --quiet "${URL}" -O ${FILE} |
65 | 53 | then |
66 | 54 | echo "[!!] DOMjudge version ${VERSION} file not found on https://www.domjudge.org/releases" |
67 | 55 | exit 1 |
68 | 56 | fi |
69 | | - |
70 | 57 | echo "[ok] DOMjudge version ${VERSION} downloaded as domjudge.tar.gz"; echo |
71 | 58 | section_end |
72 | 59 |
|
|
0 commit comments