Skip to content

Commit

Permalink
Output a summary and not an annotation
Browse files Browse the repository at this point in the history
An original implementation of this used annotations, rather job
summaries but these don't really work that well.

We can't comment on files which have changed outside of the diff, so the
output is mostly shown in the log output or the autogenerated job
summary. Instead, we assemble a custom output which is much nicer.

https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/
https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary
  • Loading branch information
nickcharlton committed Feb 17, 2024
1 parent 4f99a35 commit dc07c5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions bin/diff-check
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

set -e

message="has changed"

if ! git diff-index --quiet HEAD; then
printf 'These files changed when running the command:\n\n'

git diff --name-only | while read -r n ; do
echo "::error file=$n::$n $message"
echo "* $n"
done

exit 1
Expand Down
10 changes: 7 additions & 3 deletions spec/black_box/diff-check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
end

context "with a file change" do
it "emits a annotation with the file" do
it "emits a summary with the files changed" do
session = create_session

session.run("echo 'new text' >> README")

expect(session.run("diff-check")).
to have_stdout("::error file=README::README has changed\n")
expect(session.run("diff-check")).to have_stdout(<<~SUMMARY
These files changed when running the command:
* README
SUMMARY
)
end

it "exits with a status of 1" do
Expand Down

0 comments on commit dc07c5a

Please sign in to comment.