From a18cc5f182815577c4ae680f650c2989b7d8957b Mon Sep 17 00:00:00 2001 From: monsieurleberre Date: Thu, 5 Nov 2026 11:55:48 -0300 Subject: [PATCH] fix(scala-ci): cache the sbt launcher at a stable path instead of setup-sbt (#124) --- .github/workflows/scala-ci.yaml | 52 +++++++++++++++++++++++++++++++-- CHANGELOG.md | 4 +++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scala-ci.yaml b/.github/workflows/scala-ci.yaml index 304ffc8..c5f0705 100644 --- a/.github/workflows/scala-ci.yaml +++ b/.github/workflows/scala-ci.yaml @@ -219,6 +219,9 @@ jobs: permissions: contents: read pull-requests: write + env: + SBT_LAUNCHER_VERSION: 2.0.12 + SBT_LAUNCHER_SHA256: 73f9c4a10584cde3d37d773e2b38d2fc4348c6cef8d88da8b7dd41e7d5f614d7 defaults: run: shell: bash @@ -250,8 +253,53 @@ jobs: restore-keys: | ${{ runner.os }}-sbt- - - name: Setup sbt - uses: sbt/setup-sbt@b113b960ba361e87e08ce02a390d51871b7ee459 # v1.5.13 + - name: Restore sbt launcher + id: sbt-launcher-cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/.cache/sbt-launcher + key: sbt-launcher-${{ runner.os }}-${{ runner.arch }}-${{ env.SBT_LAUNCHER_VERSION }} + + - name: Download sbt launcher + if: steps.sbt-launcher-cache.outputs.cache-hit != 'true' + run: | + set -euo pipefail + archive="$RUNNER_TEMP/sbt-${SBT_LAUNCHER_VERSION}.zip" + curl --fail --location --silent --show-error \ + --connect-timeout 15 --max-time 180 \ + --output "$archive" \ + "https://github.com/sbt/sbt/releases/download/v${SBT_LAUNCHER_VERSION}/sbt-${SBT_LAUNCHER_VERSION}.zip" + if command -v sha256sum >/dev/null 2>&1; then + actual=$(sha256sum "$archive" | cut -d ' ' -f 1) + else + actual=$(shasum -a 256 "$archive" | cut -d ' ' -f 1) + fi + if [ "$actual" != "$SBT_LAUNCHER_SHA256" ]; then + echo "::error::sbt-${SBT_LAUNCHER_VERSION}.zip SHA-256 is ${actual}, expected ${SBT_LAUNCHER_SHA256}" + exit 1 + fi + rm -rf "$HOME/.cache/sbt-launcher" + mkdir -p "$HOME/.cache/sbt-launcher" + unzip -q "$archive" -d "$HOME/.cache/sbt-launcher" + test -f "$HOME/.cache/sbt-launcher/sbt/bin/sbt" + + - name: Save sbt launcher + if: steps.sbt-launcher-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/.cache/sbt-launcher + key: sbt-launcher-${{ runner.os }}-${{ runner.arch }}-${{ env.SBT_LAUNCHER_VERSION }} + + - name: Add sbt launcher to PATH + run: | + set -euo pipefail + launcher_bin="$HOME/.cache/sbt-launcher/sbt/bin" + test -f "$launcher_bin/sbt" + if [ "$RUNNER_OS" = "Windows" ]; then + cygpath -w "$launcher_bin" >> "$GITHUB_PATH" + else + echo "$launcher_bin" >> "$GITHUB_PATH" + fi - name: Build, test, coverage report env: diff --git a/CHANGELOG.md b/CHANGELOG.md index 585305f..d860810 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- `scala-ci.yaml` no longer fetches sbt on every run on ephemeral runners. It replaces `sbt/setup-sbt`, whose caches are keyed on `$RUNNER_TOOL_CACHE` (a path that differs per job on ephemeral runners, so they never hit) and whose cache miss bootstraps `ampel` from GitHub releases, where the provenance fetch could time out and fail the job. It now restores the sbt launcher from `actions/cache` at the fixed path `~/.cache/sbt-launcher`, keyed on runner OS, architecture and launcher version, and on a miss downloads `sbt-2.0.12.zip` from the sbt GitHub release with `curl --fail --location` and connect and total timeouts, checks it against a pinned SHA-256 (the job fails on a mismatch, on every runner OS, where `setup-sbt` verified the signature on Linux only), unpacks it and saves the cache. The launcher is still 2.0.12 and the sbt version a build runs is still controlled by `project/build.properties`. No input, output or secret changes. `setup-sbt`'s sbt 2.x disk cache (`~/.cache/sbt`) is no longer restored; builds on sbt 1.x never used it, and the existing `Cache sbt` step is unchanged. + ## [2.8.0] - 2026-11-02 ### Changed