github 原生 ci/cd,初尝 github actions
intro
github 目前已经推出了自己的 cicd 服务 —— github actions,而且比微软的 azure devops pipelines 对开发者来说更友好,使用起来更好用。
github actions 核心概念
总体看下来感觉是从 azure pipelines 迁移过来的东西,有许多概念和 azure pipelines 是类似的,如果你之前用过 azure pipelines,应该很容易上手
- runner 用来跑 cicd build 的服务器
- github hosted runner github 官方提供的 runner
- self-hosted runner 用自己的服务器作为 runner
- workflow 定义 ci/cd 的流程,需要执行哪些操作,需要做什么
- workflow 定义 workflow 的配置文件,通常放在项目根目录下的
.github/workflows
文件夹下 - workflow run 每一次 ci/cd build
- event 触发 ci/cd build 的事件,如 push/issue/pr
- job 由一系列 step 组成,job 可以并行执行也可以串行执行,每一个 job 都是一个新的环境
- step 对应 job 执行的每一个步骤
- action 对应 step 里执行的可复用的操作
github actions 配置示例
来看一个 github actions 的 dotnet 配置:
name: dotnetcore # workflow name on: [push] # event trigger,什么事件触发 build jobs: build: runs-on: ubuntu-latest # 指定 runner,使用 github 提供的 runner steps: - uses: actions/checkout@v1 # checkout - name: setup .net core # 设置 dotnet core 环境 uses: actions/setup-dotnet@v1 with: dotnet-version: 3.0.100 - name: dotnet info # 输出 dotnet -info,查看 dotnet 版本信息 run: dotnet --info - name: build run: bash build.sh # 在 bash 中运行 build 脚本
github 示例: https://github.com/weihanli/weihanli.common/blob/dev/.github/workflows/dotnetcore.yml
more
徽章:
sample:
[![github build status]()](https://github.com/weihanli/weihanli.common/actions?query=workflow%3adotnetcore+branch%3adev)
https://github.com/<owner>/<repository>/workflows/<workflow_name>/badge.svg https://github.com/<owner>/<repository>/workflows/<workflow_name>/badge.svg?branch=<branch-name>
summary
总体来说,用起来还可以,但是感觉还是不如 travis-ci 以及 azure pipelines成熟,比如说常用 ci 都支持的 commit message 里包含 [skip ci] 的不触发 build,目前 github action 还是不支持的,不过毕竟是新推出来的产品,相信以后一定会越来越好哒,想尝试的小伙伴们可以实践一下
reference
- https://mp.weixin.qq.com/s/fb9alhm2z-czg6x92nfdmg
- https://github.com/weihanli/weihanli.common