scala-steward-org / scala-steward

:robot: A bot that helps you keep your projects up-to-date
Apache License 2.0
1.15k stars 496 forks source link

`tput: command not found` in scalafmt post-update hook #3120

Closed esamson closed 11 months ago

esamson commented 1 year ago

I noticed this bash error when there's a scalafmt update.

2023-07-14 22:55:26,512 INFO  Process update org.scalameta:(scalafmt-core, scalafmt-core_2.13) : 3.7.7 -> 3.7.9
2023-07-14 22:55:27,102 INFO  Create branch update/scalafmt-core-3.7.9
2023-07-14 22:55:33,676 INFO  Executing post-update hook for org.scalameta:scalafmt-core with command 'scalafmt --non-interactive'
bash: line 1: tput: command not found
2023-07-14 22:55:37,439 INFO  Push 1 commit(s)
2023-07-14 22:55:39,050 INFO  Create PR update/scalafmt-core-3.7.9
fthomas commented 1 year ago

I've some questions.

Do you get the same output if you run scalafmt --non-interactive yourself? How do you run Scala Steward? Who installed that scalafmt that Scala Steward calls? This line bash: line 1: tput: command not found looks strange since Scala Steward does not just dump the output of external processes to its log or stdout. Is this reproducible? If yes, does running Scala Steward with TRACE log level give more clues? Searching the internet for "tput: command not found" yields some results. Did they help narrowing this issue or giving some clues?

esamson commented 1 year ago

Running scalafmt --non-interactive myself doesn't output that line.

I run the docker image using podman against a gitea instance with this script:

#!/usr/bin/env bash

DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
IMAGE=fthomas/scala-steward:latest
NAME="Scala Steward"
EMAIL=steward@gitea.at.home
LOGIN=me

mkdir -p "$DIR/workspace"

podman run \
    --volume $DIR:/opt/scala-steward:Z \
    --interactive \
    --tty \
    $IMAGE \
        --workspace  "/opt/scala-steward/workspace" \
        --repos-file "/opt/scala-steward/repos.md" \
        --git-author-name "${NAME}" \
        --git-author-email ${EMAIL} \
        --git-ask-pass "/opt/scala-steward/askpass.sh" \
        --forge-type gitea \
        --forge-api-host "https://gitea.at.home/api/v1" \
        --forge-login ${LOGIN} \
        --do-not-fork

It is reproducible. TRACE logs don't add much. I guess it does point to the scalafmt --non-interactive invocation.

2023-07-24 03:06:23,326 INFO  Executing post-update hook for org.scalameta:scalafmt-core with command 'scalafmt --non-interactive'
2023-07-24 03:06:23,328 DEBUG Execute scalafmt --non-interactive
2023-07-24 03:06:25,274 TRACE Reformatting...
bash: line 1: tput: command not found
2023-07-24 03:06:26,313 TRACE Reformatting...
2023-07-24 03:06:27,366 TRACE

My searches lead me to think it has something to do with using alpine as the base docker image and tput not being available there.

fthomas commented 1 year ago

Thanks for your investigation! I think you're spot on with tput not being available in the Docker image. Scalafmt uses it in https://github.com/scalameta/scalafmt/blob/bf26e016f2d47e0634e0f49b699634be2e9be628/scalafmt-cli/src/main/scala/org/scalafmt/cli/TermDisplay.scala#L34.

There are a couple of options how we could handle this: