From 2d150fb128faa322d7cd6a079560b1427c650c91 Mon Sep 17 00:00:00 2001 From: Reuven Harrison Date: Sun, 15 Nov 2026 20:03:25 +0200 Subject: [PATCH] Annotate errors and warnings from the changelog action Only breaking wrote inline annotations, so a changelog workflow, which is what the Pro example used, put nothing on the Files changed tab. changelog now writes them for the changes at error and warning level. Info changes are left out: a changelog can hold one per added property. The annotation format also writes error_count, warning_count and info_count to GITHUB_OUTPUT. This action does not declare those outputs and its info_count would be wrong with info filtered out, so that file is pointed away for this one render. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/test-changelog.yaml | 56 +++++++++++++++++++++++++++ README.md | 2 +- breaking/entrypoint.sh | 11 ++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-changelog.yaml b/.github/workflows/test-changelog.yaml index 6a3f7a0..e46e373 100644 --- a/.github/workflows/test-changelog.yaml +++ b/.github/workflows/test-changelog.yaml @@ -427,3 +427,59 @@ jobs: echo "Expected the step to fail: .oasdiff.yaml sets fail-on: ERR. Got: ${{ steps.test_yaml_fail_on.outcome }}" >&2 exit 1 fi + + oasdiff_changelog_annotations: + runs-on: ubuntu-latest + name: Test changelog action annotates errors and warnings, not info + # The changelog action writes the same inline annotations as breaking, for + # the changes at error and warning level. Info changes are left out, since + # a changelog can hold one per added property. Stubs oasdiff to emit one + # annotation at each level. + steps: + - uses: actions/checkout@v7 + - name: Stub oasdiff, run entrypoint + run: | + set -euo pipefail + mkdir -p /tmp/stub /tmp/run + + cat > /tmp/stub/oasdiff <<'STUB' + #!/bin/sh + for a in "$@"; do + case "$a" in + json) printf '[]'; exit 0 ;; + githubactions) + echo "::error title=an-error,file=openapi.yaml,line=3::in API GET /a broke" + echo "::warning title=a-warning,file=openapi.yaml,line=4::in API GET /a may break" + echo "::notice title=an-info,file=openapi.yaml,line=5::in API GET /a changed" + # this format reports counts through GITHUB_OUTPUT + echo "info_count=1" >> "$GITHUB_OUTPUT" + exit 0 ;; + esac + done + echo "3 changes: 1 error, 1 warning, 1 info" + STUB + chmod +x /tmp/stub/oasdiff + + export GITHUB_REF=refs/pull/123/merge + export GITHUB_REPOSITORY=acme/widgets + export GITHUB_OUTPUT=/tmp/run/out; : > "$GITHUB_OUTPUT" + export GITHUB_STEP_SUMMARY=/tmp/run/summary; : > "$GITHUB_STEP_SUMMARY" + export PATH=/tmp/stub:$PATH + + out=$(env OASDIFF_ACTION_COMMAND=changelog INPUT_BASE=b INPUT_REVISION=r INPUT_REVIEW=false \ + bash ./breaking/entrypoint.sh 2>&1) + echo "$out" + + for expected in '::error title=an-error' '::warning title=a-warning'; do + case "$out" in + *"$expected"*) ;; + *) echo "FAIL: missing annotation: $expected" >&2; exit 1 ;; + esac + done + case "$out" in + *'::notice title=an-info'*) echo "FAIL: an info change was annotated" >&2; exit 1 ;; + esac + if grep -q "info_count" "$GITHUB_OUTPUT"; then + echo "FAIL: the annotation format's counts leaked into the action's outputs" >&2; exit 1 + fi + echo "PASS" diff --git a/README.md b/README.md index 7ed1920..41780ec 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ jobs: ### Generate a changelog -Outputs the changes that can affect API consumers (breaking and non-breaking) between two specs. Documentation-only edits, such as descriptions and examples, are not included; use the [diff action](#generate-a-diff-report) to see every difference in the API definition. When changes are found it also uploads the comparison and links to a full side-by-side review (the `review` input, on by default); the two specs are encrypted in CI before upload, so the server cannot read them. The changes and the link are posted as a pull-request comment when you pass `github-token` (and grant `pull-requests: write`); otherwise, and on fork PRs where the token is read-only, the link falls back to the job summary. +Outputs the changes that can affect API consumers (breaking and non-breaking) between two specs, and writes inline annotations on the pull request's Files changed tab for the ones at error and warning level. Documentation-only edits, such as descriptions and examples, are not included; use the [diff action](#generate-a-diff-report) to see every difference in the API definition. When changes are found it also uploads the comparison and links to a full side-by-side review (the `review` input, on by default); the two specs are encrypted in CI before upload, so the server cannot read them. The changes and the link are posted as a pull-request comment when you pass `github-token` (and grant `pull-requests: write`); otherwise, and on fork PRs where the token is read-only, the link falls back to the job summary. ```yaml name: oasdiff diff --git a/breaking/entrypoint.sh b/breaking/entrypoint.sh index 14e77af..045f434 100755 --- a/breaking/entrypoint.sh +++ b/breaking/entrypoint.sh @@ -699,6 +699,17 @@ run_changelog () { fi rm -f "$_err" + # Inline annotations for the error and warning changes, on the lines they + # are on, as the breaking action writes them. Info changes are filtered + # out: a changelog can hold one per added property, and a notice for each + # would bury the ones that matter. The format also writes error_count, + # warning_count and info_count to GITHUB_OUTPUT, which this action does + # not declare, so that is pointed away. --template= overrides a 'template' + # set in .oasdiff.yaml, which this format rejects. + # shellcheck disable=SC2086 # the flags variables hold multiple arguments; splitting is intended + GITHUB_OUTPUT=/dev/null oasdiff changelog "$base" "$revision" $flags --format githubactions --template= 2>/dev/null \ + | grep -v '^::notice' || true + # One json render answers two questions, how many changes there are and what # they are, so the count below and the PR comment read the same data. The # user-facing $output cannot be parsed for either: it varies by format