Repository navigation
Show a diff when githubWorkflowCheck finds a mismatch - #236
Merged
Merged
Conversation
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>
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.
When
githubWorkflowCheckfinds 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 ownci.ymlthat is over 300 lines, and the one line that matters is somewhere in the second half: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:
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.Consolecodes. 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
githubWorkflowCheckon a real mismatch, thetar chfline from #234 reverted in this repo'sci.yml:-Dsbt.color=falsescript)[error][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
diffspecs described the caret output, so they are replaced withGenerativePluginSpeccases 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+scriptedpass.🤖 Generated with Claude Code