github actions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
name: ci
on:
push:
branches:
- master
paths:
- src/*
jobs:
job1:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3 //把代码下载下来
- uses: actions/setup-node@v1 //node js 环境
with:
node-version: '10.x'
- uses: ./.github/actions/my.action
- uses: docker://alpine:3.8
- run: echo hello
- run: |
npm install
npm run build --if-present
npm test
job2:
runs-on: ubuntu-latest
container:
image: node:8 // container 是使用 docker 正确写法
steps:
- uses: actions/checkout@v3
- run: |
node -v
  • 在 github 上可以设置 secrets 来使用某些数据时不被人发现

    1
    echo ${{ secrets. MYSECRET }} //MYSECRET 是自己设置的secret名字
  • github action 文件只对本分支有效,那么 指定分支的意义何在?

    是方便一个项目只在一个 ./.github/workflows 中统一管理 github action.yml 文件?

  • sharing data between jobs

  • Using the ${{ }} expression syntax turns the contents into a string, and strings are truthy. if: true && ${{ false }} will evaluate to true

  • Expression,三元运算符

  • contexts

  • You can access environment variable values using the env context and configuration variable values using the vars context.

    即变量分为两种,environment variableconfiguratoin variable,前者只适用于一个 workflow 而后者适用于多个 workflow

    environment variable 是有范围的,由低到高:jobs.<job_id>.steps[*].envjobs.<job_id>.envtop level,低范围覆盖高范围,注意同范围没有先后顺序,且同范围同名字只能 1 个。调用这些变量可以通过 context 或在 runner 中使用对应的环境变量调用语法。如果不用,而用 ${{ }} 这种 github 语法,则是由 github action 提前处理后再传入到 runner 中。

    configuration variable 有几个级别:environmentrepositoryorgnization。注意这里的 environment 区别,这里是指你可以在一个仓库创建多个 environment 环境,一个环境中可以定义多个 variablesecret(同 repository 级别一样) 而在 workflow 中的每个 job 你都可以通过 environment: 指定一个环境!configuration variable 不会传入到 runner 中,如果需要,则需要再用 env 来映射以下。

    Default environment variable属于特殊的第一种(Environment variable),但访问方式不同,但同样是可以传给 runner

    相关:output

  • environment variable 一定要区分两部分:Github actions 处理的部分,和发送给 runner 处理的部分

  • if 语句用 context 可以省略 ${{}}

  • 利用 github action 自动检错并创建 issue

  • Manually running a workflow from the UI workflow_dispatch

  • Setting permissions for the token permissions

  • Controlling how many workflow runs or jobs can run at the same time concurrency

  • Preventing a job from running unless specific conditions are met if

  • matrix 通过不同组合执行相同的功能,通常指定不同语言版本,不同操作系统

  • cache

  • containerized services

  • tringgering a workflow from a work flow

  • For example, if the event occurred on a particular repository branch, then the workflow files must be present in the repository on that branch. 即触发的 workflow 是当前导致分支的 workflow

  • 生成一个 github action 时,会自带一个 GITHUB_TOKEN,只能拥有当前仓库的权限,可以通过 permissions 来设置具体权限

  • runner 文档

  • 使用 services 容器来创建数据库等。

  • if, if


github actions
https://lllei.top/2023/10/21/github actions/
作者
Lei
发布于
2023年10月22日
许可协议