From 2ce52ef1f418bb8195678b62663955d847843712 Mon Sep 17 00:00:00 2001 From: Ashwin Krishna Kumar Date: Tue, 7 Apr 2026 15:22:55 +0530 Subject: [PATCH 1/6] 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 6919b0e56..5d6781db3 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 @@ -205,9 +218,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' || '' }} \ @@ -230,7 +245,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 4628b6e5c1a0b6c2bf35d87f6064bd4498dc0bf3 Mon Sep 17 00:00:00 2001 From: Ashwin Krishna Kumar Date: Tue, 7 Apr 2026 15:29:28 +0530 Subject: [PATCH 2/6] 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 5d6781db3..933d125cb 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 267ef202dfb65dff38334c4c79630301aa7b3835 Mon Sep 17 00:00:00 2001 From: Ashwin Krishna Kumar Date: Tue, 7 Apr 2026 16:37:28 +0530 Subject: [PATCH 3/6] 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 933d125cb..898827f55 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 # ========================================== @@ -168,14 +168,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 @@ -194,7 +194,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 }}" @@ -220,8 +220,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 @@ -241,7 +241,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 624be5bd88c24cebef9594f7c37133e80c009f16 Mon Sep 17 00:00:00 2001 From: Ashwin Krishna Kumar Date: Tue, 7 Apr 2026 16:54:53 +0530 Subject: [PATCH 4/6] 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 898827f55..f7cb452e0 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 # ========================================== @@ -168,14 +154,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 @@ -194,7 +180,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 }}" @@ -219,11 +205,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' || '' }} \ @@ -241,12 +225,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 6ccbd5dec505519926adc24e9a73d5c81b588b16 Mon Sep 17 00:00:00 2001 From: Ashwin Krishna Kumar Date: Tue, 7 Apr 2026 18:45:53 +0530 Subject: [PATCH 5/6] 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 f7cb452e0..6da3ad6b7 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 From 22441a25f5115e18266684984b827124a80fe2e3 Mon Sep 17 00:00:00 2001 From: Ashwin Krishna Kumar Date: Mon, 13 Apr 2026 06:27:30 +0530 Subject: [PATCH 6/6] Change PR comment context --- .github/workflows/checklist_comment_on_new_pr.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/checklist_comment_on_new_pr.yml b/.github/workflows/checklist_comment_on_new_pr.yml index fda81de21..cb287ef05 100644 --- a/.github/workflows/checklist_comment_on_new_pr.yml +++ b/.github/workflows/checklist_comment_on_new_pr.yml @@ -1,6 +1,7 @@ name: Comment on new Pull Request with checklist on: - pull_request: + # safe as long as this workflow doesn't access code from the PR branch + pull_request_target: types: opened jobs: