{"meta":{"title":"GitHub Actions快速入门","intro":"几分钟内即可试用 GitHub Actions 的核心功能。","product":"GitHub Actions","breadcrumbs":[{"href":"/zh/enterprise-cloud@latest/actions","title":"GitHub Actions"},{"href":"/zh/enterprise-cloud@latest/actions/get-started","title":"开始"},{"href":"/zh/enterprise-cloud@latest/actions/get-started/quickstart","title":"快速入门"}],"documentType":"article"},"body":"# GitHub Actions快速入门\n\n几分钟内即可试用 GitHub Actions 的核心功能。\n\n## 简介\n\nGitHub Actions 是一种持续集成和持续交付 (CI/CD) 平台，可用于自动执行生成、测试和部署管道。 可以创建在将更改推送到存储库或将合并拉取请求部署到生产环境时运行测试的工作流。\n\n本快速入门指南介绍如何使用 GitHub 的用户界面添加一个工作流，该工作流用于演示 GitHub Actions 的一些核心功能。\n\n若要开始使用预配置的工作流，请浏览 [actions/starter-workflows](https://github.com/actions/starter-workflows) 存储库中的模板列表。 有关详细信息，请参阅“[使用工作流模板](/zh/enterprise-cloud@latest/actions/how-tos/write-workflows/use-workflow-templates)”。\n\n有关 GitHub Actions 工作流的概述，请参阅 [工作流](/zh/enterprise-cloud@latest/actions/concepts/workflows-and-actions/workflows)。 若要了解构成 GitHub Actions的各种组件，请参阅 [了解GitHub Actions](/zh/enterprise-cloud@latest/actions/get-started/understand-github-actions)。\n\n## 使用工作流模板\n\nGitHub 提供预配置的工作流模板，可以按原样使用或自定义它来创建自己的工作流。 GitHub 分析代码并显示可能对仓库有用的工作流模板。 例如，如果仓库包含 Node.js 代码，您就会看到 Node.js 项目的建议。\n\n这些工作流模板旨在帮助你快速启动和运行，提供了一系列配置，例如：\n\n* CI：[持续集成工作流](https://github.com/actions/starter-workflows/tree/main/ci)\n* 部署：[部署工作流](https://github.com/actions/starter-workflows/tree/main/deployments)\n* 自动化：[自动化工作流](https://github.com/actions/starter-workflows/tree/main/automation)\n* 代码扫描：[代码扫描工作流](https://github.com/actions/starter-workflows/tree/main/code-scanning)\n* 页面：[页面工作流](https://github.com/actions/starter-workflows/tree/main/pages)\n\n使用这些工作流作为构建自定义工作流的起点或按原样使用它们。 可以在 [actions/starter-workflows](https://github.com/actions/starter-workflows) 存储库中浏览工作流模板的完整列表。\n\n## 先决条件\n\n本指南假定：\n\n* 你至少对如何使用 GitHub有一个基本知识。 如果没有，你将发现先阅读存储库和拉取请求文档中的一些文章会非常有帮助。 有关示例，请参阅“[仓库快速入门](/zh/enterprise-cloud@latest/repositories/creating-and-managing-repositories/quickstart-for-repositories)”、“[分支](/zh/enterprise-cloud@latest/pull-requests/reference/branches)”和“[拉取请求](/zh/enterprise-cloud@latest/pull-requests/reference/pull-requests)”。\n* 你有一个存储库 GitHub ，可在其中添加文件。\n* 您有权访问 GitHub Actions。\n\n  > \\[!NOTE] 如果在  上您的仓库名称下未显示  Actions 选项卡，则可能是因为该仓库已禁用 Actions。 有关详细信息，请参阅“[管理存储库的GitHub Actions设置](/zh/enterprise-cloud@latest/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository)”。\n\n## 创建第一个工作流程\n\n1. 在位于 GitHub 的仓库中，在 `.github/workflows` 目录下创建一个名为 `github-actions-demo.yml` 的工作流文件。 要执行此操作：\n   * `.github/workflows`如果目录已存在，请导航到该目录GitHub，单击“**添加文件**”，然后单击“**创建新文件**”，并命名该文件`github-actions-demo.yml`。\n\n   * 如果存储库没有 `.github/workflows` 目录，请转到存储库 GitHub的主页，单击“ **添加文件**”，然后单击“ **创建新文件**”，并命名该文件 `.github/workflows/github-actions-demo.yml`。 这会在单个步骤中创建 `.github` 和 `workflows` 目录以及 `github-actions-demo.yml` 文件。\n   > \\[!NOTE]\n   > 若要让  在你的仓库中发现任何  工作流，你必须将工作流文件保存在名为  的目录中。\n   >\n   > 你可以为工作流文件指定所需的任何名称，但必须使用 `.yml` 或 `.yaml` 作为文件扩展名。 YAML 通常是用于配置文件的标记语言。\n\n2. 将以下 YAML 内容复制到 `github-actions-demo.yml` 文件中：\n\n   ```yaml copy\n   name: GitHub Actions Demo\n   run-name: ${{ github.actor }} is testing out GitHub Actions 🚀\n   on: [push]\n   jobs:\n     Explore-GitHub-Actions:\n       runs-on: ubuntu-latest\n       steps:\n         - run: echo \"🎉 The job was automatically triggered by a ${{ github.event_name }} event.\"\n         - run: echo \"🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!\"\n         - run: echo \"🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}.\"\n         - name: Check out repository code\n           uses: actions/checkout@v6\n         - run: echo \"💡 The ${{ github.repository }} repository has been cloned to the runner.\"\n         - run: echo \"🖥️ The workflow is now ready to test your code on the runner.\"\n         - name: List files in the repository\n           run: |\n             ls ${{ github.workspace }}\n         - run: echo \"🍏 This job's status is ${{ job.status }}.\"\n   ```\n\n   在此阶段，你无需了解此工作流的详细信息。 现在，你只需将内容复制并粘贴到文件中。 完成本快速入门指南后，你可以在 [工作流](/zh/enterprise-cloud@latest/actions/concepts/workflows-and-actions/workflows) 中了解工作流文件的语法；有关 GitHub Actions 上下文（例如 `${{ github.actor }}` 和 `${{ github.event_name }}`）的说明，请参阅 [上下文参考](/zh/enterprise-cloud@latest/actions/reference/workflows-and-actions/contexts)。\n\n3. 单击“提交更改”。\n\n4. 在“建议更改”对话框中，选择提交到默认分支的选项或创建新分支并启动拉取请求的选项。 然后单击“提交更改”\\*\\*\\*\\* 或“建议更改”\\*\\*\\*\\*。\n\n   ![“建议更改”对话框的屏幕截图，其中提到的区域用橙色轮廓突出显示。](/assets/images/help/repository/actions-quickstart-commit-new-file.png)\n\n向存储库的分支提交工作流文件会触发 `push` 事件并运行工作流。\n\n如果选择启动拉取请求，则可以继续并创建拉取请求，但对于本快速入门来说，这不是必要的，因为提交仍然是对分支进行的，并会触发新工作流。\n\n## 查看工作流程结果\n\n1. 在 GitHub 上，导航到存储库的主页面。\n\n2. 在仓库名称下，单击“<svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-play\" aria-label=\"play\" role=\"img\"><path d=\"M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM1.5 8a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0Zm4.879-2.773 4.264 2.559a.25.25 0 0 1 0 .428l-4.264 2.559A.25.25 0 0 1 6 10.559V5.442a.25.25 0 0 1 .379-.215Z\"></path></svg> Actions”\\*\\*\\*\\*。\n\n   ![“github/docs”存储库的选项卡的屏幕截图。 “操作”选项卡以橙色边框突出显示。](/assets/images/help/repository/actions-tab-global-nav-update.png)\n\n3. 在左侧栏中，单击要显示的工作流，在本示例中为“GitHub Actions演示”。\n\n   ![“Actions”页面的屏幕截图。 示例工作流名称“GitHub Actions 演示”被深橙色轮廓突出显示。](/assets/images/help/repository/actions-quickstart-workflow-sidebar.png)\n\n4. 在工作流运行列表中，单击要查看的运行名称，在本示例中，“USERNAME 正在测试GitHub Actions”。\n\n5. 在工作流运行页的左侧栏中，在 **Jobs** 下，单击 **Explore-GitHub-Actions** 作业。\n\n   ![“工作流运行”页的屏幕截图。 在左侧边栏中，“Explore-GitHub-Actions”作业以深橙色边框突出显示。](/assets/images/help/repository/actions-quickstart-job.png)\n\n6. 日志显示每个步骤的处理方式。 展开任何步骤之一以查看其详细信息。\n\n   ![工作流运行步骤的屏幕截图。](/assets/images/help/repository/actions-quickstart-logs.png)\n\n   例如，你可以看到存储库中的文件列表：\n\n   ![展开以显示日志输出的“列出存储库中的文件”步骤的屏幕截图。 步骤的输出以橙色轮廓突出显示。](/assets/images/help/repository/actions-quickstart-log-detail.png)\n\n每次将代码推送到分支时，都会触发刚刚添加的示例工作流，并演示如何 GitHub Actions 处理存储库的内容。 有关深入教程，请参阅“[了解GitHub Actions](/zh/enterprise-cloud@latest/actions/get-started/understand-github-actions)”。\n\n## 后续步骤\n\nGitHub Actions 可帮助你自动执行应用程序开发过程的几乎所有方面。 准备好开始了吗？ 以下是一些有助于你借助 GitHub Actions 继续下一步的资源：\n\n* 若要创建 GitHub Actions 工作流，请参阅 [使用工作流模板](/zh/enterprise-cloud@latest/actions/how-tos/write-workflows/use-workflow-templates)。\n* 有关持续集成 (CI) 工作流，请参阅 [构建和测试代码](/zh/enterprise-cloud@latest/actions/tutorials/build-and-test-code)。\n* 有关构建和发布包的信息，请参阅 [发布包](/zh/enterprise-cloud@latest/actions/tutorials/publish-packages)。\n* 有关部署项目，请参阅 [部署到第三方平台](/zh/enterprise-cloud@latest/actions/how-tos/deploy/deploy-to-third-party-platforms)。\n* 有关在 GitHub 上自动执行任务和流程的信息，请参阅 [使用 GitHub Actions 管理你的工作](/zh/enterprise-cloud@latest/actions/tutorials/manage-your-work)。\n* 有关演示 GitHub Actions 更复杂功能的示例，请参阅 [选择工作流执行的操作](/zh/enterprise-cloud@latest/actions/how-tos/write-workflows/choose-what-workflows-do)。 这些详细示例说明如何在运行程序上测试代码、访问 GitHub CLI 并使用高级功能（如并发和测试矩阵）。\n* 要证明你在使用 GitHub Actions 自动化工作流和加速开发方面的熟练程度，请通过 GitHub Actions 获取 GitHub Certifications 证书。 有关详细信息，请参阅 [关于 GitHub Certifications](/zh/enterprise-cloud@latest/get-started/showcase-your-expertise-with-github-certifications/about-github-certifications)。"}