功能预览: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 管理子系统
截图
- 系统管理员可以访问 Runners 管理界面来创建、编辑和删除 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 文档中的一些示例,如果发现缺陷请报告,以便我们解决。