Skip to content
Open
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
67 changes: 53 additions & 14 deletions .github/workflows/test-breaking.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
base: 'specs/base.yaml'
revision: 'specs/revision-breaking.yaml'
output-to-file: 'breaking.txt'
github-token: ''
- name: Test breaking changes action output
env:
ACTUAL_OUTPUT: ${{ steps.test_breaking_changes.outputs.breaking }}
Expand Down Expand Up @@ -59,6 +60,7 @@ jobs:
revision: 'specs/revision-breaking-warn.yaml'
output-to-file: 'breaking.txt'
fail-on: 'ERR'
github-token: ''
- name: Test breaking changes action output
env:
ACTUAL_OUTPUT: ${{ steps.test_breaking_changes.outputs.breaking }}
Expand Down Expand Up @@ -93,6 +95,7 @@ jobs:
with:
base: 'specs/petstore-base.yaml'
revision: 'specs/petstore-revision.yaml'
github-token: ''
- name: Test breaking changes action output
env:
ACTUAL_OUTPUT: ${{ steps.test_breaking_changes_matching_delimiter_not_found.outputs.breaking }}
Expand All @@ -117,6 +120,7 @@ jobs:
base: 'specs/glob/base/*.yaml'
revision: 'specs/glob/revision/*.yaml'
composed: true
github-token: ''
- name: Test breaking action output
env:
ACTUAL_OUTPUT: ${{ steps.test_breaking_composed.outputs.breaking }}
Expand Down Expand Up @@ -146,6 +150,7 @@ jobs:
revision: specs/base-deprecation.yaml
deprecation-days-beta: 14
deprecation-days-stable: 21
github-token: ''
oasdiff_breaking_flatten_allof:
runs-on: ubuntu-latest
name: Test breaking action with flatten-allof option
Expand All @@ -161,6 +166,7 @@ jobs:
base: 'specs/base-allof.yaml'
revision: 'specs/revision-allof.yaml'
flatten-allof: true
github-token: ''
- name: Test breaking action output
env:
ACTUAL_OUTPUT: ${{ steps.test_breaking_flatten_allof.outputs.breaking }}
Expand All @@ -183,6 +189,7 @@ jobs:
base: 'specs/base.yaml'
revision: 'specs/revision-breaking.yaml'
err-ignore: 'specs/err-ignore.txt'
github-token: ''
- name: Test breaking changes are suppressed
env:
ACTUAL_OUTPUT: ${{ steps.test_breaking_err_ignore.outputs.breaking }}
Expand Down Expand Up @@ -218,6 +225,7 @@ jobs:
with:
base: 'specs/base.yaml'
revision: 'specs/revision-breaking.yaml'
github-token: ''
- name: Assert action failed (.oasdiff.yaml fail-on triggered) and report rendered
env:
ACTUAL_OUTPUT: ${{ steps.test_yaml_fail_on.outputs.breaking }}
Expand Down Expand Up @@ -252,6 +260,7 @@ jobs:
with:
base: 'specs/base.yaml'
revision: 'specs/revision-breaking.yaml'
github-token: ''
- name: Assert breaking changes were suppressed by .oasdiff.yaml
env:
ACTUAL_OUTPUT: ${{ steps.test_yaml_err_ignore.outputs.breaking }}
Expand Down Expand Up @@ -283,6 +292,7 @@ jobs:
with:
base: 'specs/base.yaml'
revision: 'specs/revision-breaking.yaml'
github-token: ''
- name: Assert the finding was downgraded by .oasdiff.yaml
env:
ACTUAL_OUTPUT: ${{ steps.test_yaml_severity_levels.outputs.breaking }}
Expand Down Expand Up @@ -312,6 +322,7 @@ jobs:
base: 'specs/base.yaml'
revision: 'specs/revision-breaking.yaml'
include-checks: 'not-a-real-check'
github-token: ''
- name: Assert the run was unaffected
env:
ACTUAL_OUTPUT: ${{ steps.test_include_checks.outputs.breaking }}
Expand Down Expand Up @@ -340,6 +351,7 @@ jobs:
base: 'specs/base.yaml'
revision: 'specs/revision-breaking.yaml'
exclude-elements: 'endpoints'
github-token: ''
- name: Assert the run was unaffected
env:
ACTUAL_OUTPUT: ${{ steps.test_exclude_elements.outputs.breaking }}
Expand Down Expand Up @@ -489,11 +501,12 @@ jobs:
oasdiff_breaking_comment_failure_names_the_fix:
runs-on: ubuntu-latest
name: Test a blocked PR comment says what to change
# A comment that cannot post is reported two different ways, because only
# one of them is actionable: a job without pull-requests:write gets a
# warning naming the permission, while a pull request from a fork gets a
# A comment that cannot post is reported three ways, because only one of
# them is the job's configuration: a job without pull-requests:write fails
# with an error naming the permission, a pull request from a fork gets a
# plain line, since GitHub makes the token read-only there whatever the
# job does. Both cases are also reported separately in the delivery mode.
# job does, and any other refusal (here a rate limit) only warns. Each case
# is also reported separately in the delivery event.
steps:
- uses: actions/checkout@v7
- name: Stub oasdiff + a rejecting curl, run with and without a fork event
Expand All @@ -519,19 +532,21 @@ jobs:
STUB
chmod +x /tmp/stub/oasdiff

# Rejects the comment with 403, the shape GitHub returns both for a
# missing permission and for a fork's read-only token.
# Rejects the comment with 403 and the message in /tmp/run/message:
# GitHub's message for a missing permission (also what a fork's
# read-only token gets), or a rate-limit message.
cat > /tmp/stub/curl <<'STUB'
#!/bin/sh
for a in "$@"; do
case "$prev" in -X) method=$a ;; esac
case "$prev" in -X) method=$a ;; -o) out=$a ;; esac
prev=$a
done
case " $* " in
*api/telemetry*) cat > /tmp/run/telemetry.json; exit 0 ;;
esac
if [ "${method:-GET}" = GET ]; then echo '[]'; exit 0; fi
cat > /dev/null
printf '{"message":"%s"}' "$(cat /tmp/run/message)" > "${out:-/dev/null}"
printf '403'
STUB
chmod +x /tmp/stub/curl
Expand All @@ -551,21 +566,45 @@ jobs:
'INPUT_GITHUB-TOKEN=fake-token' bash ./breaking/entrypoint.sh
}

echo "=== same-repo pull request: expect a warning naming the permission"
echo "=== same-repo pull request, missing permission: expect the step to fail naming the permission"
echo 'Resource not accessible by integration' > /tmp/run/message
printf '{"pull_request":{"head":{"repo":{"full_name":"acme/api"}}}}' > /tmp/run/event.json
out=$(run_entrypoint 2>&1)
rc=0; out=$(run_entrypoint 2>&1) || rc=$?
echo "$out" | grep -v '^flags:\|^running oasdiff'
if [ "$rc" -ne 1 ]; then
echo "FAIL: expected the step to fail with exit 1, got $rc" >&2
exit 1
fi
case "$out" in
*"::warning::oasdiff: couldn't post the review link"*"pull-requests: write"*) ;;
*) echo "FAIL: no warning naming the permission" >&2; exit 1 ;;
*"::error title=oasdiff couldn't post the PR comment::"*"pull-requests: write"*"github-token"*) ;;
*) echo "FAIL: no error naming the permission and the opt-out" >&2; exit 1 ;;
esac
mode=$(jq -r '.props.mode' < /tmp/run/telemetry.json)
if [ "$mode" != "comment_failed" ]; then
echo "FAIL: expected delivery mode 'comment_failed', got '$mode'" >&2
props=$(jq -c '.props | {mode, reason}' < /tmp/run/telemetry.json)
if [ "$props" != '{"mode":"comment_failed","reason":"http_403_permission"}' ]; then
echo "FAIL: unexpected delivery event: $props" >&2
exit 1
fi

echo "=== same-repo pull request, rate limited: expect a warning and a passing step"
echo 'You have exceeded a secondary rate limit' > /tmp/run/message
rc=0; out=$(run_entrypoint 2>&1) || rc=$?
echo "$out" | grep -v '^flags:\|^running oasdiff'
if [ "$rc" -ne 0 ]; then
echo "FAIL: a rate-limited comment must not fail the step, got exit $rc" >&2
exit 1
fi
case "$out" in
*"::warning::oasdiff: couldn't post the review link as a PR comment (HTTP 403)"*) ;;
*) echo "FAIL: no warning for the rate-limited comment" >&2; exit 1 ;;
esac
props=$(jq -c '.props | {mode, reason}' < /tmp/run/telemetry.json)
if [ "$props" != '{"mode":"comment_failed","reason":"http_403"}' ]; then
echo "FAIL: unexpected delivery event: $props" >&2
exit 1
fi

echo "=== fork pull request: expect a plain line and no warning"
echo 'Resource not accessible by integration' > /tmp/run/message
printf '{"pull_request":{"head":{"repo":{"full_name":"contrib/api-fork"}}}}' > /tmp/run/event.json
out=$(run_entrypoint 2>&1)
echo "$out" | grep -v '^flags:\|^running oasdiff'
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test-changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
base: https://raw.githubusercontent.com/oasdiff/oasdiff/main/data/openapi-test1.yaml
revision: https://raw.githubusercontent.com/oasdiff/oasdiff/main/data/openapi-test3.yaml
output-to-file: "changelog.txt"
github-token: ''
- name: Test changelog action output
run: |
output=$(echo "${{steps.test_changelog.outputs.changelog}}" | head -n 1)
Expand Down Expand Up @@ -54,6 +55,7 @@ jobs:
base: 'specs/glob/base/*.yaml'
revision: 'specs/glob/revision/*.yaml'
composed: true
github-token: ''
- name: Test changelog action output
env:
ACTUAL_OUTPUT: ${{ steps.test_changelog_composed.outputs.changelog }}
Expand All @@ -80,6 +82,7 @@ jobs:
with:
base: https://raw.githubusercontent.com/oasdiff/oasdiff/main/data/openapi-test1.yaml
revision: https://raw.githubusercontent.com/oasdiff/oasdiff/main/data/openapi-test3.yaml
github-token: ''
- name: Assert level filter from .oasdiff.yaml suppressed warning/info findings
run: |
# Without the YAML, the same specs produce "26 changes: 4 error, 4 warning, 18 info".
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
| `revision` | required | The revised (new) OpenAPI spec, in the same forms |
| `fail-on` | `''` | Fail the job when a change is at or above this severity: `ERR` or `WARN`, or `MISSING-VERSION-BUMP` to fail only when breaking changes come without a major version increase in `info.version`. Empty never fails. This is policy rather than a fact about the run: once you have a `.oasdiff.yaml`, set it there |
| `oasdiff-token` | `''` | Your oasdiff Pro token. See [Pro: Approve and gate changes](#pro-approve-and-gate-changes) |
| `github-token` | `${{ github.token }}` | Token used to post the comment. The default is the job's own token, so you only need to grant `permissions: pull-requests: write`. Set it to `''` to keep the review link in the job summary only |
| `github-token` | `${{ github.token }}` | Token used to post the comment. The default is the job's own token, so you only need to grant `permissions: pull-requests: write`. Without that permission the step fails with an error saying so. Set it to `''` to keep the review link in the job summary only |
| `review` | `true` | Upload the encrypted comparison and link to the side-by-side review. Set `false` so that no spec leaves CI; annotations and the job result are unaffected |
| `config` | `''` | Path to an oasdiff config file, when `.oasdiff.yaml` is not at the repository root |
| `output-to-file` | `''` | Also write the report to this file |
Expand Down
36 changes: 29 additions & 7 deletions breaking/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,17 @@ review_comment_changes () {
# or failed to post. This tells the maintainers how often users end up on the
# summary fallback, which is what drives fixes to the defaults. It carries no
# repo, organization, or user identity; action_ref is the action's own
# version tag. Best-effort with a 5 second cap, a failure never affects the
# run, and it is skipped when OASDIFF_INTERNAL=1 (the marker the CLI also
# uses for internal test runs).
# version tag, and reason is GitHub's HTTP status when the comment failed.
# Best-effort with a 5 second cap, a failure never affects the run, and it is
# skipped when OASDIFF_INTERNAL=1 (the marker the CLI also uses for internal
# test runs).
report_review_delivery () {
delivery_mode="$1"
delivery_reason="${2:-}"
[ "${OASDIFF_INTERNAL:-}" = "1" ] && return 0
printf '{"event":"review_delivery","props":{"mode":"%s","platform":"github-action","action_ref":"%s"}}' "$delivery_mode" "${GITHUB_ACTION_REF:-unknown}" | curl -s -m 5 -o /dev/null -X POST -H "Content-Type: application/json" "https://www.oasdiff.com/api/telemetry" --data-binary @- 2>/dev/null || true
jq -nc --arg mode "$delivery_mode" --arg ref "${GITHUB_ACTION_REF:-unknown}" --arg reason "$delivery_reason" \
'{event: "review_delivery", props: ({mode: $mode, platform: "github-action", action_ref: $ref} + (if $reason == "" then {} else {reason: $reason} end))}' \
| curl -s -m 5 -o /dev/null -X POST -H "Content-Type: application/json" "https://www.oasdiff.com/api/telemetry" --data-binary @- 2>/dev/null || true
}

post_review_comment () {
Expand Down Expand Up @@ -226,10 +230,17 @@ $(review_comment_changes "${changes_json:-}" "$review_url")
method="POST"
fi

code=$(printf '%s' "$payload" | curl -s -o /dev/null -w "%{http_code}" -X "$method" \
response=$(mktemp)
code=$(printf '%s' "$payload" | curl -s -o "$response" -w "%{http_code}" -X "$method" \
-H "Authorization: token $github_token" \
-H "Accept: application/vnd.github+json" \
"$endpoint" --data-binary @- 2>/dev/null) || code="000"
# GitHub answers a token without pull-requests: write with this message. A
# 403 for a secondary rate limit says something else, and is not the
# job's configuration.
missing_permission=""
grep -q "Resource not accessible by integration" "$response" 2>/dev/null && missing_permission=1
rm -f "$response"

if [ "$code" -ge 200 ] && [ "$code" -lt 300 ]; then
[ -n "$review_url" ] && report_review_delivery "comment"
Expand All @@ -240,8 +251,16 @@ $(review_comment_changes "${changes_json:-}" "$review_url")
[ -n "$review_url" ] && report_review_delivery "comment_fork"
echo "oasdiff: this pull request comes from a fork, where GitHub makes the token read-only, so the review link is in the job summary instead of a comment."
else
[ -n "$review_url" ] && report_review_delivery "comment_failed"
echo "::warning::oasdiff: couldn't post the review link as a PR comment (HTTP ${code}). Add 'permissions: pull-requests: write' to the job that runs this action. The link is in the job summary meanwhile."
[ -n "$review_url" ] && report_review_delivery "comment_failed" "http_${code}${missing_permission:+_permission}"
if [ -n "$missing_permission" ] && [ -n "$review_url" ]; then
# A warning on a passing job is never read, so the step fails (in
# finish) until the job grants the permission or opts out of the
# comment.
review_comment_blocked=1
echo "::error title=oasdiff couldn't post the PR comment::GitHub refused the comment (HTTP 403) because the job's token can't write to pull requests. Add 'permissions: pull-requests: write' to the job that runs this action, or set 'github-token: \"\"' on the action to keep the review link in the job summary only."
else
echo "::warning::oasdiff: couldn't post the review link as a PR comment (HTTP ${code}). The link is in the job summary."
fi
fi
}

Expand Down Expand Up @@ -452,6 +471,9 @@ finish () {
code=0
fi
fi
if [ -n "${review_comment_blocked:-}" ]; then
code=1
fi
exit "$code"
}

Expand Down
Loading