# GitHub Actions

**GitHub Actions** 是内置于 GitHub 的持续集成与持续交付（CI/CD）及工作流自动化平台，软件构建、测试和部署在其中以 YAML 工作流文件的形式定义，并在托管或自托管的虚拟机上执行。规模相当庞大：2025 年开发者在公共和开源项目上使用了 115 亿分钟 Actions 时长，同比增长 35%；自 2025 年 8 月起，所有作业都运行在重新架构的后端上，该后端每天处理 7100 万个作业。<sup>[1](https://github.blog/news-insights/product-news/lets-talk-about-github-actions/)</sup> 截至 2024 年 4 月，该生态系统包含超过 18,000 个市场操作和超过 260 万个公共工作流。<sup>[2](https://owasp.org/www-chapter-minneapolis-st-paul/download/20240417_OWASP-MSP_Github_Actions_Security_Landscape.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 执行模型 | 工作流是存放在 `.github/workflows/` 目录中的 YAML 文件；每次运行包含若干作业，作业包含若干步骤，运行器通过 `runs-on` 指定为 GitHub 托管或自托管。<sup>[3](https://www.securitee.org/files/timeforactions_secdev2025.pdf)</sup> |
| 每分钟费率 | 0.002 美元（1 核 Linux x64）、0.006 美元（2 核 Linux x64）、0.005 美元（2 核 Linux arm64）、0.010 美元（2 核 Windows）、0.062 美元（3 核或 4 核 macOS）；分钟数向上取整到最接近的整分钟。<sup>[4](https://docs.github.com/en/billing/reference/actions-runner-pricing)</sup> |
| 硬性限制 | 托管运行器上的作业在 6 小时后终止，运行在 35 天后终止；矩阵每次运行最多 256 个作业；企业版并发为 500 个标准作业（50 个 macOS）或大型运行器上的 1,000 个。<sup>[5](https://docs.github.com/en/actions/reference/limits)</sup> |
| 默认权限 | 2022 年的一项研究报告称，GitHub Actions 工作流默认对整个仓库具有写权限，而 GitLab CI 流水线默认没有写权限。<sup>[6](https://kapravelos.com/publications/githubactions-usenixsec22.pdf)</sup> |
| 供应链暴露面 | 在研究的 8,107 个 JavaScript 操作中，超过 54% 至少包含一个安全弱点；tj-actions/changed-files 被入侵事件（2025 年 3 月）在超过 23,000 个依赖仓库中泄露了运行器内存。<sup>[7](https://dl.acm.org/doi/abs/10.1145/3643991.3644899)</sup><sup> • </sup><sup>[8](https://unit42.paloaltonetworks.com/github-actions-supply-chain-attack/)</sup> |
| 典型成本 | 对于普通付费层仓库，CI/CD 平均每年花费 504 美元；测试和构建消耗了已用资源的 91.2%。<sup>[9](https://dl.acm.org/doi/10.1145/3597503.3623303)</sup> |
| 复用限制 | 可复用工作流现在支持 10 层嵌套，每次运行最多 50 次工作流调用。<sup>[1](https://github.blog/news-insights/product-news/lets-talk-about-github-actions/)</sup> |

## 工作原理

工作流是存储在仓库 `.github/workflows/` 目录中的 YAML 文件。每次运行由一个或多个作业组成；每个作业包含若干步骤，即运行脚本或 shell 命令等单条指令；步骤可以调用操作，即跨工作流复用的打包自动化单元。`runs-on` 关键字用于选择运行器，可以是 GitHub 托管或自托管。<sup>[3](https://www.securitee.org/files/timeforactions_secdev2025.pdf)</sup> 推送、拉取请求和定时等触发器启动运行，矩阵声明将一个作业定义扩展为多个并行变体，每次工作流运行最多 256 个作业。<sup>[5](https://docs.github.com/en/actions/reference/limits)</sup>

**复用。** [自动化](https://www.edgepedia.org/zh/automation)在三个层面上共享：来自市场的单个操作、捆绑多个步骤的复合操作，以及一个仓库可以从另一个仓库调用的可复用工作流。可复用工作流支持 10 层嵌套，每次运行最多 50 次工作流调用。<sup>[1](https://github.blog/news-insights/product-news/lets-talk-about-github-actions/)</sup>

## 定价与限制

GitHub 托管运行器按操作系统和架构按分钟计费：1 核 Linux x64 运行器为 0.002 美元，2 核 Linux x64 为 0.006 美元，2 核 Linux arm64 为 0.005 美元，2 核 Windows（x64 或 arm64）为 0.010 美元，3 核或 4 核 macOS（M1 或 Intel）为 0.062 美元。GitHub 将每个作业使用的分钟数和不足一分钟的部分向上取整到最接近的整分钟。<sup>[4](https://docs.github.com/en/billing/reference/actions-runner-pricing)</sup> 由于 Windows 和 macOS 按 Linux 费率的倍数计费，跨平台矩阵的成本上升速度往往比团队预期的更快。<sup>[10](https://devpages.io/blog/devops-tools-comparison)</sup>

**大型运行器**是独立产品：仅在执行工作流时计费，空闲时不产生费用，仅对团队版或企业版云计划的组织与企业开放，对公共仓库不免费，且不能使用计划内包含的分钟数。<sup>[4](https://docs.github.com/en/billing/reference/actions-runner-pricing)</sup>

该平台强制执行若干上限。GitHub 托管运行器上的作业在执行 6 小时后终止，工作流运行在 35 天后取消（包括等待和审批时间）。标准托管并发在免费版为 20 个并发作业（5 个 macOS），专业版为 40 个，团队版为 60 个，企业版为 500 个（50 个 macOS）；大型运行器允许最多 1,000 个并发作业，团队版和企业版最多 100 个 GPU 作业。依赖缓存限制为每个仓库每分钟 200 次上传、1,500 次下载和 400 次删除，每个仓库每 10 秒限制 1,500 个工作流触发事件和 500 个排队运行。<sup>[5](https://docs.github.com/en/actions/reference/limits)</sup> 自托管作业最多可运行 5 天，排队最多 24 小时后自动取消。<sup>[5](https://docs.github.com/en/actions/reference/limits)</sup>

## 数据一览

使用量集中在少数几个维护良好的操作上。使用最广泛的是 actions/checkout，出现在近 1,300 万个仓库中（12,931,705 个），其次是 actions/setup-node，有 260 万个依赖仓库。只有八个操作被超过一百万个仓库采用；这八个操作合计被 23,691,050 个仓库使用，而 20,477 个操作共享总共 175,865 个仓库。<sup>[3](https://www.securitee.org/files/timeforactions_secdev2025.pdf)</sup> Linux 基金会的 GitHub Actions Insights 集合另行跟踪了 79 个社区开发的自动化项目，共有 3,152 名贡献者。<sup>[11](https://insights.linuxfoundation.org/collection/github-actions)</sup>

成本和资源使用遵循可预测的驱动因素。测试和构建消耗了已用资源的 91.2%，由拉取请求（50.7%）、推送（30.9%）和定时工作流（15.5%）触发。尽管实测效果积极，但只有 32.9% 的付费层仓库采用了缓存；在非活跃仓库上停用定时工作流，可使受影响工作流的执行时间减少 1.1% 至 31.6%。<sup>[9](https://dl.acm.org/doi/10.1145/3597503.3623303)</sup>

## 安全与供应链

该平台的默认权限模型比同类平台更宽泛。2022 年的一项研究报告称，GitHub CI 工作流默认对整个仓库具有写权限，因此存在漏洞或恶意的工作流代码可以直接影响仓库；该研究发现 GitLab CI 流水线默认没有对仓库代码的写访问权限，且 GitHub 的插件系统授予的权限高于同类 CI/CD 平台。<sup>[6](https://kapravelos.com/publications/githubactions-usenixsec22.pdf)</sup> 使用 GHAST 工具对 50 个开源项目进行自动化分析，识别出 24,905 个安全问题，均已报告给相关方；作者指出，利用存在漏洞的工作流进行攻击可能对大型软件生态系统造成破坏性影响，因为工作流直接在托管仓库上自动化代码管理。<sup>[12](https://arxiv.org/abs/2208.03837)</sup>

**第三方操作**是主要的供应链攻击面。在 8,107 个 JavaScript 操作的数据集中，大多数依赖数十个 npm 包，绝大多数依赖存在已知漏洞的 npm 版本，间接依赖往往带有更严重的漏洞；[CodeQL](https://www.edgepedia.org/zh/codeql) 分析发现，超过 54% 的被研究操作至少包含一个安全弱点。<sup>[7](https://dl.acm.org/doi/abs/10.1145/3643991.3644899)</sup> 这一风险在 2025 年 3 月成为现实：被超过 23,000 个仓库使用的 tj-actions/changed-files 操作通过 reviewdog/action-setup（经由 tj-actions/eslint-changed-files 触达）被入侵；攻击者注入了一个转储运行器内存的载荷，将环境变量和密钥暴露在工作流日志中。截至 2025 年 3 月 20 日，维护者已缓解了该威胁。<sup>[8](https://unit42.paloaltonetworks.com/github-actions-supply-chain-attack/)</sup>

**加固指南**在各来源之间趋于一致。OWASP 建议在工作流级别设置 `permissions: {}`，默认禁用所有权限，仅在作业级别授予所需的特定权限；切勿在公共仓库中使用自托管运行器，因为任何能够复刻并打开拉取请求的人都可能在运行器上执行代码；在发布和分发工作流中禁用缓存以防止缓存投毒；使用带有必需审批规则的 GitHub 环境，使授权账户必须手动批准生产部署。<sup>[13](https://cheatsheetseries.owasp.org/cheatsheets/GitHub_Actions_Security_Cheat_Sheet.html)</sup> 对于云凭证，OIDC 用短期令牌取代长期密钥，云提供商直接验证这些令牌；GitHub 建议将 OIDC 令牌声明（仓库、环境、工作流）映射到范围狭窄的云 IAM 角色。<sup>[14](https://learn.github.com/product-guides/github-actions/succeed-long-term/implement-advanced-security-controls)</sup> Unit 42 的事件分析建议将操作固定到完整长度的提交 SHA-1 哈希，而非可变标签或分支；采用最小权限的流水线访问控制；用 OIDC 短期令牌取代长期密钥。<sup>[8](https://unit42.paloaltonetworks.com/github-actions-supply-chain-attack/)</sup>

## 与 GitLab CI、Jenkins 和 CircleCI 的比较

这些平台最大的差异在于权限默认值和配置模型。2022 年的一项研究报告称，GitHub Actions 工作流默认对整个仓库具有写访问权限，而 GitLab CI 流水线默认没有对仓库代码的写访问权限。<sup>[6](https://kapravelos.com/publications/githubactions-usenixsec22.pdf)</sup> 在配置方面，Actions 使用 `.github/workflows/` 中的 YAML，配有托管和自托管运行器，并通过操作、复合操作和可复用工作流实现复用；Jenkins 使用 Groovy Jenkinsfile，CircleCI 使用 orbs。一个被指出的调试缺口是，Actions 没有原生方式通过 shell 进入失败的运行器，因此迭代只能通过推送提交并等待来完成。<sup>[10](https://devpages.io/blog/devops-tools-comparison)</sup>

在性能方面，已发表的主要比较由厂商赞助，阅读时应予以考虑。在 CircleCI 的基准测试中，CircleCI 执行流水线的中位速度快于 GitHub Actions 默认 ubuntu-latest 运行器 40.29%，报告的排队时间比 Actions 默认运行器少 90.13%，比大型运行器少 99.12%，并观察到 Actions 尽管名义容量为 500 个作业，实际从未超过约 124 个并发作业，默认运行器的中位排队时间超过 153 秒，大型运行器超过 22 分钟。<sup>[15](https://circleci.com/blog/ci-cd-at-scale-circleci-vs-github-actions/)</sup> 成本效益同样存在争议：普通付费层仓库每年花费约 504 美元。<sup>[9](https://dl.acm.org/doi/10.1145/3597503.3623303)</sup>

## 近期发展

Arm64 Linux 和 Windows GitHub 托管运行器于 2024 年 9 月在团队版和企业版云计划上全面可用。客户 Arcjet 报告称，从自管理的 [AWS Graviton](https://www.edgepedia.org/zh/aws-graviton) 切换到 GitHub arm64 运行器后，月度费用节省超过 75%，构建时间从 x86 上的 30 多分钟缩短到 ARM 上的约 4 分钟。<sup>[16](https://github.blog/changelog/2024-09-03-github-actions-arm64-linux-and-windows-runners-are-now-generally-available/)</sup>

2025 年，GitHub 重新架构了 Actions 后端；自 8 月起所有作业都在其上运行，每天可处理 7,100 万个作业（超过此前水平的 3 倍），单个企业每分钟可启动的作业数达到此前的 7 倍。仓库现在可以超过此前 10 GB 的 Actions 缓存限制；当年的交付内容包括面向公共仓库的 arm64 托管运行器、macOS 15 和 Windows 2025 镜像、Actions 性能指标以及自定义镜像支持。<sup>[1](https://github.blog/news-insights/product-news/lets-talk-about-github-actions/)</sup> 可复用工作流限制提升至 10 层嵌套和每次运行 50 次调用。<sup>[1](https://github.blog/news-insights/product-news/lets-talk-about-github-actions/)</sup>

## 采用与实践

从业者的行为表明，他们严重依赖少数维护良好的操作，而非可复用工作流：拥有超过一百万采用者的八个操作贡献了超过 2,360 万次仓库使用，而 20,477 个操作的长尾仅共享 175,865 个仓库。<sup>[3](https://www.securitee.org/files/timeforactions_secdev2025.pdf)</sup> 成本由拉取请求、推送和定时工作流驱动，尽管有实测收益，缓存的采用率仍偏低，仅为 32.9%。<sup>[9](https://dl.acm.org/doi/10.1145/3597503.3623303)</sup> 两种运维实践直接源于定价模型：使用带有 `cancel-in-progress` 的并发块可防止被取代的运行浪费分钟数；跨平台矩阵会成倍增加成本，因为 Windows 和 macOS 运行器按 Linux 费率的倍数计费。<sup>[10](https://devpages.io/blog/devops-tools-comparison)</sup>

## References

1. [Let's talk about GitHub Actions, The GitHub Blog](https://github.blog/news-insights/product-news/lets-talk-about-github-actions/)
2. [GitHub Actions Security Landscape, OWASP Minneapolis–St. Paul (April 2024)](https://owasp.org/www-chapter-minneapolis-st-paul/download/20240417_OWASP-MSP_Github_Actions_Security_Landscape.pdf)
3. [Time for Actions: A Longitudinal Study of the GitHub Actions Ecosystem, IEEE SECDEV 2025](https://www.securitee.org/files/timeforactions_secdev2025.pdf)
4. [Actions runner pricing, GitHub Docs](https://docs.github.com/en/billing/reference/actions-runner-pricing)
5. [Usage limits for GitHub Actions, GitHub Docs](https://docs.github.com/en/actions/reference/limits)
6. [Characterizing the Security of GitHub CI Workflows, USENIX Security 2022](https://kapravelos.com/publications/githubactions-usenixsec22.pdf)
7. [Quantifying Security Issues in Reusable JavaScript Actions in GitHub Workflows, MSR 2024](https://dl.acm.org/doi/abs/10.1145/3643991.3644899)
8. [GitHub Actions Supply Chain Attack: tj-actions/changed-files Incident, Unit 42, Palo Alto Networks](https://unit42.paloaltonetworks.com/github-actions-supply-chain-attack/)
9. [Resource Usage and Optimization Opportunities in Workflows of GitHub Actions, ICSE 2024](https://dl.acm.org/doi/10.1145/3597503.3623303)
10. [DevOps Tools Comparison: CI/CD Platforms for 2025, devpages.io](https://devpages.io/blog/devops-tools-comparison)
11. [GitHub Actions Insights, Linux Foundation](https://insights.linuxfoundation.org/collection/github-actions)
12. [Automatic Security Assessment of GitHub Actions Workflows (GHAST), arXiv](https://arxiv.org/abs/2208.03837)
13. [GitHub Actions Security Cheat Sheet, OWASP](https://cheatsheetseries.owasp.org/cheatsheets/GitHub_Actions_Security_Cheat_Sheet.html)
14. [Implement advanced security controls, GitHub Learn](https://learn.github.com/product-guides/github-actions/succeed-long-term/implement-advanced-security-controls)
15. [CI/CD at scale: A performance analysis of CircleCI vs GitHub Actions, CircleCI](https://circleci.com/blog/ci-cd-at-scale-circleci-vs-github-actions/)
16. [GitHub Actions: arm64 Linux and Windows runners are now generally available, The GitHub Blog](https://github.blog/changelog/2024-09-03-github-actions-arm64-linux-and-windows-runners-are-now-generally-available/)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Named software products and platforms › Cloud, virtualization, and containers › CI/CD and deployment tools

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/github-actions

English original: https://www.edgepedia.org/github-actions
