Repository navigation
ci: 本仓 PR 唯一 test 门禁与 workflow 策略自测 - #21
Conversation
- Add .github/workflows/pr.yml: pull_request on main and tree/** plus merge_group, one hosted job named test running ./actions/mise-check with task check:pr - Restrict self-check.yml to push on main and tree/** so pull requests no longer produce check / check - Add selftest/workflows/policy.test.ts: offline bun test over .github/workflows/*.yml and actions/**/*.yml for unpinned external refs, persist-credentials: false, pr.yml path filters and continue-on-error, and the cross-repo self-hosted rejection - Add mise task check:pr and run the policy self-test from check, which keeps actionlint - Refs #17
…eck:pr - policy test executes the parse scripts of check.yml, image.yml and release-artifact.yml and guard.sh under fork and same-repo/hosted inputs; workflows with caller-controlled runs-on must be probed - check:pr runs actionlint (with shellcheck) before the policy test; check depends on check:pr Refs #17
证据包
结果 1 · 新功能 · service
结果 2 · 改功能(前后对比) · service
结果 3 · 改功能(前后对比) · service
结果 2 before · exit 0 ·
|
|
Gate 结论 · review · FAIL · HEAD b8f5daa · base tree/mouriya-devops-ci-16 · issue rev 2026-11-26T14:22:38Z · 设计 无 审查对象:证据包 #21 (comment) 与 PR 正文。结果 1 成立: 缺陷:
下一步:作者用 base 7a922e8 的 check-runs 重采结果 2 的 before;从仓库留下的痕迹给结果 3 补 before;更新正文。issue 现场的修正由 issue 作者处理。 |
证据包
结果 1 · 新功能 · service
结果 2 · 改功能(前后对比) · service
结果 3 · 改功能(前后对比) · service
结果 1 request · exit 0 ·
|
重试意图处理 #21 (comment) 的 FAIL,续用原分支,HEAD 仍为 实现变化无。 证据与正文
新证据包:#21 (comment) |
|
Gate 结论 · review · PASS · HEAD b8f5daa · base tree/mouriya-devops-ci-16 · issue rev 2026-11-26T14:22:38Z · 设计 无 增量复审,证据包 #21 (comment) 。
非阻塞:issue 现场的 |
* Add a PR gate and an offline workflow policy self-test - Add .github/workflows/pr.yml: pull_request on main and tree/** plus merge_group, one hosted job named test running ./actions/mise-check with task check:pr - Restrict self-check.yml to push on main and tree/** so pull requests no longer produce check / check - Add selftest/workflows/policy.test.ts: offline bun test over .github/workflows/*.yml and actions/**/*.yml for unpinned external refs, persist-credentials: false, pr.yml path filters and continue-on-error, and the cross-repo self-hosted rejection - Add mise task check:pr and run the policy self-test from check, which keeps actionlint - Refs #17 * selftest: run the fork-PR rejection for real and lint workflows in check:pr - policy test executes the parse scripts of check.yml, image.yml and release-artifact.yml and guard.sh under fork and same-repo/hosted inputs; workflows with caller-controlled runs-on must be probed - check:pr runs actionlint (with shellcheck) before the policy test; check depends on check:pr Refs #17
Closes #17
摘要
本仓新增
.github/workflows/pr.yml,在pull_request(main、tree/**)与merge_group上由托管 runner 的单 jobtest执行mise run check:pr;self-check.yml收窄为main/tree/**的 push 检查。mise.toml把actionlint与新增的selftest/workflows/policy.test.ts一起纳入check:pr,check改为它的依赖;策略自测扫描全仓 workflow 与 action,并实际执行三个 parse 脚本与actions/mise-check/guard.sh,证明跨仓 fork PR 被拒。仓库合并开关已收敛为仅 squash 并自动删除分支。实现说明
不变边界
actions/mise-check/action.yml、actions/mise-check/guard.sh、.github/workflows/check.yml、image.yml、release-artifact.yml不在git diff 7a922e8 b8f5daa中;新增的策略自测只读取并执行它们,不修改其行为(结果 1)。self-check.yml的改动只在on:jobs.check.uses: ./.github/workflows/check.yml与permissions: contents: read逐字未改,pull_request:触发被删除,push增加branches: [main, 'tree/**'](结果 2)。[tasks.check] run = "actionlint"被check:pr(actionlint && bun test selftest)完整包含,[tasks.check]只保留depends = ["check:pr"],命令不在两处重复维护(结果 1、2)。selftest:task、build、release三个 fixture task 与selftest/image、selftest/release脚本未改。allow_squash_merge: true、allow_merge_commit: false、allow_rebase_merge: false、delete_branch_on_merge: true;main没有分支保护,rulesets 为空,所以对外声明的唯一必过门禁只有test。机制
.github/workflows/pr.yml的on.pull_request.branches是[main, 'tree/**'],另有merge_group;permissions只有contents: read;concurrency.group为pr-${{ github.event.pull_request.number || github.ref }}且cancel-in-progress: true。唯一 job 是test,name: test、runs-on: ubuntu-24.04、timeout-minutes: 10,步骤为actions/checkout@main(persist-credentials: false)与./actions/mise-check(task: check:pr)。actions/mise-check是 composite action,作为testjob 的步骤执行,不经workflow_call,因此 CheckRun 名就是 job 的name: test,没有<caller> / <callee>前缀;selftest/workflows/policy.test.ts的pr.yml > exposes exactly one hosted job named test固定这一点。pr.yml用./actions/mise-check而不是mouriya-devops/ci/actions/mise-check@main。与@main引用相比,CheckRun 名仍精确为test、task输入面完全相同,而本仓改动actions/mise-check的 PR 由自己的test真实执行,不必等合入main后才生效。selftest/workflows/policy.test.ts用Bun.Glob收集.github/workflows/*.yml与actions/**/*.yml,walk遍历全部 mapping 后断言:外部uses只跟@main;每个actions/checkout@显式persist-credentials: false;pr.yml的触发键恰为merge_group+pull_request、分支恰为["main", "tree/**"]、恰有一个 jobtest、runs-on: ubuntu-24.04、task: check:pr、整个文件没有paths/paths-ignore/continue-on-error;self-check.yml只剩push且分支为["main", "tree/**"](结果 1、2)。runScript把check.yml、image.yml、release-artifact.yml的 parse 步骤run:写进临时目录,用必失败的gh、docker、skopeo(以及除 release-artifact 外的curl)桩替换外部命令,在bash --noprofile --norc -eo pipefail下执行;probes对pull_request与pull_request_target、["self-hosted","linux"]与["Self-Hosted","linux"]的每种组合要求非零退出并带拒绝消息,对["ubuntu-24.04"]要求放行。发现性断言要求被探测的 workflow 集合恰好等于所有 job 级runs-on含${{的 workflow(结果 1)。actions/mise-check/guard.sh按其源码执行:fork PR 在self-hosted与无法确认的 runner 上被拒,在github-hosted上放行,同仓 PR 在self-hosted上放行(结果 1)。[tasks."check:pr"] run = "actionlint && bun test selftest",[tasks.check] depends = ["check:pr"];[tools]增加bun = "latest"。pr.yml只调check:pr,合入后的self-check.yml仍调check。契约
test,由 job 的name固定,不是workflow_call派生名。缓冲分支 PR 的 head SHA 本身是tree/**的 push 目标,所以这个 head 上除test外还会出现self-check.yml→check.yml产出的check / parse与check / check,它们来自 push 事件而不是 PR 触发器;仓库没有分支保护与 rulesets,唯一声明的门禁仍是test。./actions/mise-check消费的是前置 ci:新增顶层 test 门禁 composite action actions/mise-check 与 check.yml task 参数 #19 交付的task输入,本地没有复制或重定义 action 内部逻辑;消费仓仍按mouriya-devops/ci/actions/mise-check@main引用同一个 action。mise run check:pr与mise run check两个任务名:pr.yml与self-check.yml只按任务名调用,check恒等于check:pr的集合。README.md的「## 检查」只记录这两个入口与各自触发器,不写实现细节。切换
self-check.yml的pull_request触发删除而停止:PR 分支原来经workflow_call产出的check / parse、check / check由pr.yml的单一test取代(结果 2,对应「不应残留」中「在 PR 上产出check / check而非顶层test的旧触发器」)。main与tree/**的 push 检查按 issue Anchor 保留:self-check.yml的jobs.check继续调check.yml,合入后仍在 push 上产出check / parse与check / check。mise.toml的[tasks.check]description 与实现同步改写;README.md新增「## 检查」两条要点(PR 与merge_group走test,main/tree/**push 走self-check.yml)。阅读入口
中心逻辑在
selftest/workflows/policy.test.ts:collectUses的扫描、pr.yml与self-check.yml的结构断言、probes+runScript的跨仓拒绝执行,以及mise tasks断言。.github/workflows/pr.yml是 27 行接线;mise.toml与README.md是配置与说明。实现选择与偏离
pr.yml引用本地./actions/mise-check还是mouriya-devops/ci/actions/mise-check@maintest;本仓改动 action 的 PR 由自己的test真实执行@main:本仓对actions/mise-check的改动要等合入main后才被执行,PR 上测不到check:pr是否包含 actionlintactionlint && bun test selftestcheck用depends复用同一命令check:pr只跑策略自测:PR 不再检查 YAML 语法与 shellcheck,是既有能力回退bun test selftest,用Bun.YAML/Bun.TOML/Bun.Glob/Bun.spawnSyncjs-yaml或其他测试框架:多一份依赖与安装步骤,selftest不再是单命令未验证与风险
merge_group触发未真实执行:仓库没有启用 merge queue、没有分支保护与 rulesets,merge_group事件不会产生;它只由策略测试固定在pr.yml的触发键里。pull_request路径已在本 PR 上真实运行,b8f5daa 上只有一条顶层test(success)。run:脚本,依赖宿主的jq、openssl、sed、tr、bash(curl用桩);mise.toml只声明actionlint、shellcheck、bun,这些解析器来自 runner 镜像而非 mise,未在 ubuntu-24.04 之外的环境验证。runs-on含${{的 workflow;将来新增一个静态self-hostedjob 的 workflow 不会被要求探测(结果 1 未要求,超出本 issue)。mise run check不会失败。