功能预览:Gitea Actions
Gitea 呼声最高的功能之一就是引入 CI/CD 系统,并与现有第三方 CI/CD 系统更好地集成。随着 Gitea Actions 的开发工作推进,我们希望为这一问题提供解决方案。
❗ 免责声明
⚠️ 该功能为实验性,请注意:
- 它默认处于禁用状态;
- 目前不应在生产环境中使用;
- 目前不应在公共 Gitea 实例中使用;
- 在稳定之前可能会进行破坏性变更。
- 该合并请求正在接受社区审查,设计可能会有变更。
Gitea Actions 概览
Gitea Actions 的目标是让 Gitea 与现有 CI/CD 系统之间的集成更加紧密。另一个目标是为独立 runner 提供统一的管理接口,以在需要时减少支持多个系统的管理开销。独立 runner 工作流旨在与 GitHub Actions 兼容,并可用于在 Gitea 上构建、测试、打包、发布或部署任何代码项目。
Gitea Actions 不止于 DevOps,还允许你在仓库中发生其他事件时运行工作流。例如,你可以运行一个工作流,在有人于你的仓库中创建新工单时自动添加适当的标签。
DevOps 工具链
有许多第三方 CI/CD 系统可以与 Gitea 集成。以下是一些较为流行的系统:
- Agola
- AppVeyor
- AWS Cloud Integration(webhook-to-s3)
- buildbot-gitea
- buildkite-connector
- Concourse
- Dex
- Drone
- Jenkins
- Jianmu CI
- Metroline
- mvoCI
- Tea Runner
- Woodpecker
新的 Gitea Actions 系统可以让这些现有系统将结果直接推送到 Gitea,从而以统一的方式查看;如果管理员不希望管理多个系统,也可以选择使用独立的 runner。
创建 Gitea Actions
将工作流保留在仓库中的设计理念(例如 Drone、Woodpecker 和 GitHub Actions 的做法)使仓库与 CI 工具之间的集成更紧密,实现了配置即代码。同时,平台用户为整个系统提供了丰富的应用扩展。
经过两年的研究和讨论,Gitea 内置 CI/CD 系统的开发任务取得了重大进展。(参与讨论 #13539)
实现
Gitea Actions 实现了一个内置的 CI/CD 系统框架,兼容 GitHub Actions 的 YAML 工作流格式,并兼容 GitHub Marketplace 中大多数现有的 Actions 插件。
该系统由三部分组成:
- 定义 和 实现 的 Gitea Actions 协议。第三方 CI/CD 系统可以使用该协议将结果直接发布到 Gitea。
- 基于 nektos/act 的 Gitea runner。
- 实现 Actions 管理子系统
截图
- 系统管理员可以访问 Runner 管理界面来创建、编辑和删除 Runner。

- 从导航栏打开 Actions 以查看 CI 构建日志。

- 查看日志。

在本地机器上试用
要求
- 构建 Gitea 所需的所有现有工具
- Docker:可调用的 Docker API,用于运行容器
从源码构建
- 启动 Gitea
克隆功能分支并 从源码安装:
git clone https://github.com/go-gitea/gitea.git
cd gitea
git fetch origin pull/21937/head
git checkout -b pullrequest FETCH_HEAD
# Build with SQLite support
TAGS="bindata sqlite sqlite_unlock_notify" make build
# Initialize Gitea
./gitea web
在 app.ini 中添加额外配置以启用 Actions:
# custom/conf/app.ini
[actions]
ENABLED = true
重新启动它。如果一切正常,你会在 站点管理 中看到 Runner 管理 页面。
- 启动 runner
克隆 act_runner,并按照 README 启动它。
git clone https://gitea.com/gitea/act_runner.git
cd act_runner
make build
然后将 Runner 注册到 Gitea 服务器。
交互式命令:
./act_runner register
系统会要求你输入:
- Gitea 实例 URL,例如
http://192.168.1.100:3000/。你应该使用你的 Gitea 实例 ROOT_URL 作为实例参数,并且不应使用 localhost 或 127.0.0.1 作为实例 IP; - Runner 令牌,你可以从
http://192.168.1.100:3000/admin/runners获取; - Runner 名称,可以留空;
- Runner 标签,可以留空。
非交互式命令:
./act_runner register --instance http://<your_gitea_instance> --token <your_runner_token> --no-interactive
以守护进程方式运行
./act_runner daemon
- 为仓库启用 Actions
创建一个新仓库或打开现有仓库,在设置中勾选 Actions 复选框并提交。

如果一切正常,你会看到一个新的“Actions”标签页:

- 上传工作流文件
将一些工作流文件上传到 .gitea/workflows/<some-actions-name>.yaml,你可以参考 GitHub Actions 的 快速入门。是的,Gitea Actions 在大多数情况下兼容 GitHub Actions,你可以使用相同的演示:
# .gitea/workflows/build.yaml
name: Gitea Actions Demo
run-name: ${{ github.actor }} is testing out Gitea Actions 🚀
on: [push]
jobs:
Explore-Gitea-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
如果一切正常,你会在 Actions 标签页看到一次新的运行:

- 查看作业日志
点击一次运行,你就会看到日志。很容易看到 Gitea Runner 已拉取 Docker 镜像作为基础环境。

- 未来探索
由于 Gitea Actions 与 GitHub Actions 存在交集,你可以尝试 GitHub Actions 文档 中的一些示例,如果发现 bug,请报告以便修复。