github actions
1 |
|
在 github 上可以设置 secrets 来使用某些数据时不被人发现
1
echo ${{ secrets. MYSECRET }} //MYSECRET 是自己设置的secret名字
github action 文件只对本分支有效,那么 指定分支的意义何在?
是方便一个项目只在一个 ./.github/workflows 中统一管理 github action.yml 文件?
Using the
${{ }}
expression syntax turns the contents into a string, and strings are truthy.if: true && ${{ false }}
will evaluate totrue
Expression,三元运算符
You can access environment variable values using the env context and configuration variable values using the vars context.
即变量分为两种,
environment variable
和configuratoin variable
,前者只适用于一个workflow
而后者适用于多个workflow
environment variable
是有范围的,由低到高:jobs.<job_id>.steps[*].env
,jobs.<job_id>.env
,top level
,低范围覆盖高范围,注意同范围没有先后顺序,且同范围同名字只能 1 个。调用这些变量可以通过 context 或在runner
中使用对应的环境变量调用语法。如果不用,而用${{ }}
这种 github 语法,则是由 github action 提前处理后再传入到 runner 中。configuration variable
有几个级别:environment
,repository
,orgnization
。注意这里的environment
区别,这里是指你可以在一个仓库创建多个environment
环境,一个环境中可以定义多个variable
或secret
(同repository
级别一样) 而在workflow
中的每个job
你都可以通过environment:
指定一个环境!configuration variable
不会传入到runner
中,如果需要,则需要再用env
来映射以下。Default environment variable属于特殊的第一种(Environment variable),但访问方式不同,但同样是可以传给
runner
相关:output
environment variable
一定要区分两部分:Github actions
处理的部分,和发送给runner
处理的部分if
语句用context
可以省略${{}}
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
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
来设置具体权限使用
services
容器来创建数据库等。