CICD:github actions 实现CICD

持续集成解决什么问题

  • 提高软件质量
  • 效率迭代
  • 便捷部署
  • 快速交付、便于管理

持续集成(CI)

集成,就是一些孤立的事物或元素通过某种方式集中在一起,产生联系,从而构建一个有机整体的过程。

持续,就是指长期的对项目代码进行集成。

持续集成是指将所有开发者工作副本每天多次合并到主干的做法。

持续集成强调开发人员提交了新代码之后,立刻进行构建、测试。根据测试结果,我们可以确定新代码和原有代码能否正确地集成在一起。

持续部署(CD)

对于一个成熟的CICD管到来说,最后的阶段就是持续部署。作为持续交付——自动将生产就绪型构建版本发不到代码存储库的延伸。

持续集成组成要素

一个最小化的持续集成系统需要包含以下几个要素:

  • 版本管理系统
  • 构建脚本和工具
  • CI服务器

github actions 实现 部署github pages

  1. 在项目中创建.github/workflows目录然后创建.yml文件,配置工作流。

    # Sample workflow for building and deploying a Hugo site to GitHub Pages
    name: Deploy wisdomwindy site pages
    
    on:
      # Runs on pushes targeting the default branch
      push:
        branches: [$default_branch]
    
      # Allows you to run this workflow manually from the Actions tab
      workflow_dispatch:
    
    jobs:
      # Build job
      build:
        runs-on: ubuntu-latest
        steps:
          # 检出代码
          - name: checkout
            uses: actions/checkout@v3
            with:
              fetch-depth: 0
          - name: Git Configuration
            run: |
              git config --global core.quotePath false
              git config --global core.autocrlf false
              git config --global core.safecrlf true
              git config --global core.ignorecase false  
          # 安装 PNPM
          - name: setup PNPM
            uses: pnpm/action-setup@v2
            with:
              version: latest
          # 安装 node
          - name: Setup Node
            uses: actions/setup-node@v3
            with:
              node-version: 18.18.1
              registry-url: https://registry.npmjs.org
              cache: pnpm
          # 安装依赖
          - name: Install dependencies
            run: pnpm i --frozen-lockfile
          # 打包
          - name: Build
            run: pnpm build
          # 部署
          - name: Deploy GitHub Pages
            uses:  JamesIves/github-pages-deploy-action@v4
            with:
              branch: pages
              folder: docs
    
  2. 在github项目仓库中点击actions查看工作流是否工作,如果没有工作点击,右边的按钮选中run workflow,即可运行工作流。

如果出现The deploy step encountered an error: The process '/usr/bin/git' failed with错误,在当前项目仓库的settings页面中点击actions,选中general,在Fork pull request workflows from outside collaborators配置项中选中第一个,在Workflow permissions配置项中选中第一个,且在yml配置文件中不能再次设置权限。

猜你喜欢

转载自blog.csdn.net/qq_40850839/article/details/133821809