From 8b5a60b206f2733f76f9432f91515592695ef4f7 Mon Sep 17 00:00:00 2001 From: ZhouGuangyuan Date: Thu, 23 Jul 2026 16:33:49 +0800 Subject: [PATCH 1/2] ci: persist dispatched LLGo pins before building --- .github/workflows/llgo-binary-size.yml | 76 +++++++++++++++++++------- ci/llgo-size/README.md | 14 +++-- docs/llgo-binary-size-handoff.md | 2 +- 3 files changed, 65 insertions(+), 27 deletions(-) diff --git a/.github/workflows/llgo-binary-size.yml b/.github/workflows/llgo-binary-size.yml index fe0f64b..8450d51 100644 --- a/.github/workflows/llgo-binary-size.yml +++ b/.github/workflows/llgo-binary-size.yml @@ -9,6 +9,8 @@ on: - ci/llgo-size/publish-site.sh - ci/llgo-size/prepare-pages-branch.sh - .github/workflows/llgo-binary-size-pages.yml + # ci/llgo-size/llgo-version.env is intentionally not ignored: changing + # the committed LLGo pin must trigger a binary-size build. pull_request: paths-ignore: - ci/llgo-size/site/** @@ -29,23 +31,71 @@ on: permissions: contents: write + actions: write concurrency: group: llgo-binary-size-pages cancel-in-progress: false jobs: - binary-size: + update-pin: + if: github.event_name == 'repository_dispatch' runs-on: ubuntu-24.04 - timeout-minutes: 120 steps: - uses: actions/checkout@v4 - - name: Read pinned toolchain versions + - name: Update the committed LLGo pin and start the build env: DISPATCH_SOURCE_REPOSITORY: ${{ github.event.client_payload.source_repository }} DISPATCH_LLGO_REPOSITORY: ${{ github.event.client_payload.llgo_repository }} DISPATCH_LLGO_COMMIT: ${{ github.event.client_payload.llgo_commit }} + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + if [[ "$DISPATCH_SOURCE_REPOSITORY" != "xgo-dev/llgo" || \ + "$DISPATCH_LLGO_REPOSITORY" != "xgo-dev/llgo" ]]; then + echo "refusing binary-size dispatch from ${DISPATCH_SOURCE_REPOSITORY:-unknown}" >&2 + exit 1 + fi + if [[ ! "$DISPATCH_LLGO_COMMIT" =~ ^[0-9a-f]{40}$ ]]; then + echo "invalid dispatched LLGo commit: ${DISPATCH_LLGO_COMMIT:-missing}" >&2 + exit 1 + fi + + current_commit="$(awk -F= '$1 == "LLGO_COMMIT" { print $2 }' ci/llgo-size/llgo-version.env)" + if [[ "$current_commit" == "$DISPATCH_LLGO_COMMIT" ]]; then + echo "LLGo pin is already $DISPATCH_LLGO_COMMIT; no build needed" + exit 0 + fi + + sed -i "s/^LLGO_COMMIT=.*/LLGO_COMMIT=${DISPATCH_LLGO_COMMIT}/" \ + ci/llgo-size/llgo-version.env + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add ci/llgo-size/llgo-version.env + git commit -m "ci: pin LLGo ${DISPATCH_LLGO_COMMIT:0:12}" + git push origin HEAD:main + + payload="$(jq -cn \ + --arg ref main \ + --arg llgo_commit "$DISPATCH_LLGO_COMMIT" \ + '{ref: $ref, inputs: {llgo_commit: $llgo_commit}}')" + curl --fail-with-body --location --request POST \ + --header 'Accept: application/vnd.github+json' \ + --header "Authorization: Bearer ${GH_TOKEN}" \ + --header 'X-GitHub-Api-Version: 2022-11-28' \ + "https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/llgo-binary-size.yml/dispatches" \ + --data "$payload" + + binary-size: + if: github.event_name != 'repository_dispatch' + runs-on: ubuntu-24.04 + timeout-minutes: 120 + steps: + - uses: actions/checkout@v4 + + - name: Read pinned toolchain versions + env: MANUAL_LLGO_COMMIT: ${{ inputs.llgo_commit }} run: | set -euo pipefail @@ -53,21 +103,7 @@ jobs: source ci/llgo-size/llgo-version.env set +a - # The dispatched SHA is the run's runtime pin and is retained in - # results.json / Pages. Restrict automatic events to official LLGo. - if [[ "$GITHUB_EVENT_NAME" == "repository_dispatch" ]]; then - if [[ "$DISPATCH_SOURCE_REPOSITORY" != "xgo-dev/llgo" || \ - "$DISPATCH_LLGO_REPOSITORY" != "xgo-dev/llgo" ]]; then - echo "refusing binary-size dispatch from ${DISPATCH_SOURCE_REPOSITORY:-unknown}" >&2 - exit 1 - fi - if [[ ! "$DISPATCH_LLGO_COMMIT" =~ ^[0-9a-f]{40}$ ]]; then - echo "invalid dispatched LLGo commit: ${DISPATCH_LLGO_COMMIT:-missing}" >&2 - exit 1 - fi - LLGO_REPOSITORY="$DISPATCH_LLGO_REPOSITORY" - LLGO_COMMIT="$DISPATCH_LLGO_COMMIT" - elif [[ -n "$MANUAL_LLGO_COMMIT" ]]; then + if [[ -n "$MANUAL_LLGO_COMMIT" ]]; then if [[ ! "$MANUAL_LLGO_COMMIT" =~ ^[0-9a-f]{40}$ ]]; then echo "manual LLGo commit must be a full 40-character SHA" >&2 exit 1 @@ -173,7 +209,7 @@ jobs: if-no-files-found: error - name: Publish binary-size history to Pages - if: github.event_name == 'repository_dispatch' || (github.event_name != 'pull_request' && github.ref == 'refs/heads/main') + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' env: PAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | @@ -187,7 +223,7 @@ jobs: "$pages_dir" \ ci/llgo-size/site deploy-pages: - if: github.event_name == 'repository_dispatch' || (github.event_name != 'pull_request' && github.ref == 'refs/heads/main') + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' needs: binary-size runs-on: ubuntu-24.04 permissions: diff --git a/ci/llgo-size/README.md b/ci/llgo-size/README.md index 77c9e2d..9cc5625 100644 --- a/ci/llgo-size/README.md +++ b/ci/llgo-size/README.md @@ -29,12 +29,14 @@ and TSV result as an artifact. The summary also contains Bent's native per-case build timings; `build-times.tsv`, `timing-summary.md`, `download-timings.log`, and raw `.build` files are retained for diagnosing slow downloads or builds. -The `llgo-main-updated` repository-dispatch event from `xgo-dev/llgo` replaces -the default pin with its complete `llgo_commit` for that run. That exact commit -is retained in `results.json` and the Pages history, so every LLGo `main` -update has a comparable data point without committing a moving pin back to -this repository. GitHub requires the receiver workflow to be on the -benchmarks repository's default branch before it can receive this event. +The `llgo-main-updated` repository-dispatch event from `xgo-dev/llgo` first +updates `LLGO_COMMIT` on the benchmarks `main` branch, then explicitly starts a +`workflow_dispatch` build with that complete SHA. This makes the version-file +update and the published result one ordered operation without relying on a +`GITHUB_TOKEN`-created push to trigger another workflow. The exact commit is +retained in `results.json` and the Pages history, so every LLGo `main` update +has a comparable data point. GitHub requires the receiver workflow to be on +the benchmarks repository's default branch before it can receive this event. The workflow sources `timing.sh` for its shared CI step timing output. It invokes Bent with four configurable build workers (`BENT_BUILD_WORKERS=4`); set that environment value to `1` to reproduce a serial build. diff --git a/docs/llgo-binary-size-handoff.md b/docs/llgo-binary-size-handoff.md index 557ece3..9e87df2 100644 --- a/docs/llgo-binary-size-handoff.md +++ b/docs/llgo-binary-size-handoff.md @@ -28,7 +28,7 @@ 入口工作流:[.github/workflows/llgo-binary-size.yml](../.github/workflows/llgo-binary-size.yml) -1. 读取 [ci/llgo-size/llgo-version.env](../ci/llgo-size/llgo-version.env) 的默认 LLGo、Go 和 LLVM 版本;LLGo `main` 的跨仓库事件会以其精确提交覆盖默认 LLGo pin。 +1. 读取 [ci/llgo-size/llgo-version.env](../ci/llgo-size/llgo-version.env) 的默认 LLGo、Go 和 LLVM 版本;LLGo `main` 的跨仓库事件会先更新该 pin,再显式启动一次构建和 Pages 发布。 2. 安装 LLVM 19、构建 LLGo 命令与 LTO plugin。 3. 用 Bent 对每个 suite 运行 Go + 4 个 LLGo 配置,产出 `benchsize` 的 JSON/TSV/raw 文件;CI 通过 `-j="$BENT_BUILD_WORKERS"` 并发构建,当前值为 4。 4. [report.sh](../ci/llgo-size/report.sh) 整理结果和构建/下载耗时。 From 29dc4768a09f5c91feb400a33815e7b33812582a Mon Sep 17 00:00:00 2001 From: ZhouGuangyuan Date: Thu, 23 Jul 2026 16:42:49 +0800 Subject: [PATCH 2/2] ci: guard Pages-only publication --- .github/workflows/llgo-binary-size-pages.yml | 4 ++++ ci/llgo-size/README.md | 5 +++++ docs/llgo-binary-size-handoff.md | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/.github/workflows/llgo-binary-size-pages.yml b/.github/workflows/llgo-binary-size-pages.yml index 2f13635..5acc5a0 100644 --- a/.github/workflows/llgo-binary-size-pages.yml +++ b/.github/workflows/llgo-binary-size-pages.yml @@ -20,6 +20,9 @@ concurrency: jobs: publish-site: + # Page-only publication is allowed only from the canonical main branch. + # Keep this guard even though pull_request is not currently a trigger. + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 @@ -35,6 +38,7 @@ jobs: ci/llgo-size/publish-site.sh "$pages_dir" ci/llgo-size/site deploy-pages: + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' needs: publish-site runs-on: ubuntu-24.04 permissions: diff --git a/ci/llgo-size/README.md b/ci/llgo-size/README.md index 9cc5625..0ab7b76 100644 --- a/ci/llgo-size/README.md +++ b/ci/llgo-size/README.md @@ -52,6 +52,11 @@ the Pages root lists all published runs and lets you compare any two runs by benchmark and configuration. Pull requests still build and upload an artifact but do not modify the history. +Changes that only touch the dashboard source or its publication scripts use the +separate `llgo-binary-size-pages.yml` workflow. That path publishes the updated +site directly without rebuilding benchmarks, and its publication jobs are +restricted to `main`; pull-request builds cannot publish Pages. + ### First-time repository setup The first publisher run creates the `pages` branch automatically. Before that diff --git a/docs/llgo-binary-size-handoff.md b/docs/llgo-binary-size-handoff.md index 9e87df2..ab1499a 100644 --- a/docs/llgo-binary-size-handoff.md +++ b/docs/llgo-binary-size-handoff.md @@ -35,6 +35,10 @@ 5. [publish.sh](../ci/llgo-size/publish.sh) 将结果归档到 `pages/data/runs/-/`,更新 `data/index.json`。 6. `deploy-pages` job 检出 `pages` 分支,用 Jekyll 构建后通过 GitHub Pages artifact 部署。 +只修改仪表盘源码或页面发布脚本时,不进入二进制大小构建;独立的 +`llgo-binary-size-pages.yml` 会直接刷新 `pages` 分支并部署站点。该工作流和 +主工作流的发布 job 都限制在 `main`,PR 构建只验证和上传 artifact,不会发布。 + 核心文件: - [Bent suites](../cmd/bent/configs/benchmarks-llgo-size.toml)