GitHub Actions:为何逐渐成为默认的 CI/CD 工具
我们公司正从 Jenkins 迁移到 GitHub Actions 来执行 CI/CD。本文介绍一些基础知识。 什么是 GitHub Actions? 根据 GitHub 的定义: GitHub Actions 是一个持续集成和持续交付(CI/CD)平台,可以自动化构建、测试和部署流程。你可以创建工作流,在向仓库推送更改时运行测试,或在合并拉取请求后将代码部署到生产环境。 如果你使用过 Jenkins 等 CI/CD 工具,可以把 GitHub Actions 看成自动化同类工作流的另一种方式。 GitHub Actions 还可以用于: 构建和测试 部署 发布软件包 管理 GitHub Issues 和标签 一个简单示例 1. 创建 GitHub Actions 工作流 YAML 文件 在 GitHub 仓库的 .github/workflows 目录下,创建一个名为 github-actions-hello-world.yml 的工作流文件。 2. 添加 Hello World 工作流 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 name: GitHub Actions Hello World run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 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@v4 - 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 }}." 提交工作流文件 将工作流文件提交到你的分支。 ...