操作指南
如何用 act 在本地运行 CI
用 act 在你的工作站上执行真实的 GitHub 工作流——无密钥、不写入 GitHub。
你想知道一次改动能否通过真实的 CI 工作流,而又不必推送。仓库自带的本地
act 环境正是为此而生。
命令
mise run ci:act # CI workflow: Go (ubuntu leg), quality, lint, security
ACT_INCLUDE_DOCS=1 mise run ci:act # also the docs job
mise run release:act-dry-run # release workflow as a GoReleaser snapshotci:act 运行 scripts/act-ci.sh;release:act-dry-run 运行
scripts/act-release-dry-run.sh。两者都需要 Docker。
ci:act 运行什么,怎么运行
scripts/act-image.sh从.github/act/Dockerfile构建本地 runner 镜像agore-skill/act-runner:local(node:24-bookworm-slim + build-essential、git、curl、归档工具—— 约 570 MB,本机架构,永不推送)。- CI 工作流以
workflow_dispatch方式运行,事件载荷为.github/act/ci.json:Go 作业缩减为 ubuntu 矩阵分支,然后是 quality 作业(mise run ci)、lint 作业和 security 作业。macOS 和 Windows 分支仍只在 GitHub 上运行。 - docs 作业默认跳过,除非设置了
ACT_INCLUDE_DOCS=1;设置后, 文档构建也会在 act 中运行。
act 读取 .actrc:ubuntu-latest runner 映射到本地镜像,镜像从不
拉取(--pull=false),容器/卷即使失败也会移除(--rm)。
release:act-dry-run 运行什么
发布工作流以 workflow_dispatch 方式运行,载荷为
.github/act/release-dry-run.json(dry_run: true):GoReleaser 只构建
快照工件——没有 GitHub Release,没有 publish,没有 cosign 签名,因此也
没有 OIDC token。工件位于容器内的检出副本中,并在作业日志中列出。
已知的 act 限制(以及脚本为何绕过它们)
- act 的复制模式会省略
.git。Go 作业设置GOFLAGS=-buildvcs=false(检出快照没有提交);只有 lint 作业使用--bind,因为goreleaser check需要一个仓库。GitHub Actions 检出真实历史并保持 默认行为。 - act 的工件服务器没有实现
upload-artifact@v7协议。覆盖率上传步骤用if: ${{ !env.ACT }}守护;GitHub CI 仍然会上传 profile。 - 本地运行使用 linux/arm64(本机)而非 GitHub 的 linux/amd64。
涉及的文件
| 文件 | 角色 |
|---|---|
.actrc | Runner 镜像映射与 act 默认值 |
.github/act/Dockerfile | 本地 runner 镜像 |
.github/act/ci.json | CI 的 workflow_dispatch 载荷 |
.github/act/release-dry-run.json | 含 dry_run: true 的载荷 |
scripts/act-image.sh | 构建镜像 |
scripts/act-ci.sh | 在本地运行 CI 作业 |
scripts/act-release-dry-run.sh | 以快照方式运行发布工作流 |
相关内容
- 每个工作流、作业和触发器的细节:CI 工作流参考
- 本地 CI 方案为何存在: 用 act 做本地 CI