From b22b03e53d8929527a1c221dc7e932a9aba51531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=B0=D1=82-=D0=9E=D1=80=D1=88=D0=B8=D1=85?= Date: Thu, 19 Nov 2026 11:19:52 +0800 Subject: [PATCH 1/2] ci: pass branch refs and build target to scripts through env github.head_ref is the PR author's branch name and was expanded straight into run: scripts in the benchmark and coverage jobs. Pass it, base_ref and the build action's target input through environment variables and quote them, as GitHub's hardening guide recommends. No behaviour change. Co-Authored-By: Claude Opus 5.5 --- .github/actions/build/action.yml | 14 ++++++++++---- .github/workflows/ci.yml | 27 ++++++++++++++++++--------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index bc85c92..c8ab244 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -24,19 +24,25 @@ runs: - name: Build with cross (Linux) if: runner.os == 'Linux' shell: bash + env: + TARGET: ${{ inputs.target }} run: | cargo install cross --locked - cross build --release --locked --target ${{ inputs.target }} + cross build --release --locked --target "$TARGET" - name: Build natively (macOS/Windows) if: runner.os != 'Linux' shell: bash - run: cargo build --release --locked --target ${{ inputs.target }} + env: + TARGET: ${{ inputs.target }} + run: cargo build --release --locked --target "$TARGET" - name: Final path id: get_binary_path shell: bash + env: + TARGET: ${{ inputs.target }} run: | binary=yek - [ "${{ runner.os }}" = "Windows" ] && binary=yek.exe - echo "path=target/${{ inputs.target }}/release/$binary" >> "$GITHUB_OUTPUT" + [ "$RUNNER_OS" = "Windows" ] && binary=yek.exe + echo "path=target/$TARGET/release/$binary" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 482f101..b771d8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -212,15 +212,18 @@ jobs: - uses: dtolnay/rust-toolchain@stable - name: Run benchmarks + env: + BASE_REF: ${{ github.base_ref }} + HEAD_REF: ${{ github.head_ref }} run: | - git fetch origin ${{ github.base_ref }} - git checkout ${{ github.base_ref }} + git fetch origin "$BASE_REF" + git checkout "$BASE_REF" cargo bench --bench serialization --no-run - cargo bench --bench serialization -- --save-baseline ${{ github.base_ref }} '${{ matrix.benchmark_group.group }}/' + cargo bench --bench serialization -- --save-baseline "$BASE_REF" '${{ matrix.benchmark_group.group }}/' - git checkout ${{ github.head_ref }} + git checkout "$HEAD_REF" cargo bench --bench serialization --no-run - cargo bench --bench serialization -- --baseline ${{ github.base_ref }} --noise-threshold 2 '${{ matrix.benchmark_group.group }}/' > benchmark_results.md + cargo bench --bench serialization -- --baseline "$BASE_REF" --noise-threshold 2 '${{ matrix.benchmark_group.group }}/' > benchmark_results.md echo "## Benchmark Results for ${{ matrix.benchmark_group.name }}" >> $GITHUB_STEP_SUMMARY cat benchmark_results.md >> $GITHUB_STEP_SUMMARY @@ -260,9 +263,11 @@ jobs: # --- Base Branch Coverage --- - name: Fetch and check out base branch if: github.event_name == 'pull_request' + env: + BASE_REF: ${{ github.base_ref }} run: | - git fetch origin ${{ github.base_ref }} - git checkout ${{ github.base_ref }} + git fetch origin "$BASE_REF" + git checkout "$BASE_REF" - name: Build + Test coverage on base if: github.event_name == 'pull_request' @@ -293,8 +298,10 @@ jobs: # --- PR Branch Coverage --- - name: Check out head branch (PR) if: github.event_name == 'pull_request' + env: + HEAD_REF: ${{ github.head_ref }} run: | - git checkout ${{ github.head_ref }} + git checkout "$HEAD_REF" - name: Build + Test coverage on PR run: | @@ -323,6 +330,8 @@ jobs: - name: Compare coverage if: github.event_name == 'pull_request' + env: + BASE_REF: ${{ github.base_ref }} run: | # Check if base coverage file exists if [ ! -f coverage-base/coverage.json ]; then @@ -341,7 +350,7 @@ jobs: # Compare and fail if coverage decreased check=$(awk -v base="$BASE_COV" -v pr="$PR_COV" 'BEGIN { if (pr < base) print 1; else print 0; }') if [ "$check" -eq 1 ]; then - git diff --unified=0 origin/${{ github.base_ref }}...HEAD -- 'src/*.rs' \ + git diff --unified=0 "origin/$BASE_REF...HEAD" -- 'src/*.rs' \ | awk ' /^\+\+\+ b\/src\// { file = substr($0, 11); next } /^@@/ { From 156dfebec14b6d1e88a16f5916239aa4799c2bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=B0=D1=82-=D0=9E=D1=80=D1=88=D0=B8=D1=85?= Date: Thu, 19 Nov 2026 11:26:53 +0800 Subject: [PATCH 2/2] ci: check out the fetched commit, not the PR branch by name On a fork PR the head branch exists only in the fork, so 'git checkout ' failed with 'pathspec did not match' and the coverage and benchmark jobs failed for every outside contributor (#259 too). Return to $GITHUB_SHA, the commit actions/checkout already fetched. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b771d8b..9c50526 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -214,14 +214,14 @@ jobs: - name: Run benchmarks env: BASE_REF: ${{ github.base_ref }} - HEAD_REF: ${{ github.head_ref }} run: | git fetch origin "$BASE_REF" git checkout "$BASE_REF" cargo bench --bench serialization --no-run cargo bench --bench serialization -- --save-baseline "$BASE_REF" '${{ matrix.benchmark_group.group }}/' - git checkout "$HEAD_REF" + # Back to the commit actions/checkout fetched; a fork's branch is not on origin. + git checkout "$GITHUB_SHA" cargo bench --bench serialization --no-run cargo bench --bench serialization -- --baseline "$BASE_REF" --noise-threshold 2 '${{ matrix.benchmark_group.group }}/' > benchmark_results.md echo "## Benchmark Results for ${{ matrix.benchmark_group.name }}" >> $GITHUB_STEP_SUMMARY @@ -298,10 +298,9 @@ jobs: # --- PR Branch Coverage --- - name: Check out head branch (PR) if: github.event_name == 'pull_request' - env: - HEAD_REF: ${{ github.head_ref }} run: | - git checkout "$HEAD_REF" + # Back to the commit actions/checkout fetched; a fork's branch is not on origin. + git checkout "$GITHUB_SHA" - name: Build + Test coverage on PR run: |