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 totrueExpression,三元运算符
You can access environment variable values using the env context and configuration variable values using the vars context.
即变量分为两种,
environment variable和configuratoin variable,前者只适用于一个workflow而后者适用于多个workflowenvironment 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_dispatchSetting permissions for the token
permissionsControlling how many workflow runs or jobs can run at the same time
concurrencyPreventing a job from running unless specific conditions are met
ifFor 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容器来创建数据库等。