Skip to content

GitHub Action 参考

on

push

yml
on:
  push:
    branches:
      - 'prod'
    paths:
      - 'src/**'
      - 'pom.xml'

workflow_dispatch

yml
on: 
  workflow_dispatch:
    inputs:
      domain:
        description: 'domain'
        required: true
        default:
      platform:
        description: 'platform'
        required: true
        default:

变量

默认环境变量

参考文档

shell
# step1
$GITHUB_WORKFLOW
${{ github.workflow }}
# step uses
${{ github.workflow }}

secret 变量

shell
${{ secret.PASSWORD }}

env 定义变量

shell
env:
    ABC: aaabbbccc

# step1
$ABC 可用
${{ env.ABC }} 可用

# step uses
$ABC 不可用
${{ env.ABC }} 可用

step 里定义变量

shell
# step1
ABC=aabbcc

# step1
$ABC 可用
${{ env.ABC}} 不可用

# step2
均无法获取 ABC

step 里追加变量到 $GITHUB_ENV

shell
# step1
echo "DDD=dddaaa" >> $GITHUB_ENV

# step1
均无法获取 DDD

# step2
$DDD 可用
${{ env.DDD }} 可用

Push 本仓库 GITHUB_TOKEN

yml
- name: Push
    uses: ad-m/github-push-action@master
    with:
    github_token: ${{ secrets.GITHUB_TOKEN }}

if

shell
if [ ${{ github.event.inputs.platform }} == "abc" ]; then
    echo "xxx"
fi

if [ ${{ env.INPUT }} == "abc" ]; then
    echo "xxx"
fi

git

shell
git clone https://user:${{ secrets.SOMETOKEN }}@github.com/xxxx/xxxx
cd xxxx
git config user.name "stille"
git config user.email "stille@ioiox.com"
git checkout xxxx
do something
git add xxx/xxx
git commit -m "Update"
git push

循环

shell
        cat repo.list | awk '{if (NR%2==1) print $0}' >> name.list
        cat repo.list | awk '{if (NR%2==0) print $0}' >> token.list
        sum=1
        cat ./name.list | while read repo ; do token=`cat token.list | awk 'NR=='$sum'{print $0}'` ; curl -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${{ secrets.TOKEN }}" https://api.github.com/repos/path/xxx.yml/dispatches -d '{"ref": "main","inputs":{"repo":"'"${repo}"'","token":"'"${token}"'"}}' ; let sum++ ; done
# 获取 repo.list 单行为 name 双行为 token
# 以 name 为循环,获取 repo name , 或者 token 发送 POST 请求