-
Notifications
You must be signed in to change notification settings - Fork 2k
ci: add breaking change detector #21499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rluvaton
wants to merge
25
commits into
apache:main
Choose a base branch
from
rluvaton:automate-semver-breaking-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+246
−0
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d128c07
ci: add breaking change detector
rluvaton 968fc57
ci: run manually for now
rluvaton 3500fee
add to existing ci job so i can test the workflow
rluvaton b0f7cdf
add permission
rluvaton dcb3cfc
try running
rluvaton 8ec278a
fetch main
rluvaton e15d6a7
run on all branches
rluvaton 129e180
run on changed crates
rluvaton 0a863bd
only if changed
rluvaton b3b6dde
compare against last commit
rluvaton 95189de
test: add temporary public function for semver breaking change testing
rluvaton 97ee5b5
test: remove public function to trigger semver breaking change
rluvaton d5b1985
fix
rluvaton 910501c
test: re-add temporary public function for semver testing
rluvaton f40c07a
test: remove public function to trigger semver breaking change
rluvaton 65779f4
fix
rluvaton 6de3a14
test: re-add temporary public function for semver testing
rluvaton 1bd00c2
test: remove public function to trigger semver breaking change
rluvaton b3bf244
revert
rluvaton 5286bab
Merge branch 'main' into automate-semver-breaking-api
rluvaton 10847a0
add coments
rluvaton 6d27da4
Merge remote-tracking branch 'origin/automate-semver-breaking-api' in…
rluvaton a903cae
add license
rluvaton 83a2f39
Merge branch 'main' into automate-semver-breaking-api
rluvaton 8d99fba
use script instead
rluvaton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| # Detect semver-incompatible (breaking) API changes in crates modified by a PR. | ||
| # | ||
| # Only public workspace crates that have file changes are checked. | ||
| # Internal crates (benchmarks, test-utils, sqllogictest, doc) are excluded. | ||
| # | ||
| # If breaking changes are found, a sticky comment is posted on the PR. | ||
| # The comment is removed automatically once the issues are resolved. | ||
|
|
||
| name: "Detect breaking changes" | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| check-semver: | ||
| name: Check semver | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| logs: ${{ steps.check_semver.outputs.logs }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| # For fork PRs, `origin` points to the fork, not the upstream repo. | ||
| # Explicitly fetch the base branch from the upstream repo so we have | ||
| # a valid baseline ref for both diff and semver-checks. | ||
| - name: Fetch base branch | ||
| env: | ||
| BASE_REF: ${{ github.base_ref }} | ||
| REPO: ${{ github.repository }} | ||
| run: git fetch "https://github.com/${REPO}.git" "${BASE_REF}:refs/remotes/origin/${BASE_REF}" | ||
|
|
||
| - name: Determine changed crates | ||
| id: changed_crates | ||
| env: | ||
| BASE_REF: ${{ github.base_ref }} | ||
| run: | | ||
| PACKAGES=$(ci/scripts/changed_crates.sh changed-crates "origin/${BASE_REF}") | ||
| echo "packages=$PACKAGES" >> "$GITHUB_OUTPUT" | ||
| echo "Changed crates: $PACKAGES" | ||
|
|
||
| - name: Install cargo-semver-checks | ||
| if: steps.changed_crates.outputs.packages != '' | ||
| run: cargo install cargo-semver-checks | ||
|
|
||
| - name: Run cargo-semver-checks | ||
| id: check_semver | ||
| if: steps.changed_crates.outputs.packages != '' | ||
| env: | ||
| BASE_REF: ${{ github.base_ref }} | ||
| PACKAGES: ${{ steps.changed_crates.outputs.packages }} | ||
| run: | | ||
| set +e | ||
| OUTPUT=$(ci/scripts/changed_crates.sh semver-check "origin/${BASE_REF}" $PACKAGES) | ||
| EXIT_CODE=$? | ||
| echo "logs<<EOF" >> "$GITHUB_OUTPUT" | ||
| echo "$OUTPUT" >> "$GITHUB_OUTPUT" | ||
| echo "EOF" >> "$GITHUB_OUTPUT" | ||
| exit $EXIT_CODE | ||
|
|
||
| # Post or remove a sticky comment on the PR based on the semver check result. | ||
| comment-on-pr: | ||
| name: Comment on pull request | ||
| runs-on: ubuntu-latest | ||
| needs: check-semver | ||
| if: always() | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| sparse-checkout: ci/scripts | ||
|
|
||
| - name: Update PR comment | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| REPO: ${{ github.repository }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| CHECK_RESULT: ${{ needs.check-semver.result }} | ||
| SEMVER_LOGS: ${{ needs.check-semver.outputs.logs }} | ||
| run: | | ||
| ci/scripts/changed_crates.sh comment \ | ||
| "$REPO" "$PR_NUMBER" "$CHECK_RESULT" "$SEMVER_LOGS" | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| #!/usr/bin/env bash | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| # Helper script for the breaking-changes-detector workflow. | ||
| # | ||
| # Subcommands: | ||
| # changed-crates <base_ref> | ||
| # Print space-separated list of crate names whose files changed vs base_ref. | ||
| # | ||
| # semver-check <base_ref> <packages...> | ||
| # Run cargo-semver-checks for the given packages against base_ref. | ||
| # Prints the (ANSI-stripped) log output to stdout. | ||
| # Exit code matches cargo-semver-checks (0 = pass, non-zero = breaking). | ||
| # | ||
| # comment <repo> <pr_number> <check_result> [logs] | ||
| # Upsert or delete a sticky PR comment based on check_result. | ||
| # check_result: "success" deletes any existing comment, | ||
| # anything else upserts the comment with the provided logs. | ||
| # Requires GH_TOKEN to be set. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| MARKER="<!-- semver-check-comment -->" | ||
|
|
||
| # ── changed-crates ────────────────────────────────────────────────── | ||
| cmd_changed_crates() { | ||
| local base_ref="${1:?Usage: changed_crates.sh changed-crates <base_ref>}" | ||
|
|
||
| # Parse workspace members from root Cargo.toml, excluding internal crates | ||
| # that are not published / not part of the public API. | ||
| local members | ||
| members=$(sed -n '/^members = \[/,/\]/p' Cargo.toml | grep '"' | sed 's/.*"\(.*\)".*/\1/' \ | ||
| | grep -v -e '^benchmarks$' -e '^test-utils$' -e '^datafusion/sqllogictest$' -e '^datafusion/doc$') | ||
|
|
||
| local changed_files | ||
| changed_files=$(git diff --name-only "${base_ref}...HEAD") | ||
|
|
||
| local packages="" | ||
| for member in $members; do | ||
| if echo "$changed_files" | grep -q "^${member}/"; then | ||
| local pkg | ||
| pkg=$(grep '^name\s*=' "$member/Cargo.toml" | head -1 | sed 's/.*=\s*"\(.*\)"/\1/') | ||
| if [ -n "$pkg" ]; then | ||
| packages="$packages $pkg" | ||
| fi | ||
| fi | ||
| done | ||
|
|
||
| echo "$packages" | xargs | ||
| } | ||
|
|
||
| # ── semver-check ──────────────────────────────────────────────────── | ||
| cmd_semver_check() { | ||
| local base_ref="${1:?Usage: changed_crates.sh semver-check <base_ref> <packages...>}" | ||
| shift | ||
|
|
||
| local args="" | ||
| for pkg in "$@"; do | ||
| args="$args --package $pkg" | ||
| done | ||
|
|
||
| set +e | ||
| # Compare the PR's code against the base branch to detect breaking changes. | ||
| # Use tee to show output in the Actions log while also capturing it. | ||
| cargo semver-checks --baseline-rev "$base_ref" $args 2>&1 | tee /tmp/semver-output.txt | ||
| local exit_code=${PIPESTATUS[0]} | ||
| set -e | ||
|
|
||
| # Strip ANSI escape codes from the captured output for the PR comment. | ||
| sed 's/\x1b\[[0-9;]*m//g' /tmp/semver-output.txt | ||
| return "$exit_code" | ||
| } | ||
|
|
||
| # ── comment ───────────────────────────────────────────────────────── | ||
| cmd_comment() { | ||
| local repo="${1:?Usage: changed_crates.sh comment <repo> <pr_number> <check_result> [logs]}" | ||
| local pr_number="${2:?}" | ||
| local check_result="${3:?}" | ||
| local logs="${4:-}" | ||
|
|
||
| # Find existing comment with our marker | ||
| local comment_id | ||
| comment_id=$(gh api "repos/${repo}/issues/${pr_number}/comments" \ | ||
| --jq ".[] | select(.body | contains(\"${MARKER}\")) | .id" | head -1) | ||
|
|
||
| if [ "$check_result" = "success" ]; then | ||
| # Delete the comment if one exists | ||
| if [ -n "$comment_id" ]; then | ||
| gh api "repos/${repo}/issues/comments/${comment_id}" --method DELETE | ||
| fi | ||
| else | ||
| local body="${MARKER} | ||
| Thank you for opening this pull request! | ||
|
|
||
| Reviewer note: [cargo-semver-checks](https://github.com/obi1kenobi/cargo-semver-checks) reported the current version number is not SemVer-compatible with the changes made since the last release. | ||
|
|
||
| Details: | ||
|
|
||
| \`\`\` | ||
| ${logs} | ||
| \`\`\`" | ||
|
|
||
| if [ -n "$comment_id" ]; then | ||
| gh api "repos/${repo}/issues/comments/${comment_id}" \ | ||
| --method PATCH --field body="$body" | ||
| else | ||
| gh api "repos/${repo}/issues/${pr_number}/comments" \ | ||
| --method POST --field body="$body" | ||
| fi | ||
| fi | ||
| } | ||
|
|
||
| # ── main ──────────────────────────────────────────────────────────── | ||
| cmd="${1:?Usage: changed_crates.sh <changed-crates|semver-check|comment> [args...]}" | ||
| shift | ||
|
|
||
| case "$cmd" in | ||
| changed-crates) cmd_changed_crates "$@" ;; | ||
| semver-check) cmd_semver_check "$@" ;; | ||
| comment) cmd_comment "$@" ;; | ||
| *) echo "Unknown command: $cmd" >&2; exit 1 ;; | ||
| esac |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.