Skip to content

Commit a7d499c

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a4761b6 commit a7d499c

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

ci/lib.sh

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,34 @@ then
1414
need_to_end_group=
1515
echo '::endgroup::' >&2
1616
}
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"
3617
else
3718
begin_group () { :; }
3819
end_group () { :; }
3920

40-
group () {
41-
shift
42-
"$@"
43-
}
4421
set -x
4522
fi
4623

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+
4745
# Set 'exit on error' for all CI scripts to let the caller know that
4846
# something went wrong.
4947
#
@@ -285,5 +283,5 @@ esac
285283

286284
MAKEFLAGS="$MAKEFLAGS CC=${CC:-cc}"
287285

288-
end_group
286+
end_group "CI setup"
289287
set -x

0 commit comments

Comments
 (0)