Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/test-changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions breaking/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading