Skip to content

Commit

Permalink
doc: update docs/github-actions.md (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 16, 2024
1 parent 187fe9e commit d3e778e
Showing 1 changed file with 53 additions and 52 deletions.
105 changes: 53 additions & 52 deletions docs/github-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,6 @@ on:
types: [published]
```

### 定时触发
可以使用 cron 表达式配置周期性任务,定时执行

```yaml
name: schedule task

# 要注意时差,最好手动指定时区
env:
TZ: Asia/Shanghai

on:
# push 到 main 分支时执行任务
push:
branches:
- main
# 每隔两小时自动执行任务
schedule:
- cron: '0 0/2 * * *'
```

### 多项任务

```yml
Expand Down Expand Up @@ -175,6 +155,27 @@ jobs:
- run: echo ${{needs.job1.outputs.output1}} ${{needs.job1.outputs.output2}}
```

### 定时触发

可以使用 cron 表达式配置周期性任务,定时执行

```yaml
name: schedule task

# 要注意时差,最好手动指定时区
env:
TZ: Asia/Shanghai

on:
# push 到 main 分支时执行任务
push:
branches:
- main
# 每隔两小时自动执行任务
schedule:
- cron: '0 0/2 * * *'
```

### 指定每项任务的虚拟机环境

```yml
Expand Down Expand Up @@ -294,7 +295,7 @@ env:
<!--rehype:className=cols-2 style-none-->

### Github 上下文
<!--rehype:wrap-class=col-span-2-->
<!--rehype:wrap-class=col-span-2 row-span-3-->

属性名称 | 类型 | 描述
---- | ---- | ----
Expand All @@ -320,34 +321,7 @@ env:

[Github 上下文](https://help.github.com/cn/actions/reference/context-and-expression-syntax-for-github-actions)是访问有关工作流运行、运行器环境、作业和步骤的信息的一种方式

### 默认环境变量

环境变量 | 描述
---- | ----
`CI` | 始终设置为 `true`
`HOME` | 用于存储用户数据的 GitHub 主目录路径。 例如 `/github/home`
`GITHUB_WORKFLOW` | 工作流程的名称。
`GITHUB_RUN_ID` | 仓库中每个运行的唯一编号。 如果您重新执行工作流程运行,此编号不变。
`GITHUB_RUN_NUMBER` | 仓库中特定工作流程每个运行的唯一编号。 此编号从 1(对应于工作流程的第一个运行)开始,然后随着每个新的运行而递增。 如果您重新执行工作流程运行,此编号不变。
`GITHUB_ACTION` | 操作唯一的标识符 (id)。
`GITHUB_ACTIONS` | 当 GitHub 操作 运行工作流程时,始终设置为 true。 您可以使用此变量来区分测试是在本地运行还是通过 GitHub 操作 运行。
`GITHUB_ACTION_PATH` | GitHub 操作所在的路径
`GITHUB_ACTOR` | 发起工作流程的个人或应用程序的名称。 例如 octocat
`GITHUB_API_URL` | 返回 `API URL`。例如:`https://api.github.com`
`GITHUB_REPOSITORY` | 所有者和仓库名称。 例如 octocat/Hello-World
`GITHUB_EVENT_NAME` | 触发工作流程的 web 挂钩事件的名称
`GITHUB_EVENT_PATH` | 具有完整 web 挂钩事件有效负载的文件路径。 例如 /github/workflow/event.json
`GITHUB_WORKSPACE` | GitHub 工作空间目录路径。 如果您的工作流程使用 [actions/checkout](https://github.com/actions/checkout) 操作,工作空间目录将包含存储仓库副本的子目录。 如果不使用 [actions/checkout](https://github.com/actions/checkout) 操作,该目录将为空。 例如 /home |/runner/work/my-repo-name/my-repo-name
`GITHUB_SHA` | 触发工作流程的提交 SHA。 例如 ffac537e6cbbf9
`GITHUB_REF` | 触发工作流程的分支或标记参考。 例如 refs/heads/feature-branch-1。 如果分支或标记都不适用于事件类型,则变量不会存在
`GITHUB_HEAD_REF` | 仅为复刻的仓库设置。头部仓库的分支
`GITHUB_BASE_REF` | 仅为复刻的仓库设置。基础仓库的分支
<!--rehype:className=style-list-arrow-->

另见: [默认环境变量](https://docs.github.com/cn/actions/learn-github-actions/environment-variables#default-environment-variables)

### 直接常量
<!--rehype:wrap-class=row-span-2-->

作为表达式的一部分,可以使用 `boolean`, `null`, `number``string`数据类型

Expand All @@ -364,7 +338,6 @@ env:
```

### 函数 contains
<!--rehype:wrap-class=row-span-2-->

使用字符串的示例

Expand All @@ -389,6 +362,33 @@ startsWith('Hello world', 'He') // 返回 true

另见: [函数 startsWith](https://docs.github.com/cn/actions/learn-github-actions/expressions#startswith),此函数不区分大小写

### 默认环境变量
<!--rehype:wrap-class=row-span-8 col-span-2-->

环境变量 | 描述
---- | ----
`CI` | 始终设置为 `true`
`HOME` | 用于存储用户数据的 GitHub 主目录路径。 例如 `/github/home`
`GITHUB_WORKFLOW` | 工作流程的名称。
`GITHUB_RUN_ID` | 仓库中每个运行的唯一编号。 如果您重新执行工作流程运行,此编号不变。
`GITHUB_RUN_NUMBER` | 仓库中特定工作流程每个运行的唯一编号。 此编号从 1(对应于工作流程的第一个运行)开始,然后随着每个新的运行而递增。 如果您重新执行工作流程运行,此编号不变。
`GITHUB_ACTION` | 操作唯一的标识符 (id)。
`GITHUB_ACTIONS` | 当 GitHub 操作 运行工作流程时,始终设置为 true。 您可以使用此变量来区分测试是在本地运行还是通过 GitHub 操作 运行。
`GITHUB_ACTION_PATH` | GitHub 操作所在的路径
`GITHUB_ACTOR` | 发起工作流程的个人或应用程序的名称。 例如 octocat
`GITHUB_API_URL` | 返回 `API URL`。例如:`https://api.github.com`
`GITHUB_REPOSITORY` | 所有者和仓库名称。 例如 octocat/Hello-World
`GITHUB_EVENT_NAME` | 触发工作流程的 web 挂钩事件的名称
`GITHUB_EVENT_PATH` | 具有完整 web 挂钩事件有效负载的文件路径。 例如 /github/workflow/event.json
`GITHUB_WORKSPACE` | GitHub 工作空间目录路径。 如果您的工作流程使用 [actions/checkout](https://github.com/actions/checkout) 操作,工作空间目录将包含存储仓库副本的子目录。 如果不使用 [actions/checkout](https://github.com/actions/checkout) 操作,该目录将为空。 例如 /home |/runner/work/my-repo-name/my-repo-name
`GITHUB_SHA` | 触发工作流程的提交 SHA。 例如 ffac537e6cbbf9
`GITHUB_REF` | 触发工作流程的分支或标记参考。 例如 refs/heads/feature-branch-1。 如果分支或标记都不适用于事件类型,则变量不会存在
`GITHUB_HEAD_REF` | 仅为复刻的仓库设置。头部仓库的分支
`GITHUB_BASE_REF` | 仅为复刻的仓库设置。基础仓库的分支
<!--rehype:className=style-list-arrow-->

另见: [默认环境变量](https://docs.github.com/cn/actions/learn-github-actions/environment-variables#default-environment-variables)

### 函数 format

```js
Expand All @@ -402,7 +402,7 @@ format('{{Hello {0} {1} {2}!}}', 'Mona', 'the', 'Octocat')
### 函数 join

```js
join(github.event.issue.labels.*.name, ', ')
join(github.event.issue.labels.*.name,', ')
// 也许返回 'bug, help wanted'.
```

Expand Down Expand Up @@ -603,14 +603,15 @@ npm token revoke <id|token> # 撤销

Artifacts 是 GitHub Actions 为您提供持久文件并在运行完成后使用它们或在作业(文档)之间共享的一种方式。

要创建工件并使用它,您将需要不同的操作:上传和下载。
- 要创建工件并使用它,您将需要不同的操作:上传和下载

要上传文件或目录,您只需像这样使用它:

```yml
steps:
- uses: actions/checkout@v2
- run: mkdir -p path/to/artifact
- run: echo hello > path/to/artifact/a.txt
- run: echo hello > path/to/file/a.txt
- uses: actions/upload-artifact@v2
with:
name: my-artifact
Expand Down

0 comments on commit d3e778e

Please sign in to comment.