Skip to content

Show a diff when githubWorkflowCheck finds a mismatch - #236

Merged
eed3si9n merged 1 commit into
sbt:mainfrom
nafg:colored-workflow-diff
Oct 21, 2026
Merged

eed3si9n merged 1 commit into
sbt:mainfrom
nafg:colored-workflow-diff

Conversation

@nafg

@nafg nafg commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

When githubWorkflowCheck finds that a workflow file is out of date, it logs the whole generated workflow, then the whole file on disk with a caret under the first character that differs. For this repo's own ci.yml that is over 300 lines, and the one line that matters is somewhere in the second half:

[error] Expected:
[error] # This file was automatically generated by sbt-github-actions using the
… 155 more lines: the whole generated ci.yml …
[error] Actual:
[error] # This file was automatically generated by sbt-github-actions using the
… 81 more lines …
[error]       - name: Compress target directories
[error]         shell: bash
[error]         run: tar cf targets.tar target project/target
[error]                   ^ (different character)
[error] 
… 70 more lines: the rest of the file …
[error] java.lang.RuntimeException: ci.yml does not contain contents that would have been generated by sbt-github-actions; try running githubWorkflowGenerate

To see what the generated line should be, you have to find the same spot in the first copy. The second copy comes from diff, which compared the two files line by line by position, marked only the first difference, and printed the rest of the file as is.

Fix

Log a line diff of the file on disk against the generated workflow instead, as unified diff hunks with three lines of context. Removed lines are red, added lines green, hunk headers cyan. On the same mismatch:

[error] Differences between ci.yml (-) and the generated workflow (+):
[error] @@ -82,7 +82,7 @@
[error]  
[error]        - name: Compress target directories
[error]          shell: bash
[error] -        run: tar cf targets.tar target project/target
[error] +        run: tar chf targets.tar target project/target
[error]  
[error]        - name: Upload target directories
[error]          uses: actions/upload-artifact@v7
[error] java.lang.RuntimeException: ci.yml does not contain contents that would have been generated by sbt-github-actions; try running githubWorkflowGenerate

The diff is a longest-common-subsequence line diff, written out in GenerativePlugin, so there is no new dependency. Lines are compared with their line terminators, so a missing final newline or CRLF line endings still show up as a changed line.

The colors are plain scala.Console codes. sbt's console appender (Appender.write, the same in sbt 1.5.5 and 2.0.0) strips color codes from a message when color is disabled, so the diff is colored exactly when sbt colors its own [error] labels, by sbt's rule (-Dsbt.color, -Dsbt.log.noformat, whether the output is a terminal). The plugin doesn't decide anything itself.

When the file pins actions by commit hash, the comparison has always used a copy of the file with each hash replaced by the expected tag. The diff is computed on that copy too, so such lines appear in context with the tag rather than the hash.

Verification

Ran githubWorkflowCheck on a real mismatch, the tar chf line from #234 reverted in this repo's ci.yml:

sbt 1.12.2 sbt 2.0.0 (thin client)
output redirected to a file plain diff, as above plain diff
-Dsbt.color=false plain diff, identical to the above –
on a terminal (script) red / green / cyan, along with sbt's red [error] red / green / cyan, along with sbt's red [error]

Under sbt 2, a server started by an earlier invocation whose output was redirected kept that no-color setting for a later run on a terminal, and sbt's own [error] label was uncolored too. The diff followed sbt in that case as well.

The three old diff specs described the caret output, so they are replaced with GenerativePluginSpec cases for a changed line with context, missing and added lines, separate hunks, a missing final newline and equal contents, plus one for the colors. githubWorkflowCheck, +test (87 examples on each of sbt 1 and sbt 2) and +scripted pass.

🤖 Generated with Claude Code

On a mismatch, githubWorkflowCheck logged the whole generated workflow,
then the whole file on disk with a caret under the first character that
differs. Finding the change meant scrolling through both copies, and the
output never showed what the generated line should be.

Log only the differing lines instead, as unified diff hunks with three
lines of context, removed lines in red and added lines in green. sbt's
console appender strips the colors when color is disabled or the output
doesn't support it, by the same rule it uses for its own colors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@eed3si9n eed3si9n left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@eed3si9n
eed3si9n merged commit c62aa65 into sbt:main Oct 21, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants