From fb8ff82a8b6b51188d253ccd96c9cf04f95dac0e Mon Sep 17 00:00:00 2001 From: Ashwin Krishna Kumar Date: Tue, 7 Apr 2026 15:22:55 +0530 Subject: [PATCH 1/5] Allow bench workflow to run on PRs from forks --- .github/workflows/run-bench.yml | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/.github/workflows/run-bench.yml b/.github/workflows/run-bench.yml index 19762aaa5..87c97498b 100644 --- a/.github/workflows/run-bench.yml +++ b/.github/workflows/run-bench.yml @@ -1,5 +1,9 @@ name: Run Bench Main +permissions: + contents: read + pull-requests: read + on: workflow_dispatch: inputs: @@ -42,9 +46,17 @@ jobs: # Default branches based on event type if [[ "${{ github.event_name }}" == "pull_request" ]]; then echo "Pull request detected. Using main and PR branch: ${{ github.head_ref }}" - BRANCHES='["main", "${{ github.head_ref }}"]' + # Check if PR is from a fork + if [[ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]]; then + echo "PR from fork detected: ${{ github.event.pull_request.head.repo.full_name }}" + BRANCHES='[{"branch":"main","repository":"${{ github.repository }}"}, {"branch":"${{ github.head_ref }}","repository":"${{ github.event.pull_request.head.repo.full_name }}"}]' + else + echo "PR from same repository" + BRANCHES='[{"branch":"main","repository":"${{ github.repository }}"}, {"branch":"${{ github.head_ref }}","repository":"${{ github.repository }}"}]' + fi elif [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.branches }}" ]]; then # Parse space-separated branches input into JSON array + # All branches from workflow_dispatch are assumed to be from the current repository echo "Workflow dispatch with branches input detected" BRANCHES_INPUT="${{ github.event.inputs.branches }}" BRANCHES="[" @@ -52,22 +64,22 @@ jobs: if [[ "$BRANCHES" != "[" ]]; then BRANCHES="$BRANCHES, " fi - BRANCHES="$BRANCHES\"$branch\"" + BRANCHES="$BRANCHES{\"branch\":\"$branch\",\"repository\":\"${{ github.repository }}\"}" echo "Adding branch to matrix: $branch" done BRANCHES="$BRANCHES]" else echo "Default event type. Using main branch only" - BRANCHES='["main"]' + BRANCHES='[{"branch":"main","repository":"${{ github.repository }}"}]' fi echo "Generated branches matrix: $BRANCHES" - echo "matrix={\"jdk\":[24],\"isa\":[\"isa-avx512f\"],\"branch\":$BRANCHES}" >> $GITHUB_OUTPUT + echo "matrix={\"jdk\":[24],\"isa\":[\"isa-avx512f\"],\"include\":$BRANCHES}" >> $GITHUB_OUTPUT test-avx512: needs: generate-matrix concurrency: - group: ${{ matrix.isa }}-${{ matrix.jdk }}-${{ matrix.branch }} + group: ${{ matrix.isa }}-${{ matrix.jdk }}-${{ matrix.repository }}-${{ matrix.branch }} cancel-in-progress: false strategy: matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }} @@ -123,6 +135,7 @@ jobs: - name: Checkout branch uses: actions/checkout@v4 with: + repository: ${{ matrix.repository }} ref: ${{ matrix.branch }} fetch-depth: 0 @@ -193,9 +206,11 @@ jobs: echo "No custom configuration provided, using default autoDefault.yml" fi - # Sanitize branch name for filenames: replace any non-alphanumeric, dash or underscore with underscore + # Sanitize branch name and repository for filenames: replace any non-alphanumeric, dash or underscore with underscore SAFE_BRANCH=$(echo "${{ matrix.branch }}" | sed 's/[^A-Za-z0-9_-]/_/g') + SAFE_REPO=$(echo "${{ matrix.repository }}" | sed 's/[^A-Za-z0-9_-]/_/g') echo "safe_branch=$SAFE_BRANCH" >> $GITHUB_OUTPUT + echo "safe_repo=$SAFE_REPO" >> $GITHUB_OUTPUT if [[ "${{ github.event_name }}" == "pull_request" ]]; then java ${{ matrix.jdk >= 20 && '--enable-native-access=ALL-UNNAMED --add-modules=jdk.incubator.vector' || '' }} \ @@ -218,7 +233,7 @@ jobs: - name: Upload Individual Benchmark Results uses: actions/upload-artifact@v4 with: - name: benchmark-results-${{ matrix.isa }}-jdk${{ matrix.jdk }}-${{ steps.run-benchmark.outputs.safe_branch }} + name: benchmark-results-${{ matrix.isa }}-jdk${{ matrix.jdk }}-${{ steps.run-benchmark.outputs.safe_repo }}-${{ steps.run-benchmark.outputs.safe_branch }} path: | benchmark_results/*.csv benchmark_results/*.json From f035366edb3fc05db0a4ea8984cfbb60f2d164b6 Mon Sep 17 00:00:00 2001 From: Ashwin Krishna Kumar Date: Tue, 7 Apr 2026 15:29:28 +0530 Subject: [PATCH 2/5] Trigger bench workflow on workflow file changes --- .github/workflows/run-bench.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-bench.yml b/.github/workflows/run-bench.yml index 87c97498b..5689a8046 100644 --- a/.github/workflows/run-bench.yml +++ b/.github/workflows/run-bench.yml @@ -28,6 +28,7 @@ on: - '**/src/main/java/**' - 'pom.xml' - '**/pom.xml' + - '.github/workflows/run-bench.yml' jobs: # Job to generate the matrix configuration From 486f26dfed62a32ac459d7e9d356dcee85014763 Mon Sep 17 00:00:00 2001 From: Ashwin Krishna Kumar Date: Tue, 7 Apr 2026 16:37:28 +0530 Subject: [PATCH 3/5] Use nested object instead of include --- .github/workflows/run-bench.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/run-bench.yml b/.github/workflows/run-bench.yml index 5689a8046..c82c0b828 100644 --- a/.github/workflows/run-bench.yml +++ b/.github/workflows/run-bench.yml @@ -75,12 +75,12 @@ jobs: fi echo "Generated branches matrix: $BRANCHES" - echo "matrix={\"jdk\":[24],\"isa\":[\"isa-avx512f\"],\"include\":$BRANCHES}" >> $GITHUB_OUTPUT + echo "matrix={\"jdk\":[24],\"isa\":[\"isa-avx512f\"],\"ref\":$BRANCHES}" >> $GITHUB_OUTPUT test-avx512: needs: generate-matrix concurrency: - group: ${{ matrix.isa }}-${{ matrix.jdk }}-${{ matrix.repository }}-${{ matrix.branch }} + group: ${{ matrix.isa }}-${{ matrix.jdk }}-${{ matrix.ref.repository }}-${{ matrix.ref.branch }} cancel-in-progress: false strategy: matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }} @@ -128,7 +128,7 @@ jobs: - name: Print job information run: | echo "Running benchmark for:" - echo " - Branch: ${{ matrix.branch }}" + echo " - Branch: ${{ matrix.ref.branch }}" echo " - JDK: ${{ matrix.jdk }}" echo " - ISA: ${{ matrix.isa }}" @@ -136,8 +136,8 @@ jobs: - name: Checkout branch uses: actions/checkout@v4 with: - repository: ${{ matrix.repository }} - ref: ${{ matrix.branch }} + repository: ${{ matrix.ref.repository }} + ref: ${{ matrix.ref.branch }} fetch-depth: 0 # Create a directory to store benchmark results @@ -156,14 +156,14 @@ jobs: run: | # Check if jvector-examples directory and AutoBenchYAML class exist if [ ! -d "jvector-examples" ]; then - echo "Warning: jvector-examples directory not found in branch ${{ matrix.branch }}. Skipping benchmark." + echo "Warning: jvector-examples directory not found in branch ${{ matrix.ref.branch }}. Skipping benchmark." exit 0 fi # Check if the jar with dependencies was built JAR_COUNT=$(ls jvector-examples/target/jvector-examples-*-jar-with-dependencies.jar 2>/dev/null | wc -l) if [ "$JAR_COUNT" -eq 0 ]; then - echo "Warning: No jar with dependencies found in branch ${{ matrix.branch }}. Skipping benchmark." + echo "Warning: No jar with dependencies found in branch ${{ matrix.ref.branch }}. Skipping benchmark." exit 0 fi @@ -182,7 +182,7 @@ jobs: echo "Total memory: ${TOTAL_MEM_GB}GB, using ${HALF_MEM_GB}GB for Java heap" # Run the benchmark - echo "Running benchmark for branch ${{ matrix.branch }}" + echo "Running benchmark for branch ${{ matrix.ref.branch }}" # Determine optional benchmark config argument from workflow input BENCH_ARG="${{ github.event.inputs.benchmark_config }}" @@ -208,8 +208,8 @@ jobs: fi # Sanitize branch name and repository for filenames: replace any non-alphanumeric, dash or underscore with underscore - SAFE_BRANCH=$(echo "${{ matrix.branch }}" | sed 's/[^A-Za-z0-9_-]/_/g') - SAFE_REPO=$(echo "${{ matrix.repository }}" | sed 's/[^A-Za-z0-9_-]/_/g') + SAFE_BRANCH=$(echo "${{ matrix.ref.branch }}" | sed 's/[^A-Za-z0-9_-]/_/g') + SAFE_REPO=$(echo "${{ matrix.ref.repository }}" | sed 's/[^A-Za-z0-9_-]/_/g') echo "safe_branch=$SAFE_BRANCH" >> $GITHUB_OUTPUT echo "safe_repo=$SAFE_REPO" >> $GITHUB_OUTPUT @@ -229,7 +229,7 @@ jobs: mv ${SAFE_BRANCH}-bench-results.csv benchmark_results/ || true mv ${SAFE_BRANCH}-bench-results.json benchmark_results/ || true - echo "Completed benchmarks for branch: ${{ matrix.branch }}" + echo "Completed benchmarks for branch: ${{ matrix.ref.branch }}" - name: Upload Individual Benchmark Results uses: actions/upload-artifact@v4 From 6ab5846b534ab1fd4ab4400f7f64ada0773efd16 Mon Sep 17 00:00:00 2001 From: Ashwin Krishna Kumar Date: Tue, 7 Apr 2026 16:54:53 +0530 Subject: [PATCH 4/5] Simplify by using SHA only --- .github/workflows/run-bench.yml | 46 +++++++++++---------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/.github/workflows/run-bench.yml b/.github/workflows/run-bench.yml index c82c0b828..96e525bec 100644 --- a/.github/workflows/run-bench.yml +++ b/.github/workflows/run-bench.yml @@ -1,9 +1,5 @@ name: Run Bench Main -permissions: - contents: read - pull-requests: read - on: workflow_dispatch: inputs: @@ -28,7 +24,6 @@ on: - '**/src/main/java/**' - 'pom.xml' - '**/pom.xml' - - '.github/workflows/run-bench.yml' jobs: # Job to generate the matrix configuration @@ -46,18 +41,10 @@ jobs: # Default branches based on event type if [[ "${{ github.event_name }}" == "pull_request" ]]; then - echo "Pull request detected. Using main and PR branch: ${{ github.head_ref }}" - # Check if PR is from a fork - if [[ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]]; then - echo "PR from fork detected: ${{ github.event.pull_request.head.repo.full_name }}" - BRANCHES='[{"branch":"main","repository":"${{ github.repository }}"}, {"branch":"${{ github.head_ref }}","repository":"${{ github.event.pull_request.head.repo.full_name }}"}]' - else - echo "PR from same repository" - BRANCHES='[{"branch":"main","repository":"${{ github.repository }}"}, {"branch":"${{ github.head_ref }}","repository":"${{ github.repository }}"}]' - fi + echo "Pull request detected. Using main and PR commit SHA: ${{ github.event.pull_request.head.sha }}" + BRANCHES='["main", "${{ github.event.pull_request.head.sha }}"]' elif [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.branches }}" ]]; then # Parse space-separated branches input into JSON array - # All branches from workflow_dispatch are assumed to be from the current repository echo "Workflow dispatch with branches input detected" BRANCHES_INPUT="${{ github.event.inputs.branches }}" BRANCHES="[" @@ -65,22 +52,22 @@ jobs: if [[ "$BRANCHES" != "[" ]]; then BRANCHES="$BRANCHES, " fi - BRANCHES="$BRANCHES{\"branch\":\"$branch\",\"repository\":\"${{ github.repository }}\"}" + BRANCHES="$BRANCHES\"$branch\"" echo "Adding branch to matrix: $branch" done BRANCHES="$BRANCHES]" else echo "Default event type. Using main branch only" - BRANCHES='[{"branch":"main","repository":"${{ github.repository }}"}]' + BRANCHES='["main"]' fi echo "Generated branches matrix: $BRANCHES" - echo "matrix={\"jdk\":[24],\"isa\":[\"isa-avx512f\"],\"ref\":$BRANCHES}" >> $GITHUB_OUTPUT + echo "matrix={\"jdk\":[24],\"isa\":[\"isa-avx512f\"],\"branch\":$BRANCHES}" >> $GITHUB_OUTPUT test-avx512: needs: generate-matrix concurrency: - group: ${{ matrix.isa }}-${{ matrix.jdk }}-${{ matrix.ref.repository }}-${{ matrix.ref.branch }} + group: ${{ matrix.isa }}-${{ matrix.jdk }}-${{ matrix.branch }} cancel-in-progress: false strategy: matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }} @@ -128,7 +115,7 @@ jobs: - name: Print job information run: | echo "Running benchmark for:" - echo " - Branch: ${{ matrix.ref.branch }}" + echo " - Branch: ${{ matrix.branch }}" echo " - JDK: ${{ matrix.jdk }}" echo " - ISA: ${{ matrix.isa }}" @@ -136,8 +123,7 @@ jobs: - name: Checkout branch uses: actions/checkout@v4 with: - repository: ${{ matrix.ref.repository }} - ref: ${{ matrix.ref.branch }} + ref: ${{ matrix.branch }} fetch-depth: 0 # Create a directory to store benchmark results @@ -156,14 +142,14 @@ jobs: run: | # Check if jvector-examples directory and AutoBenchYAML class exist if [ ! -d "jvector-examples" ]; then - echo "Warning: jvector-examples directory not found in branch ${{ matrix.ref.branch }}. Skipping benchmark." + echo "Warning: jvector-examples directory not found in branch ${{ matrix.branch }}. Skipping benchmark." exit 0 fi # Check if the jar with dependencies was built JAR_COUNT=$(ls jvector-examples/target/jvector-examples-*-jar-with-dependencies.jar 2>/dev/null | wc -l) if [ "$JAR_COUNT" -eq 0 ]; then - echo "Warning: No jar with dependencies found in branch ${{ matrix.ref.branch }}. Skipping benchmark." + echo "Warning: No jar with dependencies found in branch ${{ matrix.branch }}. Skipping benchmark." exit 0 fi @@ -182,7 +168,7 @@ jobs: echo "Total memory: ${TOTAL_MEM_GB}GB, using ${HALF_MEM_GB}GB for Java heap" # Run the benchmark - echo "Running benchmark for branch ${{ matrix.ref.branch }}" + echo "Running benchmark for branch ${{ matrix.branch }}" # Determine optional benchmark config argument from workflow input BENCH_ARG="${{ github.event.inputs.benchmark_config }}" @@ -207,11 +193,9 @@ jobs: echo "No custom configuration provided, using default autoDefault.yml" fi - # Sanitize branch name and repository for filenames: replace any non-alphanumeric, dash or underscore with underscore - SAFE_BRANCH=$(echo "${{ matrix.ref.branch }}" | sed 's/[^A-Za-z0-9_-]/_/g') - SAFE_REPO=$(echo "${{ matrix.ref.repository }}" | sed 's/[^A-Za-z0-9_-]/_/g') + # Sanitize branch name for filenames: replace any non-alphanumeric, dash or underscore with underscore + SAFE_BRANCH=$(echo "${{ matrix.branch }}" | sed 's/[^A-Za-z0-9_-]/_/g') echo "safe_branch=$SAFE_BRANCH" >> $GITHUB_OUTPUT - echo "safe_repo=$SAFE_REPO" >> $GITHUB_OUTPUT if [[ "${{ github.event_name }}" == "pull_request" ]]; then java ${{ matrix.jdk >= 20 && '--enable-native-access=ALL-UNNAMED --add-modules=jdk.incubator.vector' || '' }} \ @@ -229,12 +213,12 @@ jobs: mv ${SAFE_BRANCH}-bench-results.csv benchmark_results/ || true mv ${SAFE_BRANCH}-bench-results.json benchmark_results/ || true - echo "Completed benchmarks for branch: ${{ matrix.ref.branch }}" + echo "Completed benchmarks for branch: ${{ matrix.branch }}" - name: Upload Individual Benchmark Results uses: actions/upload-artifact@v4 with: - name: benchmark-results-${{ matrix.isa }}-jdk${{ matrix.jdk }}-${{ steps.run-benchmark.outputs.safe_repo }}-${{ steps.run-benchmark.outputs.safe_branch }} + name: benchmark-results-${{ matrix.isa }}-jdk${{ matrix.jdk }}-${{ steps.run-benchmark.outputs.safe_branch }} path: | benchmark_results/*.csv benchmark_results/*.json From 22b2122e0bbd1ad3ab857e2d31942660f4cd9182 Mon Sep 17 00:00:00 2001 From: Ashwin Krishna Kumar Date: Tue, 7 Apr 2026 18:45:53 +0530 Subject: [PATCH 5/5] Add back run-bench to trigger list --- .github/workflows/run-bench.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-bench.yml b/.github/workflows/run-bench.yml index 96e525bec..aeca49ad4 100644 --- a/.github/workflows/run-bench.yml +++ b/.github/workflows/run-bench.yml @@ -24,6 +24,7 @@ on: - '**/src/main/java/**' - 'pom.xml' - '**/pom.xml' + - '.github/workflows/run-bench.yml' jobs: # Job to generate the matrix configuration