Skip to content

Commit 5ddae1b

Browse files
Fix doc-snippet version query for sbt 2.x
`just test-snippets` derived the chimney version with an unfiltered `$(sbt -batch -error 'print chimney/version')`. Under sbt 2.x `-error` no longer suppresses the terminal control output, so that captured the version PLUS leaked ANSI escapes (`\e[0J`) and a trailing `[success] elapsed time` line - a polluted string that broke scala-cli dependency resolution and thus every snippet. Query with a non-client sbt, strip ANSI, then grep the version out (and guard for empty), and publish with `sbt --client`. This mirrors how kindlings/hearth solved the same issue. Keep the sbt call and the grep pipeline as separate `|| true` statements so `set -euo pipefail` can't abort on a grep no-match / head SIGPIPE. Verified locally on sbt 2.0.2: version resolves to a clean `2.0.0-M4-1-gca22d63-SNAPSHOT` and all documentation snippets pass.
1 parent 83bf4dc commit 5ddae1b

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

docs/Justfile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,22 @@ serve: build
55
docker run --rm -it -p 8000:8000 -v ${PWD}:/docs --env "CI_LATEST_TAG=$(git describe --tags)" mkdocs-chimney-docs
66

77
test-snippets:
8-
cd .. && sbt publish-local-for-tests
9-
cd .. && scala-cli run scripts/test-snippets.scala -- --extra "chimney-version=$(sbt -batch -error 'print chimney/version')" "$PWD/docs/docs"
8+
#!/usr/bin/env bash
9+
set -euo pipefail
10+
cd ..
11+
sbt --client "publish-local-for-tests"
12+
# sbt 2.x leaks ANSI escapes and a trailing `[success] elapsed time` line into `-error` output, so the
13+
# old unfiltered `$(sbt -batch -error 'print chimney/version')` fed a polluted version to scala-cli and
14+
# broke snippet dependency resolution. Query with a NON-client sbt (the `--client` thin client does not
15+
# write `print` results to captured stdout in a non-TTY), strip ANSI, then grep out the version. Keep the
16+
# sbt call and the pipeline as SEPARATE `|| true` statements so `set -euo pipefail` (grep no-match -> 1,
17+
# head SIGPIPE -> 141) cannot abort before the guard. Mirrors how kindlings/hearth query their versions.
18+
raw="$(sbt -batch -error 'print chimney/version' 2>&1 || true)"
19+
chimney_version="$(printf '%s\n' "${raw}" | sed -E 's/\x1b\[[0-9;?]*[A-Za-z]//g' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+[A-Za-z0-9.+-]*' | head -1 || true)"
20+
if [ -z "${chimney_version}" ]; then
21+
echo "ERROR: could not determine chimney version. sbt output was:" >&2
22+
printf '%s\n' "${raw}" >&2
23+
exit 1
24+
fi
25+
echo "Using chimney-version=${chimney_version}"
26+
scala-cli run scripts/test-snippets.scala -- --extra "chimney-version=${chimney_version}" "$PWD/docs/docs"

scripts/test-snippets.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ class ChimneyExtendedRunner(runner: Runner)(
100100
*
101101
* on CI:
102102
* {{{
103-
* # run all tests, use artifacts published locally from current tag
104-
* scala-cli run scripts/test-snippets.scala -- --extra "chimney-version=$(sbt -batch -error 'print chimney/version')" "$PWD/docs/docs"
103+
* # run all tests, use artifacts published locally from current tag (see docs/Justfile `test-snippets`)
104+
* # NB: under sbt 2.x `print chimney/version` leaks ANSI + a `[success]` line, so strip/grep the version out:
105+
* sbt --client "publish-local-for-tests"
106+
* raw="$(sbt -batch -error 'print chimney/version' 2>&1 || true)"
107+
* chimney_version="$(printf '%s\n' "$raw" | sed -E 's/\x1b\[[0-9;?]*[A-Za-z]//g' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+[A-Za-z0-9.+-]*' | head -1)"
108+
* scala-cli run scripts/test-snippets.scala -- --extra "chimney-version=$chimney_version" "$PWD/docs/docs"
105109
* }}}
106110
*
107111
* during development:

0 commit comments

Comments
 (0)