diff mbox series

[3/4] ci/lib: use echo instead of printf to set up sections

Message ID 20241206-pks-ci-section-fixes-v1-3-7ab1b69e3648@pks.im (mailing list archive)
State Superseded
Headers show
Series Random improvements to GitLab CI | expand

Commit Message

Patrick Steinhardt Dec. 6, 2024, 11:10 a.m. UTC
We use printf to set up sections with GitLab CI even though we could
trivially use echo. This may cause problems in case the argument passed
to `begin_group ()` or `end_group ()` contains formatting directives as
we use them as part of the formatting string.

Simplify the code to instead use echo.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 ci/lib.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Oswald Buddenhagen Dec. 7, 2024, 9:13 a.m. UTC | #1
On Fri, Dec 06, 2024 at 12:10:15PM +0100, Patrick Steinhardt wrote:
>We use printf to set up sections with GitLab CI even though we could
>trivially use echo.
>
probably not a good idea, because the file is also included from plain
sh scripts, which may invoke an `echo` that cannot deal with \escapes.
at least potentially.

>This may cause problems in case the argument passed to `begin_group ()`
>or `end_group ()` contains formatting directives as we use them as part
>of the formatting string.
>
that can be fixed properly by using the %s expando.

>+++ b/ci/lib.sh
>-		printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)[collapsed=true]\r\e[0K$1\n"
>+		echo "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)[collapsed=true]\r\e[0K$1"
Patrick Steinhardt Dec. 10, 2024, 11:56 a.m. UTC | #2
On Sat, Dec 07, 2024 at 10:13:11AM +0100, Oswald Buddenhagen wrote:
> On Fri, Dec 06, 2024 at 12:10:15PM +0100, Patrick Steinhardt wrote:
> > We use printf to set up sections with GitLab CI even though we could
> > trivially use echo.
> > 
> probably not a good idea, because the file is also included from plain
> sh scripts, which may invoke an `echo` that cannot deal with \escapes.
> at least potentially.

Ah, true.

> > This may cause problems in case the argument passed to `begin_group ()`
> > or `end_group ()` contains formatting directives as we use them as part
> > of the formatting string.
> > 
> that can be fixed properly by using the %s expando.

Yup, will do. Thanks!

Patrick
diff mbox series

Patch

diff --git a/ci/lib.sh b/ci/lib.sh
index a54601be923bf475ba1a9cafd98bb1cb71a10255..ba8f4da39caf29db5edaffde160bc81a7c58c329 100755
--- a/ci/lib.sh
+++ b/ci/lib.sh
@@ -18,7 +18,7 @@  elif test true = "$GITLAB_CI"
 then
 	begin_group () {
 		need_to_end_group=t
-		printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)[collapsed=true]\r\e[0K$1\n"
+		echo "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)[collapsed=true]\r\e[0K$1"
 		trap "end_group '$1'" EXIT
 		set -x
 	}
@@ -27,7 +27,7 @@  then
 		test -n "$need_to_end_group" || return 0
 		set +x
 		need_to_end_group=
-		printf "\e[0Ksection_end:$(date +%s):$(echo "$1" | tr ' ' _)\r\e[0K\n"
+		echo "\e[0Ksection_end:$(date +%s):$(echo "$1" | tr ' ' _)\r\e[0K"
 		trap - EXIT
 	}
 else