nchammas commented on code in PR #60045:
URL: https://github.com/apache/spark/pull/60045#discussion_r4455095349
##########
.github/workflows/build_main.yml:
##########
@@ -25,13 +25,70 @@ on:
- '**'
jobs:
+ check-commit-count:
+ name: Check commit count
+ if: github.repository == 'apache/spark' && github.ref ==
'refs/heads/master'
+ runs-on: ubuntu-slim
+ permissions:
+ contents: read
+ outputs:
+ should-run: ${{ steps.count.outputs.should-run }}
+ steps:
+ - name: Check out the full branch history
+ uses: actions/checkout@v6
+ with:
+ fetch-depth: 0
Review Comment:
I don't think a full pull of the history is necessary to calculate this
count. The full checkout takes 1-2 minutes, whereas something like this should
run in under a second:
```sh
gh api graphql \
-F owner=apache \
-F name=spark \
-F sha=152e072adb20172a27b595f5a36d8b53df91986b \
-f query='
query($owner: String!, $name: String!, $sha: GitObjectID!) {
repository(owner: $owner, name: $name) {
object(oid: $sha) {
... on Commit { history { totalCount } }
}
}
}' \
--jq '.data.repository.object.history.totalCount'
```
##########
.github/workflows/build_main.yml:
##########
@@ -25,13 +25,70 @@ on:
- '**'
jobs:
+ check-commit-count:
+ name: Check commit count
+ if: github.repository == 'apache/spark' && github.ref ==
'refs/heads/master'
+ runs-on: ubuntu-slim
+ permissions:
+ contents: read
+ outputs:
+ should-run: ${{ steps.count.outputs.should-run }}
+ steps:
+ - name: Check out the full branch history
+ uses: actions/checkout@v6
+ with:
+ fetch-depth: 0
+ - name: Check whether this is every tenth commit
+ id: count
+ run: |
+ count=$(git rev-list --count HEAD)
+ remainder=$((count % 10))
+
+ if ((remainder == 0)); then
+ should_run=true
+ icon=":white_check_mark:"
+ title="Commit count matched"
+ details="Commit count $count is divisible by 10."
+ else
+ should_run=false
+ icon=":pause_button:"
+ title="Commit count not matched"
+ details="Commit count $count is not divisible by 10."
+ fi
+
+ echo "should-run=$should_run" >> "$GITHUB_OUTPUT"
+ echo "Branch: $GITHUB_REF_NAME"
+ echo "Commit: $GITHUB_SHA"
+ echo "Commit count: $count"
+ echo "Remainder: $remainder"
+ echo "Should run: $should_run"
+ echo "Details: $details"
+ echo "::notice title=$title::$details"
+ echo "### $icon Commit count check" >> "$GITHUB_STEP_SUMMARY"
+ echo "" >> "$GITHUB_STEP_SUMMARY"
+ echo "- Branch: $GITHUB_REF_NAME" >> "$GITHUB_STEP_SUMMARY"
+ echo "- Commit: $GITHUB_SHA" >> "$GITHUB_STEP_SUMMARY"
+ echo "- Commit count: $count" >> "$GITHUB_STEP_SUMMARY"
+ echo "- Remainder: $remainder" >> "$GITHUB_STEP_SUMMARY"
+ echo "- Should run: $should_run" >> "$GITHUB_STEP_SUMMARY"
+ echo "- Details: $details" >> "$GITHUB_STEP_SUMMARY"
+
call-build-and-test:
permissions:
packages: write
name: Run
+ needs: check-commit-count
# Skip pushes to `master` on forks: the "Sync fork" button mirrors
# apache/spark and would otherwise re-run the full build on every sync.
+ # Evaluate this condition even when the master-only sampling check is
skipped.
if: >-
- github.repository == 'apache/spark'
- || github.ref != 'refs/heads/master'
+ (!cancelled())
Review Comment:
Could you update this comment to explain why the `!cancelled()` is needed?
Right now the comment just repeats what the code does.
When exactly would the sampling check be skipped?
--
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]