ci: make grouping setup more generic

Make the grouping setup more generic by always calling `begin_group ()` and `end_group ()` regardless of whether we have stubbed those functions or not. This ensures we can more readily add support for additional CI platforms. Furthermore, the `group ()` function is made generic so that it is the same for both GitHub Actions and for other platforms. There is a semantic conflict here though: GitHub Actions used to call `set +x` in `group ()` whereas the non-GitHub case unconditionally uses `set -x`. The latter would get overriden if we kept the `set +x` in the generic version of `group ()`. To resolve this conflict, we simply drop the `set +x` in the generic variant of this function. As `begin_group ()` calls `set -x` anyway this is not much of a change though, as the only commands that aren't printed anymore now are the ones between the beginning of `group ()` and the end of `begin_group ()`. Last, this commit changes `end_group ()` to also accept a parameter that indicates _which_ group should end. This will be required by a later commit that introduces support for GitLab CI. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Nov 9, 2023 at 09:05 UTC a7d499cb9361e4c4d6c8b5f841e95fc8cd97584d
1 file changed +22 -24
ci/lib.sh
+22 -24
@@ -14,36 +14,34 @@ then
14 need_to_end_group=
15 echo '::endgroup::' >&2
16 }
17 - trap end_group EXIT
18 -
19 - group () {
20 - set +x
21 - begin_group "$1"
22 - shift
23 - # work around `dash` not supporting `set -o pipefail`
24 - (
25 - "$@" 2>&1
26 - echo $? >exit.status
27 - ) |
28 - sed 's/^\(\([^ ]*\):\([0-9]*\):\([0-9]*:\) \)\(error\|warning\): /::\5 file=\2,line=\3::\1/'
29 - res=$(cat exit.status)
30 - rm exit.status
31 - end_group
32 - return $res
33 - }
34 -
35 - begin_group "CI setup"
17 else
18 begin_group () { :; }
19 end_group () { :; }
20
40 - group () {
41 - shift
42 - "$@"
43 - }
21 set -x
22 fi
23
24 +group () {
25 + group="$1"
26 + shift
27 + begin_group "$group"
28 +
29 + # work around `dash` not supporting `set -o pipefail`
30 + (
31 + "$@" 2>&1
32 + echo $? >exit.status
33 + ) |
34 + sed 's/^\(\([^ ]*\):\([0-9]*\):\([0-9]*:\) \)\(error\|warning\): /::\5 file=\2,line=\3::\1/'
35 + res=$(cat exit.status)
36 + rm exit.status
37 +
38 + end_group "$group"
39 + return $res
40 +}
41 +
42 +begin_group "CI setup"
43 +trap "end_group 'CI setup'" EXIT
44 +
45 # Set 'exit on error' for all CI scripts to let the caller know that
46 # something went wrong.
47 #
@@ -285,5 +283,5 @@ esac
283
284 MAKEFLAGS="$MAKEFLAGS CC=${CC:-cc}"
285
288 -end_group
286 +end_group "CI setup"
287 set -x