From 4404da0b295f6f717f58df258f64a875e053bf06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maurycy=20Paw=C5=82owski-Wiero=C5=84ski?= Date: Fri, 13 Nov 2026 05:54:14 +0100 Subject: [PATCH 1/2] zimzor in templates --- bench_runner/scripts/install.py | 7 ++-- bench_runner/templates/_benchmark.src.yml | 38 +++++++++++++++++-- bench_runner/templates/_find_failures.src.yml | 7 ++++ bench_runner/templates/_generate.src.yml | 5 +++ bench_runner/templates/_notify.src.yml | 16 +++++++- bench_runner/templates/_publish.src.yml | 10 ++++- bench_runner/templates/_pystats.src.yml | 13 ++++++- bench_runner/templates/_weekly.src.yml | 20 +++++++--- bench_runner/templates/benchmark.src.yml | 38 ++++++++++++++----- bench_runner/templates/ci.src.yml | 6 +++ 10 files changed, 136 insertions(+), 24 deletions(-) diff --git a/bench_runner/scripts/install.py b/bench_runner/scripts/install.py index 4ad9adee..08aed250 100644 --- a/bench_runner/scripts/install.py +++ b/bench_runner/scripts/install.py @@ -133,8 +133,9 @@ def add_flag_env(jobs: dict[str, Any]): job.setdefault("env", {}) job["env"]["flags"] = flag_value for step in job["steps"]: - if "run" in step: - step["run"] = step["run"].replace("${{ env.flags }}", flag_value) + for key, value in step.get("env", {}).items(): + if isinstance(value, str): + step["env"][key] = value.replace("${{ env.flags }}", flag_value) def generate__benchmark(src: Any) -> Any: @@ -271,6 +272,7 @@ def generate__weekly(dst: Any) -> Any: ) job = { "uses": "./.github/workflows/_benchmark.yml", + "permissions": {"contents": "write"}, "needs": "determine_head", "with": { "fork": "python", @@ -280,7 +282,6 @@ def generate__weekly(dst: Any) -> Any: "pgo": True, **flags.flags_to_gha_variables_yml(weekly_cfg.flags), }, - "secrets": "inherit", } job_name = f"weekly-{name}-{runner.nickname}" dst["jobs"][job_name] = job diff --git a/bench_runner/templates/_benchmark.src.yml b/bench_runner/templates/_benchmark.src.yml index f97dee05..5782c48e 100644 --- a/bench_runner/templates/_benchmark.src.yml +++ b/bench_runner/templates/_benchmark.src.yml @@ -55,9 +55,13 @@ name: _benchmark description: "Collect Linux perf profiling data (Linux only)" type: boolean +permissions: {} + jobs: benchmark-windows: runs-on: [self-hosted, windows, bare-metal] + permissions: + contents: write steps: # Tell git to checkout repos with symlinks (required by pyston @@ -68,12 +72,20 @@ jobs: git config --global core.symlinks true - name: Checkout benchmarking uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: true - name: git gc run: | git gc - name: Building Python and running pyperformance + env: + FORK: ${{ inputs.fork }} + REF: ${{ inputs.ref }} + MACHINE: ${{ inputs.machine }} + BENCHMARKS: ${{ inputs.benchmarks || 'all' }} + FLAGS: ${{ env.flags }} run: | - py workflow_bootstrap.py ${{ inputs.fork }} ${{ inputs.ref }} ${{ inputs.machine }} ${{ inputs.benchmarks || 'all' }} "${{ env.flags }}" ${{ inputs.force && '--force' || '' }} ${{ inputs.pgo && '--pgo' || '' }} --run_id ${{ github.run_id }} + py workflow_bootstrap.py $env:FORK $env:REF $env:MACHINE $env:BENCHMARKS "$env:FLAGS" ${{ inputs.force && '--force' || '' }} ${{ inputs.pgo && '--pgo' || '' }} --run_id ${{ github.run_id }} # Pull again, since another job may have committed results in the meantime - name: Pull benchmarking run: | @@ -97,10 +109,14 @@ jobs: benchmark-linux: runs-on: [self-hosted, linux, bare-metal] timeout-minutes: 1440 + permissions: + contents: write steps: - name: Checkout benchmarking uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: true - name: git gc run: | git gc @@ -111,8 +127,14 @@ jobs: with: python-version: "3.11" - name: Building Python and running pyperformance + env: + FORK: ${{ inputs.fork }} + REF: ${{ inputs.ref }} + MACHINE: ${{ inputs.machine }} + BENCHMARKS: ${{ inputs.benchmarks || 'all' }} + FLAGS: ${{ env.flags }} run: | - python workflow_bootstrap.py ${{ inputs.fork }} ${{ inputs.ref }} ${{ inputs.machine }} ${{ inputs.benchmarks || 'all' }} ${{ env.flags }} ${{ inputs.force && '--force' || '' }} ${{ inputs.pgo && '--pgo' || '' }} ${{ inputs.perf && '--perf' || '' }} --run_id ${{ github.run_id }} + python workflow_bootstrap.py "$FORK" "$REF" "$MACHINE" "$BENCHMARKS" "$FLAGS" ${{ inputs.force && '--force' || '' }} ${{ inputs.pgo && '--pgo' || '' }} ${{ inputs.perf && '--perf' || '' }} --run_id ${{ github.run_id }} # Pull again, since another job may have committed results in the meantime - name: Pull benchmarking if: ${{ !inputs.perf }} @@ -145,16 +167,26 @@ jobs: benchmark-darwin: runs-on: [self-hosted, macos, bare-metal] + permissions: + contents: write steps: - name: Checkout benchmarking uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: true - name: git gc run: | git gc - name: Building Python and running pyperformance + env: + FORK: ${{ inputs.fork }} + REF: ${{ inputs.ref }} + MACHINE: ${{ inputs.machine }} + BENCHMARKS: ${{ inputs.benchmarks || 'all' }} + FLAGS: ${{ env.flags }} run: | - python3 workflow_bootstrap.py ${{ inputs.fork }} ${{ inputs.ref }} ${{ inputs.machine }} ${{ inputs.benchmarks || 'all' }} ${{ env.flags }} ${{ inputs.force && '--force' || '' }} ${{ inputs.pgo && '--pgo' || '' }} --run_id ${{ github.run_id }} + python3 workflow_bootstrap.py "$FORK" "$REF" "$MACHINE" "$BENCHMARKS" "$FLAGS" ${{ inputs.force && '--force' || '' }} ${{ inputs.pgo && '--pgo' || '' }} --run_id ${{ github.run_id }} # Pull again, since another job may have committed results in the meantime - name: Pull benchmarking run: | diff --git a/bench_runner/templates/_find_failures.src.yml b/bench_runner/templates/_find_failures.src.yml index b2346454..dca72416 100644 --- a/bench_runner/templates/_find_failures.src.yml +++ b/bench_runner/templates/_find_failures.src.yml @@ -6,12 +6,19 @@ name: _find_failures - cron: "0 22 * * 0" workflow_dispatch: {} +permissions: {} + jobs: find_failures: runs-on: ubuntu-latest + permissions: + actions: read + contents: write steps: - name: Checkout benchmarking uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: true - name: Setup system Python uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: diff --git a/bench_runner/templates/_generate.src.yml b/bench_runner/templates/_generate.src.yml index 2f4e4c8c..7870ad2b 100644 --- a/bench_runner/templates/_generate.src.yml +++ b/bench_runner/templates/_generate.src.yml @@ -22,13 +22,18 @@ name: _generate type: boolean default: false +permissions: {} + jobs: generate-results: runs-on: ubuntu-latest + permissions: + contents: write steps: - name: Checkout benchmarking uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: + persist-credentials: true ref: main - name: Checkout CPython uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 diff --git a/bench_runner/templates/_notify.src.yml b/bench_runner/templates/_notify.src.yml index 7aa68421..fae4f883 100644 --- a/bench_runner/templates/_notify.src.yml +++ b/bench_runner/templates/_notify.src.yml @@ -15,9 +15,15 @@ name: _notify version: type: string +permissions: {} + jobs: notify: runs-on: ubuntu-latest + permissions: + actions: read + contents: read + issues: write steps: - uses: technote-space/workflow-conclusion-action@45ce8e0eb155657ab8ccf346ade734257fd196a5 #v3.0.3 - name: Checkout benchmarking @@ -34,6 +40,12 @@ jobs: pip install -r requirements.txt - name: Send notifications if: env.WORKFLOW_CONCLUSION == 'success' - run: python -m bench_runner notify --fork ${{ inputs.fork }} --ref ${{ inputs.ref }} --head ${{ inputs.head }} --date ${{ inputs.date }} --version ${{ inputs.version }} --flags ${{ env.flags }} + run: python -m bench_runner notify --fork "$FORK" --ref "$REF" --head "$HEAD" --date "$DATE" --version "$VERSION" --flags "$FLAGS" env: - GH_TOKEN: ${{ github.token }} \ No newline at end of file + GH_TOKEN: ${{ github.token }} + FORK: ${{ inputs.fork }} + REF: ${{ inputs.ref }} + HEAD: ${{ inputs.head }} + DATE: ${{ inputs.date }} + VERSION: ${{ inputs.version }} + FLAGS: ${{ env.flags }} \ No newline at end of file diff --git a/bench_runner/templates/_publish.src.yml b/bench_runner/templates/_publish.src.yml index 52064d7d..3f7d1a1f 100644 --- a/bench_runner/templates/_publish.src.yml +++ b/bench_runner/templates/_publish.src.yml @@ -7,6 +7,9 @@ name: _publish dry_run: type: boolean default: false + secrets: + BENCHMARK_MIRROR: + required: true workflow_dispatch: inputs: @@ -15,13 +18,18 @@ name: _publish type: boolean default: false +permissions: {} + jobs: mirror: runs-on: ubuntu-latest + permissions: + contents: read steps: - name: Checkout benchmarking uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: + persist-credentials: true ref: main # This has to be enough depth to handle since the last time we published. # As a rule of thumb, (number of machines * 2, plus the generated stuff) * 2 @@ -29,5 +37,5 @@ jobs: token: ${{ secrets.BENCHMARK_MIRROR }} - name: Mirror run: | - git remote add public https://github.com/${{ github.repository }}-public + git remote add public "https://github.com/$GITHUB_REPOSITORY-public" git push -f public main diff --git a/bench_runner/templates/_pystats.src.yml b/bench_runner/templates/_pystats.src.yml index 8a91278d..943904bb 100644 --- a/bench_runner/templates/_pystats.src.yml +++ b/bench_runner/templates/_pystats.src.yml @@ -37,12 +37,18 @@ name: _pystats description: "Rerun and replace results if commit already exists" type: boolean +permissions: {} + jobs: collect-stats: runs-on: [self-hosted, linux, cloud] + permissions: + contents: write steps: - name: Checkout benchmarking uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: true - name: git gc run: | git gc @@ -51,8 +57,13 @@ jobs: with: python-version: "3.11" - name: Build CPython and run pyperformance benchmarks + env: + FORK: ${{ inputs.fork }} + REF: ${{ inputs.ref }} + BENCHMARKS: ${{ inputs.benchmarks || 'all' }} + FLAGS: ${{ env.flags }} run: | - python workflow_bootstrap.py --pystats ${{ inputs.fork }} ${{ inputs.ref }} all ${{ inputs.benchmarks || 'all' }} ${{ env.flags }} --run_id ${{ github.run_id }} + python workflow_bootstrap.py --pystats "$FORK" "$REF" all "$BENCHMARKS" "$FLAGS" --run_id ${{ github.run_id }} - name: Pull benchmarking run: | # Another benchmarking task may have created results for the same diff --git a/bench_runner/templates/_weekly.src.yml b/bench_runner/templates/_weekly.src.yml index 9f53a42d..a50b810b 100644 --- a/bench_runner/templates/_weekly.src.yml +++ b/bench_runner/templates/_weekly.src.yml @@ -6,12 +6,16 @@ name: _weekly - cron: "0 0 * * 0" workflow_dispatch: {} +permissions: {} + jobs: # Determine the base commit of the selected commit. The output is passed to # the `base` job below. If the data already exists for this commit, it will be # skipped. determine_head: runs-on: ubuntu-latest + permissions: + contents: read outputs: commit: ${{ steps.head.outputs.commit }} steps: @@ -26,38 +30,44 @@ jobs: id: head run: | cd cpython - git log -n 1 --format="commit=%H" >> $GITHUB_OUTPUT + git log -n 1 --format="commit=%H" >> "$GITHUB_OUTPUT" pystats: uses: ./.github/workflows/_pystats.yml + permissions: + contents: write needs: determine_head with: fork: python ref: ${{ needs.determine_head.outputs.commit }} benchmarks: all tier2: false - secrets: inherit pystats-tier2: uses: ./.github/workflows/_pystats.yml + permissions: + contents: write needs: determine_head with: fork: python ref: ${{ needs.determine_head.outputs.commit }} benchmarks: all tier2: true - secrets: inherit generate: uses: ./.github/workflows/_generate.yml + permissions: + contents: write if: ${{ always() }} with: force: false needs: [pystats, pystats-tier2] - secrets: inherit publish: uses: ./.github/workflows/_publish.yml + permissions: + contents: read if: ${{ always() }} needs: [generate] - secrets: inherit + secrets: + BENCHMARK_MIRROR: ${{ secrets.BENCHMARK_MIRROR }} diff --git a/bench_runner/templates/benchmark.src.yml b/bench_runner/templates/benchmark.src.yml index 9ee61f9d..c6f51e34 100644 --- a/bench_runner/templates/benchmark.src.yml +++ b/bench_runner/templates/benchmark.src.yml @@ -32,12 +32,16 @@ run-name: benchmarking ${{ inputs.fork }}/${{ inputs.ref }} on ${{ inputs.machin type: boolean default: false +permissions: {} + jobs: # Determine the base commit of the selected commit. The output is passed to # the `base` job below. If the data already exists for this commit, it will be # skipped. determine_base: runs-on: ubuntu-latest + permissions: + contents: read outputs: head: ${{ steps.base.outputs.head }} date: ${{ steps.base.outputs.date }} @@ -67,12 +71,19 @@ jobs: pip install -r requirements.txt - name: Determine base id: base + env: + BENCHMARK_BASE: ${{ inputs.benchmark_base }} + MACHINE: ${{ inputs.machine }} + PYSTATS: ${{ inputs.pystats }} + FLAGS: ${{ env.flags }} run: | - python -m bench_runner get_merge_base ${{ inputs.benchmark_base }} ${{ inputs.machine }} ${{ inputs.pystats }} ${{ env.flags }} >> $GITHUB_OUTPUT - cat $GITHUB_OUTPUT + python -m bench_runner get_merge_base "$BENCHMARK_BASE" "$MACHINE" "$PYSTATS" "$FLAGS" >> "$GITHUB_OUTPUT" + cat "$GITHUB_OUTPUT" head: uses: ./.github/workflows/_benchmark.yml + permissions: + contents: write with: fork: ${{ inputs.fork }} ref: ${{ inputs.ref }} @@ -81,10 +92,11 @@ jobs: pgo: true perf: false force: true - secrets: inherit base: uses: ./.github/workflows/_benchmark.yml + permissions: + contents: write needs: determine_base if: ${{ needs.determine_base.outputs.need_to_run != 'false' }} with: @@ -95,20 +107,22 @@ jobs: pgo: true perf: false force: false - secrets: inherit pystats-head: uses: ./.github/workflows/_pystats.yml + permissions: + contents: write if: ${{ inputs.pystats }} with: fork: ${{ inputs.fork }} ref: ${{ inputs.ref }} benchmarks: ${{ inputs.benchmarks }} force: true - secrets: inherit pystats-base: uses: ./.github/workflows/_pystats.yml + permissions: + contents: write needs: determine_base if: ${{ inputs.pystats && needs.determine_base.outputs.need_to_run != 'false' }} with: @@ -116,24 +130,31 @@ jobs: ref: ${{ needs.determine_base.outputs.ref }} benchmarks: ${{ inputs.benchmarks }} force: false - secrets: inherit generate: uses: ./.github/workflows/_generate.yml + permissions: + contents: write with: force: false if: ${{ always() }} needs: [head, base, pystats-head, pystats-base] - secrets: inherit publish: uses: ./.github/workflows/_publish.yml + permissions: + contents: read if: ${{ always() }} needs: [generate] - secrets: inherit + secrets: + BENCHMARK_MIRROR: ${{ secrets.BENCHMARK_MIRROR }} notify: uses: ./.github/workflows/_notify.yml + permissions: + actions: read + contents: read + issues: write if: ${{ always() }} needs: [publish, determine_base] with: @@ -142,4 +163,3 @@ jobs: head: ${{ needs.determine_base.outputs.head }} date: ${{ needs.determine_base.outputs.date }} version: ${{ needs.determine_base.outputs.version }} - secrets: inherit diff --git a/bench_runner/templates/ci.src.yml b/bench_runner/templates/ci.src.yml index 9531f946..74c8bd65 100644 --- a/bench_runner/templates/ci.src.yml +++ b/bench_runner/templates/ci.src.yml @@ -7,11 +7,17 @@ name: ci branches: - main +permissions: {} + jobs: test: runs-on: ubuntu-latest + permissions: + contents: read steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: "3.11" From 102daba6fe86cdc67d09427d879edd060b47a667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maurycy=20Paw=C5=82owski-Wiero=C5=84ski?= Date: Fri, 13 Nov 2026 21:07:55 +0100 Subject: [PATCH 2/2] hook --- .pre-commit-config.yaml | 5 +++++ DEVELOPER.md | 3 ++- zizmor.yml | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 zizmor.yml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d7b3cfdf..cb6818fd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,6 +16,11 @@ repos: files: ^\.github/ types: [file] # Include actions.lock. stages: [pre-commit] + - id: zizmor + name: zizmor (templates) + args: [--offline] + files: ^bench_runner/templates/.*\.src\.yml$ + stages: [pre-commit] - repo: local hooks: diff --git a/DEVELOPER.md b/DEVELOPER.md index 0547cf25..0eb5bd45 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -13,7 +13,8 @@ prek install prek run --all-files ``` -The hooks include zizmor checks for `.github`. +The hooks include zizmor checks for `.github` and the workflow templates in +`bench_runner/templates`. After changing action references or adding workflows under `.github/workflows`, run `gh actions-lock` and commit the updated lockfile with the workflow changes. diff --git a/zizmor.yml b/zizmor.yml new file mode 100644 index 00000000..94f46a42 --- /dev/null +++ b/zizmor.yml @@ -0,0 +1,3 @@ +rules: + self-repository: + disable: true