|
| 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 | +# This workflow only runs cargo-semver-checks and uploads the result as an |
| 24 | +# artifact. The actual PR comment is posted by a companion workflow |
| 25 | +# (`breaking_changes_detector_comment.yml`) that picks up the artifact via |
| 26 | +# `workflow_run`. |
| 27 | +# |
| 28 | +# Why split it? |
| 29 | +# "The GITHUB_TOKEN has read-only permissions in pull requests from forked |
| 30 | +# repositories." |
| 31 | +# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request |
| 32 | +# A read-only token cannot post comments, so on fork PRs the previous |
| 33 | +# single-workflow design failed with HTTP 403. We can't simply broaden the |
| 34 | +# trigger here either: cargo-semver-checks compiles PR code (build.rs, proc |
| 35 | +# macros), so granting this job a write token would expose it to any code |
| 36 | +# in the PR. And ASF infra policy independently forbids `pull_request_target` |
| 37 | +# for any workflow that exposes GITHUB_TOKEN |
| 38 | +# (https://infra.apache.org/github-actions-policy.html). The companion |
| 39 | +# `workflow_run` workflow runs in the base-repo context with write access |
| 40 | +# and never executes PR code. |
| 41 | + |
| 42 | +name: "Detect breaking changes" |
| 43 | + |
| 44 | +on: |
| 45 | + pull_request: |
| 46 | + branches: |
| 47 | + - main |
| 48 | + |
| 49 | +permissions: |
| 50 | + contents: read |
| 51 | + |
| 52 | +jobs: |
| 53 | + check-semver: |
| 54 | + name: Check semver |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - name: Checkout |
| 58 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 59 | + with: |
| 60 | + fetch-depth: 0 |
| 61 | + |
| 62 | + # For fork PRs, `origin` points to the fork, not the upstream repo. |
| 63 | + # Explicitly fetch the base branch from the upstream repo so we have |
| 64 | + # a valid baseline ref for both diff and semver-checks. |
| 65 | + - name: Fetch base branch |
| 66 | + env: |
| 67 | + BASE_REF: ${{ github.base_ref }} |
| 68 | + REPO: ${{ github.repository }} |
| 69 | + run: git fetch "https://github.com/${REPO}.git" "${BASE_REF}:refs/remotes/origin/${BASE_REF}" |
| 70 | + |
| 71 | + - name: Determine changed crates |
| 72 | + id: changed_crates |
| 73 | + env: |
| 74 | + BASE_REF: ${{ github.base_ref }} |
| 75 | + run: | |
| 76 | + PACKAGES=$(ci/scripts/changed_crates.sh changed-crates "origin/${BASE_REF}") |
| 77 | + echo "packages=$PACKAGES" >> "$GITHUB_OUTPUT" |
| 78 | + echo "Changed crates: $PACKAGES" |
| 79 | +
|
| 80 | + # `datafusion-substrait` (and crates that depend on it via sqllogictest) |
| 81 | + # have a build script that calls protoc, which is not preinstalled on |
| 82 | + # ubuntu-latest runners. |
| 83 | + - name: Install Protobuf Compiler |
| 84 | + if: steps.changed_crates.outputs.packages != '' |
| 85 | + run: | |
| 86 | + sudo apt-get update |
| 87 | + sudo apt-get install -y protobuf-compiler |
| 88 | +
|
| 89 | + - name: Install cargo-semver-checks |
| 90 | + if: steps.changed_crates.outputs.packages != '' |
| 91 | + uses: taiki-e/install-action@94cb46f8d6e437890146ffbd78a778b78e623fb2 # v2.74.0 |
| 92 | + with: |
| 93 | + tool: cargo-semver-checks |
| 94 | + |
| 95 | + - name: Run cargo-semver-checks |
| 96 | + id: check_semver |
| 97 | + if: steps.changed_crates.outputs.packages != '' |
| 98 | + env: |
| 99 | + BASE_REF: ${{ github.base_ref }} |
| 100 | + PACKAGES: ${{ steps.changed_crates.outputs.packages }} |
| 101 | + run: | |
| 102 | + set +e |
| 103 | + # `tee` lets cargo's output stream live into the Actions log |
| 104 | + # while we also keep a copy for the PR comment. |
| 105 | + ci/scripts/changed_crates.sh semver-check "origin/${BASE_REF}" $PACKAGES \ |
| 106 | + 2>&1 | tee /tmp/semver-output.txt |
| 107 | + EXIT_CODE=${PIPESTATUS[0]} |
| 108 | + # Pass the result through an output instead of failing the job: |
| 109 | + # a detected breaking change should surface as a PR comment, not a |
| 110 | + # red check, so PR authors aren't confused by an intentional break. |
| 111 | + if [ "$EXIT_CODE" -eq 0 ]; then |
| 112 | + echo "result=success" >> "$GITHUB_OUTPUT" |
| 113 | + else |
| 114 | + echo "result=failure" >> "$GITHUB_OUTPUT" |
| 115 | + fi |
| 116 | +
|
| 117 | + # Stage the data the companion comment workflow needs into a single |
| 118 | + # directory. We default the result to "success" so the comment |
| 119 | + # workflow clears any stale comment when the check step is skipped |
| 120 | + # (e.g. no published crates changed). |
| 121 | + - name: Stage artifact for comment workflow |
| 122 | + if: always() |
| 123 | + env: |
| 124 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 125 | + CHECK_RESULT: ${{ steps.check_semver.outputs.result || 'success' }} |
| 126 | + run: | |
| 127 | + mkdir -p semver-artifact |
| 128 | + echo "$PR_NUMBER" > semver-artifact/pr_number |
| 129 | + echo "$CHECK_RESULT" > semver-artifact/result |
| 130 | + if [ -f /tmp/semver-output.txt ]; then |
| 131 | + sed 's/\x1b\[[0-9;]*m//g' /tmp/semver-output.txt > semver-artifact/logs |
| 132 | + else |
| 133 | + : > semver-artifact/logs |
| 134 | + fi |
| 135 | +
|
| 136 | + - name: Upload artifact |
| 137 | + if: always() |
| 138 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 139 | + with: |
| 140 | + name: semver-check-result |
| 141 | + path: semver-artifact/ |
| 142 | + retention-days: 1 |
0 commit comments