简介
You only need a GitHub repository to create and run a GitHub Actions workflow. In this guide, you'll add a workflow that demonstrates some of the essential features of GitHub Actions.
The following example shows you how GitHub Actions jobs can be automatically triggered, where they run, and how they can interact with the code in your repository.
创建第一个工作流程
-
从 GitHub 上的仓库,在
.github/workflows
目录中创建一个名为github-actions-demo.yml
的新文件。 更多信息请参阅“创建新文件”。 -
Copy the following YAML contents into the
github-actions-demo.yml
file:YAML name: GitHub Actions Demo on: [push] jobs: Explore-GitHub-Actions: runs-on: ubuntu-latest steps: - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - name: Check out repository code uses: actions/checkout@v2 - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - run: echo "🖥️ The workflow is now ready to test your code on the runner." - name: List files in the repository run: | ls ${{ github.workspace }} - run: echo "🍏 This job's status is ${{ job.status }}."
-
滚动到页面底部,然后选择 Create a new branch for this commit and start a pull request(为此提交创建一个新分支并开始拉取请求)。 然后,若要创建拉取请求,请单击 Propose new file(提议新文件)。
Committing the workflow file to a branch in your repository triggers the push
event and runs your workflow.
查看工作流程结果
-
在 GitHub 上,导航到仓库的主页面。
-
在仓库名称下,单击 Actions(操作)。
-
在左侧边栏中,单击您想要查看的工作流程。
-
从工作流程运行列表中,单击要查看的运行的名称。
-
Under Jobs , click the Explore-GitHub-Actions job.
-
The log shows you how each of the steps was processed. Expand any of the steps to view its details.
For example, you can see the list of files in your repository:
更多工作流程模板
GitHub 提供预配置的工作流程模板,您可以自定义以创建自己的持续集成工作流程。 GitHub 分析代码并显示可能适用于您的仓库的 CI 模板。 例如,如果仓库包含 Node.js 代码,您就会看到 Node.js 项目的建议。 您可以使用工作流程模板作为基础来构建自定义工作流程,或按原样使用模板。
您可以在 actions/starter-workflows 仓库中浏览工作流程模板的完整列表。
后续步骤
The example workflow you just added runs each time code is pushed to the branch, and shows you how GitHub Actions can work with the contents of your repository. But this is only the beginning of what you can do with GitHub Actions:
- 您的仓库可以包含多个基于不同事件触发不同任务的工作流程。
- You can use a workflow to install software testing apps and have them automatically test your code on GitHub's runners.
GitHub Actions 可以帮助您自动执行应用程序开发过程的几乎每个方面。 准备好开始了吗? 以下是一些帮助您对 GitHub Actions 执行后续操作的有用资源:
- "Learn GitHub Actions" for an in-depth tutorial.
- "Guides" for specific uses cases and examples.