GithubWorkFlow 就是 Git 自带的 CI 服务
1name: Greet Everyone
2# 事件
3on: [push]
4# 工作集合
5jobs:
6 build:
7 # 作业名称为 Greeting
8 name: Greeting
9 # 此作业在 Linux 上运行,runs-on选项一共就有几种类型
10 runs-on: ubuntu-latest
11 steps:
12 # 此步骤使用 GitHub 的 hello-world-javascript-action:https://github.com/actions/hello-world-javascript-action
13 - name: Hello world
14 uses: actions/hello-world-javascript-action@v1
15 with:
16 who-to-greet: 'Mona the Octocat'
17 id: hello
18 # 此步骤打印上一步操作的输出(时间)。
19 - name: Echo the greeting's time
20 run: echo 'The time was ${{ steps.hello.outputs.time }}.'
push
,pull_request
,create
更多 1on:
2 push:
3 branches:
4 # master分支发push请求时
5 - master
6 pull_request:
7 branches:
8 # master分支pull_request时
9 - master
10 page_build:
11 release:
12 types:
13 - created
1# 当release的published,created,edited事件被触发时
2on:
3 release:
4 types: [published,created,edited]
1# 在这些分支和tag被push代码时触发
2# ignore在这些分支和tag被push时不会触发
3on:
4 push:
5 branches:
6 - master
7 - 'mona/octocat'
8 - 'releases/**'
9 tags:
10 - v1
11 - v1.*
12 branches-ignore:
13 - devp
14 - '**-alpha'
15 tags-ignore:
16 - v2.*
1# 当有js被推送时触发
2# 当docs下推送时不触发
3on:
4 push:
5 paths:
6 - '**.js'
7 paths-ignore:
8 - 'docs/**'
1# 每隔15分钟构建一次
2on:
3 schedule:
4 - cron: '*/15 * * * *'
1env:
2 SERVER: production
1jobs:
2 my_first_job:
3 name: MyfirstJob
4 my_second_job:
5 name: MysecondJob
1jobs:
2 job1:
3 job2:
4 needs: job1
5 job3:
6 needs: [job1,job2]
虚拟环境 | YAML 工作流程标签 |
---|---|
Windows Server 2019 | windows-latest 或 windows-2019 |
Ubuntu 18.04 | ubuntu-latest 或 ubuntu-18.04 |
Ubuntu 16.04 | ubuntu-16.04 |
macOS Catalina 10.15 | macos-latest or macos-10.15 |
1runs-on : windows-latest
1jobs:
2 job1:
3 env:
4 FIRST_NAME: mona
1name: Greeting from Mona
2
3on: push
4
5jobs:
6 my-job:
7 name: My Job
8 runs-on: ubuntu-latest
9 steps:
10 - name: Print a greeting
11 env:
12 MY_VAR: Hi there! My name is
13 FIRST_NAME: Mona
14 MIDDLE_NAME: The
15 LAST_NAME: Octocat
16 run: |
17 echo $MY_VAR $FIRST_NAME $MIDDLE_NAME $LAST_NAME.
1jobs:
2 my_first_job:
3 steps:
4 - name: My first step
5 uses: actions/heroku@master
6 - name: My second step
7 uses: actions/aws@v2.0.1
8
9
10jobs:
11 my_first_job:
12 steps:
13 - name: My first step
14 uses: docker://alpine:3.8
1- name: install dependencies and build
2 run: |
3 npm ci
4 shell: bash
5
6
7
8
9- name: Clean temp directory
10 run: rm -rf *
11 working-directory: ./temp
环境列表 `
支持的平台 | shell 参数 | 描述 | 内部运行命令 |
---|---|---|---|
所有 | bash | 非 Windows 平台上回退到 sh 的默认 shell。 指定 Windows 上的 bash shell 时,将使用 Git for Windows 随附的 bash shel。 | bash --noprofile --norc -eo pipefail {0} |
所有 | pwsh | PowerShell Core。 GitHub 将扩展名 .ps1 附加到您的脚本名称。 | pwsh -command "& '{0}'" |
所有 | python | 执行 python 命令。 | python {0} |
Linux / macOS | sh | 未提供 shell 且 在路径中找不到 bash 时的非 Windows 平台的后退行为。 | sh -e {0} |
Windows | cmd | GitHub 将扩展名 .cmd 附加到您的脚本名称并替换 {0} 。 | %ComSpec% /D /E:ON /V:OFF /S /C "CALL "{0}"" . |
Windows | powershell | 这是 Windows 上使用的默认 shell。 Desktop PowerShell。 GitHub 将扩展名 .ps1 附加到您的脚本名称。 | powershell -command "& '{0}'" . |
1# with传入了actions/hello_word@master操作所需要的三个参数,参数名称为fitst_name,middle_name,last_name
2jobs:
3 my_first_job:
4 steps:
5 - name: My first step
6 uses: actions/hello_world@master
7 with:
8 first_name: Mona
9 middle_name: The
10 last_name: Octocat
1steps:
2 - name: Explain why this job ran
3 uses: monacorp/action-name@master
4 with:
5 entrypoint: /bin/echo
6 args: The ${{ github.event_name }} event triggered this step.
7
1steps:
2 - name: Run a custom command
3 uses: monacorp/action-name@master
4 with:
5 entrypoint: /a/different/executable
secrets
上下文设置1steps:
2 - name: My first action
3 env:
4 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 FIRST_NAME: Mona
6 LAST_NAME: Octocat
1steps:
2 - continue-on-error: true
3 - name: My first action
4 env:
5 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 FIRST_NAME: Mona
7 LAST_NAME: Octocat
8
1# 3*1 3个任务,每个都会试
2strategy:
3 matrix:
4 node: [6, 8, 10]
5steps:
6 # Configures the node version used on GitHub-hosted runners
7 - uses: actions/setup-node@v1
8 with:
9 # The Node.js version to configure
10 node-version: ${{ matrix.node }}
11
1# os和node全排列
2runs-on: ${{ matrix.os }}
3strategy:
4 matrix:
5 os: [ubuntu-16.04, ubuntu-18.04]
6 node: [6, 8, 10]
7steps:
8 - uses: actions/setup-node@v1
9 with:
10 node-version: ${{ matrix.node }}
11
添加额外的配置到矩阵中
1# include 在os为windows-latest时且node为4时,npm为2
2runs-on: ${{ matrix.os }}
3strategy:
4 matrix:
5 os: [macos-latest, windows-latest, ubuntu-18.04]
6 node: [4, 6, 8, 10]
7 include:
8 - os: windows-latest
9 node: 4
10 npm: 2
1strategy:
2 max-parallel: 2
1jobs:
2 my_job:
3 container:
4 image: node:10.16-jessie
5 env:
6 NODE_ENV: development
7 ports:
8 - 80
9 volumes:
10 - my_docker_volume:/volume_mount
11 options: --cpus 1
12
1services:
2 nginx:
3 image: nginx
4 volumes:
5 - my_docker_volume:/volume_mount
6 - /data/my_data
7 - /source/directory:/destination/directory
8 ports:
9 - 8080:80
10 redis:
11 image: redis
12 ports:
13 - 6379/tcp
14
项目地址:https://github.com/ferried/animal-crossing-cli
action 地址 : https://github.com/ferried/animal-crossing-cli/runs/648812568?check_suite_focus=true
1name: Go
2on:
3 push:
4 branches: [ devp ]
5 pull_request:
6 branches: [ devp ]
7jobs:
8 release:
9 name: release
10 runs-on: ubuntu-latest
11 steps:
12
13 - name: setup go
14 uses: actions/setup-go@v2
15 with:
16 go-version: ^1.13
17 id: go
18
19 - name: checkout code
20 uses: actions/checkout@v2
21
22 - name: install dependencies
23 run: |
24 go get -v -t -d ./...
25 if [ -f Gopkg.toml ]; then
26 curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
27 dep ensure
28 fi
29
30 - name: test code
31 run: go test
32