Skip to content

Commit

Permalink
Add Chinese documentations for Actions (#24902)
Browse files Browse the repository at this point in the history
  • Loading branch information
HesterG committed May 25, 2023
1 parent 69eb92a commit cff4e37
Show file tree
Hide file tree
Showing 12 changed files with 877 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/content/doc/usage/actions/act-runner.en-us.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
date: "2023-04-27T15:00:00+08:00"
title: "Act Runner"
slug: "usage/actions/act-runner"
slug: "act-runner"
weight: 20
draft: false
toc: false
Expand Down
203 changes: 203 additions & 0 deletions docs/content/doc/usage/actions/act-runner.zh-cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
---
date: "2023-05-24T15:00:00+08:00"
title: "Act Runner"
slug: "act-runner"
weight: 20
draft: false
toc: false
menu:
sidebar:
parent: "actions"
name: "Act Runner"
weight: 20
identifier: "actions-runner"
---

# Act Runner

本页面将详细介绍[Act Runner](https://gitea.com/gitea/act_runner),这是Gitea Actions的Runner。

**目录**

{{< toc >}}

## 要求

建议在Docker容器中运行Job,因此您需要首先安装Docker。
并确保Docker守护进程正在运行。

其他与Docker API兼容的OCI容器引擎也应该可以正常工作,但尚未经过测试。

但是,如果您确定要直接在主机上运行Job,则不需要Docker。

## 安装

有多种安装Act Runner的方法。

### 下载二进制文件

您可以从[发布页面](https://gitea.com/gitea/act_runner/releases)下载二进制文件。
然而,如果您想使用最新的夜间构建版本,可以从[下载页面](https://dl.gitea.com/act_runner/)下载。

下载二进制文件时,请确保您已经下载了适用于您的平台的正确版本。
您可以通过运行以下命令进行检查:

```bash
chmod +x act_runner
./act_runner --version
```

如果看到版本信息,则表示您已经下载了正确的二进制文件。

### 使用 Docker 镜像

您可以使用[docker hub](https://hub.docker.com/r/gitea/act_runner/tags)上的Docker镜像。
与二进制文件类似,您可以使用`nightly`标签使用最新的夜间构建版本,而`latest`标签是最新的稳定版本。

```bash
docker pull gitea/act_runner:latest # for the latest stable release
docker pull gitea/act_runner:nightly # for the latest nightly build
```

## 配置

配置通过配置文件进行。它是可选的,当没有指定配置文件时,将使用默认配置。

您可以通过运行以下命令生成配置文件:

```bash
./act_runner generate-config
```

默认配置是安全的,可以直接使用。

```bash
./act_runner generate-config > config.yaml
./act_runner --config config.yaml [command]
```

当使用Docker镜像时,可以使用`CONFIG_FILE`环境变量指定配置文件。确保将文件作为卷挂载到容器中:

```bash
docker run -v $(pwd)/config.yaml:/config.yaml -e CONFIG_FILE=/config.yaml ...
```

您可能注意到上面的命令都是不完整的,因为现在还不是运行Act Runner的时候。
在运行Act Runner之前,我们需要首先将其注册到您的Gitea实例中。

## 注册

在运行Act Runner之前,需要进行注册,因为Runner需要知道从哪里获取Job,并且对于Gitea实例来说,识别Runner也很重要。

### Runner级别

您可以在不同级别上注册Runner,它可以是:

- 实例级别:Runner将为实例中的所有存储库运行Job。
- 组织级别:Runner将为组织中的所有存储库运行Job。
- 存储库级别:Runner将为其所属的存储库运行Job。

请注意,即使存储库具有自己的存储库级别Runner,它仍然可以使用实例级别或组织级别Runner。未来的版本可能提供更多对此进行更好控制的选项。

### 获取注册令牌

Runner级别决定了从哪里获取注册令牌。

- 实例级别:管理员设置页面,例如 `<your_gitea.com>/admin/runners`
- 组织级别:组织设置页面,例如 `<your_gitea.com>/<org>/settings/runners`
- 存储库级别:存储库设置页面,例如 `<your_gitea.com>/<owner>/<repo>/settings/runners`

如果您无法看到设置页面,请确保您具有正确的权限并且已启用 Actions。

注册令牌的格式是一个随机字符串 `D0gvfu2iHfUjNqCYVljVyRV14fISpJxxxxxxxxxx`

### 注册Runner

可以通过运行以下命令来注册Act Runner:

```bash
./act_runner register
```

或者,您可以使用 `--config` 选项来指定前面部分提到的配置文件。

```bash
./act_runner --config config.yaml register
```

您将逐步输入注册信息,包括:

- Gitea 实例的 URL,例如 `https://gitea.com/``http://192.168.8.8:3000/`
- 注册令牌。
- Runner名称(可选)。如果留空,将使用主机名。
- Runner标签(可选)。如果留空,将使用默认标签。

您可能对Runner标签感到困惑,稍后将对其进行解释。

如果您想以非交互方式注册Runner,可以使用参数执行以下操作。

```bash
./act_runner register --no-interactive --instance <instance_url> --token <registration_token> --name <runner_name> --labels <runner_labels>
```

注册Runner后,您可以在当前目录中找到一个名为 `.runner` 的新文件。该文件存储注册信息。
请不要手动编辑该文件。
如果此文件丢失或损坏,可以直接删除它并重新注册。

如果您想将注册信息存储在其他位置,请在配置文件中指定,并不要忘记指定 `--config` 选项。

### 使用Docker注册Runner

如果您使用的是Docker镜像,注册行为会略有不同。在这种情况下,注册和运行合并为一步,因此您需要在运行Act Runner时指定注册信息。

```bash
docker run \
-v $(pwd)/config.yaml:/config.yaml \
-v $(pwd)/data:/data \
-v /var/run/docker.sock:/var/run/docker.sock \
-e CONFIG_FILE=/config.yaml \
-e GITEA_INSTANCE_URL=<instance_url> \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
-e GITEA_RUNNER_NAME=<runner_name> \
-e GITEA_RUNNER_LABELS=<runner_labels> \
--name my_runner \
-d gitea/act_runner:nightly
```

您可能注意到我们已将`/var/run/docker.sock`挂载到容器中。
这是因为Act Runner将在Docker容器中运行Job,因此它需要与Docker守护进程进行通信。
如前所述,如果要在主机上直接运行Job,可以将其移除。
需要明确的是,这里的 "主机" 实际上指的是当前运行 Act Runner的容器,而不是主机机器本身。

### 标签

Runner的标签用于确定Runner可以运行哪些Job以及如何运行它们。

默认标签为`ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye,ubuntu-20.04:docker://node:16-bullseye,ubuntu-18.04:docker://node:16-buster`
它们是逗号分隔的列表,每个项目都是一个标签。

让我们以 `ubuntu-22.04:docker://node:16-bullseye` 为例。
它意味着Runner可以运行带有`runs-on: ubuntu-22.04`的Job,并且该Job将在使用`node:16-bullseye`镜像的Docker容器中运行。

如果默认镜像无法满足您的需求,并且您有足够的磁盘空间可以使用更好、更大的镜像,您可以将其更改为`ubuntu-22.04:docker://<您喜欢的镜像>`
您可以在[act 镜像](https://github.com/nektos/act/blob/master/IMAGES.md)上找到更多有用的镜像。

如果您想直接在主机上运行Job,您可以将其更改为`ubuntu-22.04:host`或仅`ubuntu-22.04``:host`是可选的。
然而,我们建议您使用类似`linux_amd64:host``windows:host`的特殊名称,以避免误用。

还有一点需要注意的是,建议在更改标签时注册Runner。
这可能会有些麻烦,所以我们可能会在将来提供更好的方法来处理。

## 运行

注册完Runner后,您可以通过运行以下命令来运行它:

```bash
./act_runner daemon
# or
./act_runner daemon --config config.yaml
```

Runner将从Gitea实例获取Job并自动运行它们。

由于Act Runner仍处于开发中,建议定期检查最新版本并进行升级。
2 changes: 1 addition & 1 deletion docs/content/doc/usage/actions/comparison.en-us.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
date: "2023-04-27T15:00:00+08:00"
title: "Compared to GitHub Actions"
slug: "usage/actions/comparison"
slug: "comparison"
weight: 30
draft: false
toc: false
Expand Down
171 changes: 171 additions & 0 deletions docs/content/doc/usage/actions/comparison.zh-cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
---
date: "2023-05-24T15:00:00+08:00"
title: "与GitHub Actions的对比"
slug: "comparison"
weight: 30
draft: false
toc: false
menu:
sidebar:
parent: "actions"
name: "对比"
weight: 30
identifier: "actions-comparison"
---

# 与GitHub Actions的对比

尽管Gitea Actions旨在与GitHub Actions兼容,但它们之间存在一些差异。

**目录**

{{< toc >}}

## 额外功能

### Action URL绝对路径

Gitea Actions支持通过URL绝对路径定义actions,这意味着您可以使用来自任何Git存储库的Actions。
例如,`uses: https://github.com/actions/checkout@v3``uses: http://your_gitea.com/owner/repo@branch`

### 使用Go编写Actions

Gitea Actions支持使用Go编写Actions。
请参阅[创建Go Actions](https://blog.gitea.io/2023/04/creating-go-actions/)

## 不支持的工作流语法

### `concurrency`

这是用于一次运行一个Job。
请参阅[使用并发](https://docs.github.com/zh/actions/using-jobs/using-concurrency)

Gitea Actions目前不支持此功能。

### `run-name`

这是工作流生成的工作流运行的名称。
请参阅[GitHub Actions 的工作流语法](https://docs.github.com/zh/actions/using-workflows/workflow-syntax-for-github-actions#run-name)

Gitea Actions目前不支持此功能。

### `permissions``jobs.<job_id>.permissions`

请参阅[GitHub Actions的工作流语法](https://docs.github.com/zh/actions/using-workflows/workflow-syntax-for-github-actions#permissions)

Gitea Actions目前不支持此功能。

### `jobs.<job_id>.timeout-minutes`

请参阅[GitHub Actions的工作流语法](https://docs.github.com/zh/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idtimeout-minutes)

Gitea Actions目前不支持此功能。

### `jobs.<job_id>.continue-on-error`

请参阅[GitHub Actions的工作流语法](https://docs.github.com/zh/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idcontinue-on-error)

Gitea Actions目前不支持此功能。

### `jobs.<job_id>.environment`

请参阅[GitHub Actions的工作流语法](https://docs.github.com/zh/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idenvironment)

Gitea Actions 目前不支持此功能。

### 复杂的`runs-on`

请参阅[GitHub Actions的工作流语法](https://docs.github.com/zh/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on)

Gitea Actions目前只支持`runs-on: xyz``runs-on: [xyz]`

### `workflow_dispatch`

请参阅[GitHub Actions的工作流语法](https://docs.github.com/zh/actions/using-workflows/workflow-syntax-for-github-actions#onworkflow_dispatch)

Gitea Actions目前不支持此功能。

### `hashFiles`表达式

请参阅[表达式](https://docs.github.com/en/actions/learn-github-actions/expressions#hashfiles)

Gitea Actions目前不支持此功能,如果使用它,结果将始终为空字符串。

作为解决方法,您可以使用[go-hashfiles](https://gitea.com/actions/go-hashfiles)

## 缺失的功能

### 变量

请参阅[变量](https://docs.github.com/zh/actions/learn-github-actions/variables)

目前变量功能正在开发中。

### 问题匹配器

问题匹配器是一种扫描Actions输出以查找指定正则表达式模式并在用户界面中突出显示该信息的方法。
请参阅[问题匹配器](https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md)

Gitea Actions目前不支持此功能。

### 为错误创建注释

请参阅[为错误创建注释](https://docs.github.com/zh/actions/using-workflows/workflow-commands-for-github-actions#example-creating-an-annotation-for-an-error)

Gitea Actions目前不支持此功能。

## 缺失的UI功能

### 预处理和后处理步骤

预处理和后处理步骤在Job日志用户界面中没有自己的用户界面。

## 不一样的行为

### 下载Actions

Gitea Actions默认不从GitHub下载Actions。
"默认" 意味着您在`uses` 字段中不指定主机,如`uses: actions/checkout@v3`
相反,`uses: https://github.com/actions/checkout@v3`是有指定主机的。

如果您不进行配置,缺失的主机将填充为`https://gitea.com`
这意味着`uses: actions/checkout@v3`将从[gitea.com/actions/checkout](https://gitea.com/actions/checkout)下载该Action,而不是[github.com/actions/checkout](https://github.com/actions/checkout)

正如前面提到的,这是可配置的。
如果您希望您的运行程序默认从GitHub或您自己的Gitea实例下载动作,您可以通过设置`[actions].DEFAULT_ACTIONS_URL`进行配置。请参阅[配置备忘单]({{< relref "doc/administration/config-cheat-sheet.en-us.md#actions-actions" >}})。

### 上下文可用性

不检查上下文可用性,因此您可以在更多地方使用env上下文。
请参阅[上下文可用性](https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability)

## 已知问题

### `docker/build-push-action@v4`

请参阅[act_runner#119](https://gitea.com/gitea/act_runner/issues/119#issuecomment-738294)

`ACTIONS_RUNTIME_TOKEN`在Gitea Actions中是一个随机字符串,而不是JWT。
但是`DOCKER/BUILD-PUSH-ACTION@V4尝试将令牌解析为JWT,并且不处理错误,因此Job失败。

有两种解决方法:

手动将`ACTIONS_RUNTIME_TOKEN`设置为空字符串,例如:

``` yml
- name: Build and push
uses: docker/build-push-action@v4
env:
ACTIONS_RUNTIME_TOKEN: ''
with:
...
```

该问题已在较新的[提交](https://gitea.com/docker/build-push-action/commit/d8823bfaed2a82c6f5d4799a2f8e86173c461aba?style=split&whitespace=show-all#diff-1af9a5bdf96ddff3a2f3427ed520b7005e9564ad)中修复,但尚未发布。因此,您可以通过指定分支名称来使用最新版本,例如:

``` yml
- name: Build and push
uses: docker/build-push-action@master
with:
...
```
Loading

0 comments on commit cff4e37

Please sign in to comment.