注意:GitHub Enterprise Server 目前不支持 GitHub 托管的运行器。 可以在 GitHub public roadmap 上查看有关未来支持计划的更多信息。
Example overview
本文使用示例工作流演示 GitHub Actions 的某些主要 CI 功能。 When this workflow is triggered, it automatically runs a script that checks whether the GitHub Docs site has any broken links. If any broken links are found, the workflow uses the GitHub CLI to create a GitHub issue with the details.
下图显示了工作流步骤的高级视图以及它们如何在作业中运行:
Features used in this example
示例工作流演示了 GitHub Actions 的以下功能:
Feature | Implementation |
---|---|
定期运行工作流: | schedule |
设置令牌的权限: | permissions |
除非满足特定条件,否则阻止作业运行: | if |
引用工作流中的机密: | 秘密 |
将存储库克隆到运行器: | actions/checkout |
在运行器上安装 node : | actions/setup-node |
Using a third-party action: | peter-evans/create-issue-from-file |
Running shell commands on the runner: | run |
Running a script on the runner: | Using script/check-english-links.js |
Generating an output file: | Piping the output using the > operator |
Checking for existing issues using GitHub CLI: | gh issue list |
Commenting on an issue using GitHub CLI: | gh issue comment |
Example workflow
GitHub Docs 工程团队创建了以下工作流。 若要查看 github/docs
存储库中此文件的最新版本,请参阅 check-all-english-links.yml
.
注意:此工作流的每一行将在下一部分“了解示例”中介绍。
|
Understanding the example
下表介绍了在创建 GitHub Actions 工作流时如何使用这些功能。
Code | Explanation |
---|---|
|
将显示在 GitHub 存储库的“操作”选项卡中的工作流名称。 |
|
Defines the
|
|
Modifies the default permissions granted to |
|
Groups together all the jobs that run in the workflow file. |
|
Defines a job with the ID |
|
Only run the |
|
Configures the job to run on an Ubuntu Linux runner. This means that the job will execute on a fresh virtual machine hosted by GitHub. For syntax examples using other runners, see "Workflow syntax for GitHub Actions." |
|
Creates custom environment variables, and redefines the built-in |
|
Groups together all the steps that will run as part of the |
|
The |
|
This step uses the |
|
The |
|
This |
|
If the |
|
Uses the |
|
Uses
|
|
If an issue from a previous run is open and assigned to someone, then use |
|
If an issue from a previous run is open and is not assigned to anyone, then:
|
Next steps
- 若要了解 GitHub Actions 概念,请参阅“了解 GitHub Actions”。
- 有关创建基本工作流的分步指南,请参阅“GitHub Actions 快速入门”。
- 如果� 熟悉 GitHub Actions 的基础知识,可以在“关于工作流”中了解工作流及其功能。