Github Actions使用小结

348 阅读1分钟
  1. 获取打包的id,用作 docker tag

$GITHUB_RUN_NUMBER

  1. 模糊匹配分支名
branch
  - feature**
  1. 打印相关参数
echo ${{ toJson(github) }}
  1. 条件判断 用于不同分支进行打包
if: contains(github.ref, 'master')
if: ${{ startsWith(github.ref, 'feature') || endsWith(github.event.head_commit.message, 'build') }}
  1. 动态写入环境变量
echo "BUILD_ENV=test" >> $GITHUB_ENV
echo "$( echo ${GITHUB_REF##*/} )" >> $GITHUB_ENV
  1. 仓库包含子模块,需要设置token
 - uses: actions/checkout@v2
   with:
      submodules: true
      token: ${{ secrets.REPO_TOKEN }}
  1. 匹配tag
on:
  push:
tags: 
  - '*'
  1. github参数中有用的信息
github.ref: #当前 分支信息,如果为标签,则为具体标签数字
github.event.head_commit: #当前提交信息
github.event_name: #当前提交事件,如push, pull_request