-
Notifications
You must be signed in to change notification settings - Fork 132
Add CI build caching and improve benchmark workflow #1148
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
base: master
Are you sure you want to change the base?
Changes from all commits
3738e14
c3a2469
79ce4e7
bb7f705
08490be
4172553
233aa11
2406c64
d4e7c8f
84835be
09920e7
1adc121
f7d0164
5c97194
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -52,16 +52,16 @@ else | |||||||||||||||||||||||||||||||||||||||||||||||
| echo "Master job completed successfully" | ||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| # Check if either job failed | ||||||||||||||||||||||||||||||||||||||||||||||||
| # Warn if either job failed (partial results may still be usable) | ||||||||||||||||||||||||||||||||||||||||||||||||
| if [ "${pr_exit}" -ne 0 ] || [ "${master_exit}" -ne 0 ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "ERROR: One or both benchmark jobs failed: pr_exit=${pr_exit}, master_exit=${master_exit}" | ||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "WARNING: Benchmark jobs had failures: pr=${pr_exit}, master=${master_exit}" | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Checking for partial results..." | ||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "==========================================" | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Both benchmark jobs completed successfully!" | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "==========================================" | ||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+55
to
63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Use a flag to track benchmark job failures and exit with a non-zero status at the end of the script if any job failed, ensuring the workflow status is accurate. [possible issue, importance: 9]
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| echo "==========================================" | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Both benchmark jobs completed successfully!" | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "==========================================" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| # Final verification that output files exist before proceeding | ||||||||||||||||||||||||||||||||||||||||||||||||
| pr_yaml="pr/bench-${device}-${interface}.yaml" | ||||||||||||||||||||||||||||||||||||||||||||||||
| master_yaml="master/bench-${device}-${interface}.yaml" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #!/bin/bash | ||
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Sets up a persistent build cache for self-hosted CI runners. | ||
| # Creates a symlink: ./build -> <scratch>/.mfc-ci-cache/<key>/build | ||
| # | ||
| # Each runner gets its own cache keyed by (cluster, device, interface, runner). | ||
| # This avoids cross-runner path issues entirely — CMake's absolute paths are | ||
| # always correct because the same runner always uses the same workspace path. | ||
| # | ||
| # Usage: source .github/scripts/setup-build-cache.sh <cluster> <device> <interface> | ||
|
|
||
| _cache_cluster="${1:?Usage: setup-build-cache.sh <cluster> <device> <interface>}" | ||
| _cache_device="${2:?}" | ||
| _cache_interface="${3:-none}" | ||
| _cache_runner="${RUNNER_NAME:?RUNNER_NAME not set}" | ||
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| _cache_key="${_cache_cluster}-${_cache_device}-${_cache_interface}-${_cache_runner}" | ||
| _cache_base="$HOME/scratch/.mfc-ci-cache/${_cache_key}/build" | ||
|
|
||
| mkdir -p "$_cache_base" | ||
| _cache_dir="$(cd "$_cache_base" && pwd -P)" | ||
|
|
||
| echo "=== Build Cache Setup ===" | ||
| echo " Cache key: $_cache_key" | ||
| echo " Cache dir: $_cache_dir" | ||
|
|
||
| # Replace any existing build/ (real dir or stale symlink) with a symlink | ||
| # to our runner-specific cache directory. | ||
| # Use unlink for symlinks to avoid rm -rf following the link and deleting | ||
| # the shared cache contents (which another runner may be using). | ||
| if [ -L "build" ]; then | ||
| unlink "build" | ||
| elif [ -e "build" ]; then | ||
| rm -rf "build" | ||
| fi | ||
|
|
||
| ln -s "$_cache_dir" "build" | ||
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| echo " Symlink: build -> $_cache_dir" | ||
| echo "=========================" | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -46,21 +46,42 @@ jobs: | |||||||
| else | ||||||||
| # Get PR number from workflow_run | ||||||||
| PR_NUMBER="${{ github.event.workflow_run.pull_requests[0].number }}" | ||||||||
| if [ -z "$PR_NUMBER" ]; then | ||||||||
| # Cross-repo PRs don't populate pull_requests[]. Search by head SHA. | ||||||||
| HEAD_SHA="${{ github.event.workflow_run.head_sha }}" | ||||||||
| PR_NUMBER=$(gh api "repos/${{ github.repository }}/pulls?state=open&sort=updated&direction=desc&per_page=30" \ | ||||||||
| --jq ".[] | select(.head.sha == \"$HEAD_SHA\") | .number" | head -1) | ||||||||
| fi | ||||||||
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| if [ -z "$PR_NUMBER" ]; then | ||||||||
| # workflow_run may report the merge/base SHA for forks. Fall back to branch name. | ||||||||
| HEAD_BRANCH="${{ github.event.workflow_run.head_branch }}" | ||||||||
| if [ -n "$HEAD_BRANCH" ] && [ "$HEAD_BRANCH" != "master" ]; then | ||||||||
| PR_NUMBER=$(gh api "repos/${{ github.repository }}/pulls?state=open&sort=updated&direction=desc&per_page=30" \ | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Branch-name-only fallback can select the wrong PR when multiple forks share the same branch name. Include the head repository in the filter so the fallback can’t misidentify a PR. Prompt for AI agents
Suggested change
|
||||||||
| --jq ".[] | select(.head.ref == \"$HEAD_BRANCH\") | .number" | head -1) | ||||||||
| fi | ||||||||
| fi | ||||||||
|
|
||||||||
| if [ -n "$PR_NUMBER" ]; then | ||||||||
| echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT | ||||||||
|
|
||||||||
| # Fetch actual PR author from API (workflow_run.actor is the re-runner, not PR author) | ||||||||
| PR_AUTHOR=$(gh api repos/${{ github.repository }}/pulls/$PR_NUMBER --jq '.user.login') | ||||||||
| echo "author=$PR_AUTHOR" >> $GITHUB_OUTPUT | ||||||||
|
|
||||||||
| # Check if PR is approved | ||||||||
| APPROVED=$(gh api repos/${{ github.repository }}/pulls/$PR_NUMBER/reviews \ | ||||||||
| --jq '[.[] | select(.state == "APPROVED")] | length') | ||||||||
| if [ "$APPROVED" -gt 0 ]; then | ||||||||
| echo "approved=true" >> $GITHUB_OUTPUT | ||||||||
| else | ||||||||
| echo "approved=false" >> $GITHUB_OUTPUT | ||||||||
| fi | ||||||||
| # Check if PR is approved by a maintainer/admin (ignore AI bot approvals) | ||||||||
| APPROVERS=$(gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER/reviews" \ | ||||||||
| --jq '[.[] | select(.state == "APPROVED") | .user.login] | unique | .[]') | ||||||||
| APPROVED="false" | ||||||||
| for approver in $APPROVERS; do | ||||||||
| PERM=$(gh api "repos/${{ github.repository }}/collaborators/$approver/permission" \ | ||||||||
| --jq '.permission' 2>/dev/null || echo "none") | ||||||||
| if [ "$PERM" = "admin" ] || [ "$PERM" = "maintain" ] || [ "$PERM" = "write" ]; then | ||||||||
| echo " Approved by $approver (permission: $PERM)" | ||||||||
| APPROVED="true" | ||||||||
| break | ||||||||
| fi | ||||||||
| done | ||||||||
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| echo "approved=$APPROVED" >> $GITHUB_OUTPUT | ||||||||
| else | ||||||||
| echo "pr_number=" >> $GITHUB_OUTPUT | ||||||||
| echo "approved=false" >> $GITHUB_OUTPUT | ||||||||
|
|
@@ -76,8 +97,7 @@ jobs: | |||||||
| ( | ||||||||
| github.event_name == 'workflow_dispatch' || | ||||||||
| needs.file-changes.outputs.pr_approved == 'true' || | ||||||||
| needs.file-changes.outputs.pr_author == 'sbryngelson' || | ||||||||
| needs.file-changes.outputs.pr_author == 'wilfonba' | ||||||||
| needs.file-changes.outputs.pr_author == 'sbryngelson' | ||||||||
| ) | ||||||||
| needs: [file-changes] | ||||||||
| strategy: | ||||||||
|
|
@@ -164,6 +184,7 @@ jobs: | |||||||
| run: bash pr/.github/scripts/run_parallel_benchmarks.sh ${{ matrix.device }} ${{ matrix.interface }} ${{ matrix.cluster }} | ||||||||
|
|
||||||||
| - name: Generate & Post Comment | ||||||||
| if: always() | ||||||||
| run: | | ||||||||
| (cd pr && . ./mfc.sh load -c ${{ matrix.flag }} -m g) | ||||||||
| (cd pr && ./mfc.sh bench_diff ../master/bench-${{ matrix.device }}-${{ matrix.interface }}.yaml ../pr/bench-${{ matrix.device }}-${{ matrix.interface }}.yaml) | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.