|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +# Detect semver-incompatible (breaking) API changes in crates modified by a PR. |
| 19 | +# |
| 20 | +# Only public workspace crates that have file changes are checked. |
| 21 | +# Internal crates (benchmarks, test-utils, sqllogictest, doc) are excluded. |
| 22 | +# |
| 23 | +# If breaking changes are found, a sticky comment is posted on the PR. |
| 24 | +# The comment is removed automatically once the issues are resolved. |
| 25 | + |
| 26 | +name: "Detect breaking changes" |
| 27 | + |
| 28 | +on: |
| 29 | + pull_request: |
| 30 | + branches: |
| 31 | + - main |
| 32 | + |
| 33 | +permissions: |
| 34 | + contents: read |
| 35 | + |
| 36 | +jobs: |
| 37 | + check-semver: |
| 38 | + name: Check semver |
| 39 | + runs-on: ubuntu-latest |
| 40 | + outputs: |
| 41 | + logs: ${{ steps.check_semver.outputs.logs }} |
| 42 | + # Default to "success" so the comment job clears any stale comment |
| 43 | + # when the check step is skipped (e.g. no published crates changed). |
| 44 | + result: ${{ steps.check_semver.outputs.result || 'success' }} |
| 45 | + steps: |
| 46 | + - name: Checkout |
| 47 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 48 | + with: |
| 49 | + fetch-depth: 0 |
| 50 | + |
| 51 | + # For fork PRs, `origin` points to the fork, not the upstream repo. |
| 52 | + # Explicitly fetch the base branch from the upstream repo so we have |
| 53 | + # a valid baseline ref for both diff and semver-checks. |
| 54 | + - name: Fetch base branch |
| 55 | + env: |
| 56 | + BASE_REF: ${{ github.base_ref }} |
| 57 | + REPO: ${{ github.repository }} |
| 58 | + run: git fetch "https://github.com/${REPO}.git" "${BASE_REF}:refs/remotes/origin/${BASE_REF}" |
| 59 | + |
| 60 | + - name: Determine changed crates |
| 61 | + id: changed_crates |
| 62 | + env: |
| 63 | + BASE_REF: ${{ github.base_ref }} |
| 64 | + run: | |
| 65 | + PACKAGES=$(ci/scripts/changed_crates.sh changed-crates "origin/${BASE_REF}") |
| 66 | + echo "packages=$PACKAGES" >> "$GITHUB_OUTPUT" |
| 67 | + echo "Changed crates: $PACKAGES" |
| 68 | +
|
| 69 | + - name: Install cargo-semver-checks |
| 70 | + if: steps.changed_crates.outputs.packages != '' |
| 71 | + uses: taiki-e/install-action@94cb46f8d6e437890146ffbd78a778b78e623fb2 # v2.74.0 |
| 72 | + with: |
| 73 | + tool: cargo-semver-checks |
| 74 | + |
| 75 | + - name: Run cargo-semver-checks |
| 76 | + id: check_semver |
| 77 | + if: steps.changed_crates.outputs.packages != '' |
| 78 | + env: |
| 79 | + BASE_REF: ${{ github.base_ref }} |
| 80 | + PACKAGES: ${{ steps.changed_crates.outputs.packages }} |
| 81 | + run: | |
| 82 | + set +e |
| 83 | + # `tee` lets cargo's output stream live into the Actions log |
| 84 | + # while we also keep a copy for the PR comment. |
| 85 | + ci/scripts/changed_crates.sh semver-check "origin/${BASE_REF}" $PACKAGES \ |
| 86 | + 2>&1 | tee /tmp/semver-output.txt |
| 87 | + EXIT_CODE=${PIPESTATUS[0]} |
| 88 | + { |
| 89 | + echo "logs<<EOF" |
| 90 | + sed 's/\x1b\[[0-9;]*m//g' /tmp/semver-output.txt |
| 91 | + echo "EOF" |
| 92 | + } >> "$GITHUB_OUTPUT" |
| 93 | + # Pass the result through an output instead of failing the job: |
| 94 | + # a detected breaking change should surface as a PR comment, not a |
| 95 | + # red check, so PR authors aren't confused by an intentional break. |
| 96 | + if [ "$EXIT_CODE" -eq 0 ]; then |
| 97 | + echo "result=success" >> "$GITHUB_OUTPUT" |
| 98 | + else |
| 99 | + echo "result=failure" >> "$GITHUB_OUTPUT" |
| 100 | + fi |
| 101 | +
|
| 102 | + # Post or remove a sticky comment on the PR based on the semver check result. |
| 103 | + comment-on-pr: |
| 104 | + name: Comment on pull request |
| 105 | + runs-on: ubuntu-latest |
| 106 | + needs: check-semver |
| 107 | + if: always() |
| 108 | + permissions: |
| 109 | + contents: read |
| 110 | + pull-requests: write |
| 111 | + steps: |
| 112 | + - name: Checkout |
| 113 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 114 | + with: |
| 115 | + sparse-checkout: ci/scripts |
| 116 | + |
| 117 | + - name: Update PR comment |
| 118 | + env: |
| 119 | + GH_TOKEN: ${{ github.token }} |
| 120 | + REPO: ${{ github.repository }} |
| 121 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 122 | + CHECK_RESULT: ${{ needs.check-semver.outputs.result }} |
| 123 | + SEMVER_LOGS: ${{ needs.check-semver.outputs.logs }} |
| 124 | + run: | |
| 125 | + ci/scripts/changed_crates.sh comment \ |
| 126 | + "$REPO" "$PR_NUMBER" "$CHECK_RESULT" "$SEMVER_LOGS" |
0 commit comments