alamb commented on code in PR #21499:
URL: https://github.com/apache/datafusion/pull/21499#discussion_r3060488526


##########
.github/workflows/breaking_changes_detector.yml:
##########
@@ -0,0 +1,143 @@
+# 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
+        run: git fetch https://github.com/${{ github.repository }}.git ${{ 
github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}
+
+      - name: Determine changed crates
+        id: changed_crates
+        run: |
+          # Parse workspace members from root Cargo.toml, excluding internal 
crates
+          # that are not published / not part of the public API.
+          MEMBERS=$(sed -n '/^members = \[/,/\]/p' Cargo.toml | grep '"' | sed 
's/.*"\(.*\)".*/\1/' \
+            | grep -v -e '^benchmarks$' -e '^test-utils$' -e 
'^datafusion/sqllogictest$' -e '^datafusion/doc$')
+
+          # Diff against the base branch to find which files changed in this PR
+          CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref 
}}...HEAD)
+
+          # For each workspace member, check if any of its files were modified.
+          # If so, extract the crate name from its Cargo.toml.
+          PACKAGES=""
+          for member in $MEMBERS; do
+            if echo "$CHANGED_FILES" | grep -q "^${member}/"; then
+              pkg=$(grep '^name\s*=' "$member/Cargo.toml" | head -1 | sed 
's/.*=\s*"\(.*\)"/\1/')
+              if [ -n "$pkg" ]; then
+                PACKAGES="$PACKAGES $pkg"
+              fi
+            fi
+          done
+
+          PACKAGES=$(echo "$PACKAGES" | xargs)
+          echo "packages=$PACKAGES" >> "$GITHUB_OUTPUT"
+          echo "Changed crates: $PACKAGES"
+
+      # Only install toolchain and cargo-semver-checks if there are crates to 
check
+      - name: Install Rust toolchain
+        if: steps.changed_crates.outputs.packages != ''
+        uses: dtolnay/rust-toolchain@stable
+
+      - 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 != ''
+        run: |
+          set +e
+          ARGS=""
+          for pkg in ${{ steps.changed_crates.outputs.packages }}; do
+            ARGS="$ARGS --package $pkg"
+          done
+
+          # 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.
+          # Strip ANSI escape codes from the captured output for the PR 
comment.
+          cargo semver-checks --baseline-rev origin/${{ github.base_ref }} 
$ARGS 2>&1 | tee /tmp/semver-output.txt
+          EXIT_CODE=${PIPESTATUS[0]}
+          OUTPUT=$(sed 's/\x1b\[[0-9;]*m//g' /tmp/semver-output.txt)
+          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: Comment
+        if: ${{ needs.check-semver.result != 'success' }}
+        uses: marocchino/sticky-pull-request-comment@v2

Review Comment:
   I thought in general the ASF CI jobs are supposed to avoid using non github 
actions (unless it is on the whitelist) -- so I am surprised this works. 



##########
.github/workflows/breaking_changes_detector.yml:
##########
@@ -0,0 +1,143 @@
+# 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
+        run: git fetch https://github.com/${{ github.repository }}.git ${{ 
github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}
+
+      - name: Determine changed crates
+        id: changed_crates
+        run: |
+          # Parse workspace members from root Cargo.toml, excluding internal 
crates

Review Comment:
   I am not sure how to debug scripts like this -- can you please put this 
logic into an existing script (like maybe `ci/scripts/changed_packages.sh`?



##########
.github/workflows/breaking_changes_detector.yml:
##########
@@ -0,0 +1,143 @@
+# 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
+        run: git fetch https://github.com/${{ github.repository }}.git ${{ 
github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}
+
+      - name: Determine changed crates
+        id: changed_crates
+        run: |
+          # Parse workspace members from root Cargo.toml, excluding internal 
crates
+          # that are not published / not part of the public API.
+          MEMBERS=$(sed -n '/^members = \[/,/\]/p' Cargo.toml | grep '"' | sed 
's/.*"\(.*\)".*/\1/' \
+            | grep -v -e '^benchmarks$' -e '^test-utils$' -e 
'^datafusion/sqllogictest$' -e '^datafusion/doc$')
+
+          # Diff against the base branch to find which files changed in this PR
+          CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref 
}}...HEAD)
+
+          # For each workspace member, check if any of its files were modified.
+          # If so, extract the crate name from its Cargo.toml.
+          PACKAGES=""
+          for member in $MEMBERS; do
+            if echo "$CHANGED_FILES" | grep -q "^${member}/"; then
+              pkg=$(grep '^name\s*=' "$member/Cargo.toml" | head -1 | sed 
's/.*=\s*"\(.*\)"/\1/')
+              if [ -n "$pkg" ]; then
+                PACKAGES="$PACKAGES $pkg"
+              fi
+            fi
+          done
+
+          PACKAGES=$(echo "$PACKAGES" | xargs)
+          echo "packages=$PACKAGES" >> "$GITHUB_OUTPUT"
+          echo "Changed crates: $PACKAGES"
+
+      # Only install toolchain and cargo-semver-checks if there are crates to 
check
+      - name: Install Rust toolchain
+        if: steps.changed_crates.outputs.packages != ''

Review Comment:
   I think the github runner already has rust installed so this step is 
unecessary probably?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to