Fix generated workflow varying with the Scala version under sbt 2 - #233
Merged
Merged
Conversation
Member
|
Thanks for the contribution! |
eed3si9n
reviewed
Sep 4, 2026
sbt 2 lays a project's target out as
`target/out/<platform>/scala-<scalaVersion>/<module>`, so with plain
`crossScalaVersions` only the currently loaded version's directory
exists. `internalTargetAggregation` picked that path up verbatim, which
made the generated "Compress target directories" step depend on the
`++` version the workflow happened to be generated at:
at 2.13.10 -> tar cf targets.tar target/out/jvm/scala-2.13.10/root ... project/target
at 2.12.17 -> tar cf targets.tar target/out/jvm/scala-2.12.17/root ... project/target
CI runs `githubWorkflowCheck` once per matrix row with a different `++`,
so no single committed ci.yml could satisfy more than one row.
Aggregate the nearest ancestor that is not scoped to a Scala version
instead, i.e. `target/out/<platform>`. Targets which are already
independent of the Scala version are returned unchanged: sbt 1's
`<project>/target`, and sbt 2's `target/out/<platform>/u/<module>`,
which is the layout used when `crossPaths` is `false`.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
nafg
force-pushed
the
fix-sbt2-cross-scala-target-aggregation
branch
from
September 4, 2026 05:53
6184b86 to
9493953
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(ai generated)
Problem
Under sbt 2, a project's
targetistarget/out/<platform>/scala-<scalaVersion>/<module>rather than sbt 1's version-independent<project>/target.GenerativePluginfeedstarget.valuestraight intointernalTargetAggregation, which is rendered into the Compress target directories step. In a build using plaincrossScalaVersions, only the currently loaded Scala version's directory exists, so the generatedci.ymldepends on which++sbt happened to be at whengithubWorkflowGenerateran:The generated workflow runs
sbt ++<scala> githubWorkflowCheckonce per matrix row, so whichever version the committed file was generated at, every other row fails with "ci.yml does not contain contents that would have been generated by sbt-github-actions". There is no committed file that satisfies a multi-Scala matrix.projectMatrixbuilds are not affected — every row is materialised as a real project, so all of the paths are enumerated regardless of++. Only plaincrossScalaVersionsbuilds hit this. sbt 1 is not affected at all.Fix
Aggregate the nearest ancestor of
targetthat is not scoped to a Scala version —target/out/<platform>— instead of the version-scoped directory itself:An sbt 1
<project>/targetcontains noscala-<scalaVersion>directory, so it is returned unchanged and sbt 1 output is byte-identical to before.internalTargetAggregationis now de-duplicated inpathStrs, since under sbt 2 every project of a build collapses onto the same aggregated path.The artifact contract with the publish job is preserved: each matrix row still uploads a tarball rooted at the repository root, and
githubWorkflowGeneratedDownloadStepsstill just runstar xf targets.tarper Scala version. Because each row only ever builds one Scala version, its tarball still contains onlytarget/out/<platform>/scala-<that version>/…, so inflating all of them in the publish job reconstitutes the same tree as before.Caveat worth a maintainer's opinion
Under sbt 2,
githubWorkflowArtifactUpload := falseon a subproject no longer excludes that subproject's output from the tarball, because all projects sharetarget/out/<platform>. Excluding it would require naming the version-scoped directories again, which is exactly what causes the bug. The setting still works as before at the build level and under sbt 1. Happy to take this a different direction if you'd prefer something narrower.Tests
src/sbt-test/sbtghactions/cross-scala-version-stability— new scripted test: generate at the default Scala version,++to the othercrossScalaVersionsentry, andgithubWorkflowCheckagain. It fails onmainunder sbt 2 and passes under sbt 1 and 2 with this change.GenerativePluginSpec— three unit examples covering the newscalaVersionIndependentTargethelper, including that sbt 1 style targets are returned untouched.patchIfSbt2helper tasks in the existing scripted tests are updated to the new expected sbt 2 path.+testand+scriptedare green (sbt 1.5.5/Scala 2.12.20 and sbt 2.0.0/Scala 3.8.4).