体验 Gitea Actions


即将推出的 Gitea Actions 致力于打造一个 CI/CD 工具的标准协议,第三方 CI 系统可以基于actions 协议与 Gitea 平台集成,提供一站式管理方案。Gitea Actions 为此走出了第一步。

学习 GitHub Actions

GitHub Actions 是一种持续集成和持续交付 (CI/CD) 平台,可用于自动执行任务、测试和部署。用户可以创建工作流程来构建和测试存储库的每个拉取请求,或将合并的拉取请求部署到生产环境。

GitHub Actions 不仅仅是 DevOps,还允许用户在存储库中发生其他事件时运行工作流程。 例如,可以运行工作流程,以便在有人创建新问题时自动添加相应的标签。

GitHub 提供 Linux、Windows 和 macOS 虚拟机来运行工作流程,或者在自有的数据中心或云基础架构中托管运行器。

Gitea 的 DevOps 生态

得益于广大开源社区的支持,目前 Gitea 可以良好适配以下 DevOps 工具。

  • Agola
  • AppVeyor
  • AWS Cloud Integration(webhook-to-s3)
  • buildbot-gitea
  • buildkite-connector
  • Concourse
  • Dex
  • Drone
  • Ghorg
  • gickup
  • Jenkins
  • 建木 CI
  • Metroline
  • Monitoring mixin
  • mvoCI
  • Renovate
  • Tea Runner
  • Woodpecker

经过长期的社区互动,我们获得了大量第三方CI系统的集成方案。但我们始终发现,独立搭建并运维一整套CI系统只是一小部分极客的专长,对于更广泛的用户而言这并不是个简单的工作,于是我们开始尝试为此努力,让工具更好地为人服务。

打造 Gitea Actions

不可否认 GitHub Actions 打造了一套很棒的工作环境,它的设计理念使仓库与 CI 工具之间有了更加紧密的集成,实现了代码即配置,同时平台用户为整套系统提供了丰富的应用扩展,相比传统模式来说,易用性上更胜一筹。如果能将它的优点移植到 Gitea 将是件很棒的事情。

好消息是,经过两年的调研与讨论,我们终于将 Gitea 内置CI/CD系统的开发任务提上了日程。(#13539)

开发进展

https://github.com/go-gitea/gitea/issues/13539

Gitea Actions 实现了一个内置的 CI/CD 系统框架,兼容 GitHub Actions 的 YAML 工作流编排格式,兼容 GitHub Marketplace 中大部分现有的 Actions 插件。

系统由三部分组成:

  • Gitea Actions 协议的定义和 Golang实现
  • Actions Runner: 基于 nektos/act 实现的任务子系统
  • 在 Gitea 主程序上实现 Runner 任务管理和调度模块

运行截图

1.系统管理员可以访问 Runners 管理界面,创建、编辑和删除 Runner。

Runners 管理界面

2.通过仓库顶部的导航打开 Actions,查看 CI 构建信息。

仓库下的 Workflows 列表

3.点击某个 CI 构建结果,查看日志。

点击 Workflows 查看执行日志

尝鲜体验

⚠ 实验性功能,请勿用于生产环境

准备环境

  • 内存:至少 4GB,用于编译 Gitea
  • Docker:可执行 docker 命令,用于拉取和运行容器

搭建

1.编译运行 Gitea

下载带有 Actions 模块的 Gitea 源代码:

# 目前可以从 @wolfogre 的开发分支克隆带有 Actions 模块的源代码到本地编译。
git clone https://github.com/wolfogre/gitea.git --branch=feature/bots
cd gitea

编译方法可以参考从源代码安装。这里我们需要准备开发环境 Node.js LTS (nvm instal --lts) 和 Golang。

以下是推荐的打包方法(带有SQLite,方便本地测试)

TAGS="bindata sqlite sqlite_unlock_notify" make build

启动 Gitea 主程序。这里先走完初始化步骤,会生成一个配置文件,位于当前目录下的

./custom/conf/app.ini

编辑上述配置文件,打开 Actions 功能。

[actions]
ENABLED = true

重新启动程序:./gitea web

2.启动 Runner

首先编译 act_runner 程序

git clone https://gitea.com/gitea/act_runner.git
cd act_runner
make build

然后将 Runner 注册到 Gitea 服务器。

  • 方法一:使用交互命令配置
$ ./act_runner register

INFO Registering runner, arch=amd64, os=linux, version=0.1.5.
WARN Runner in user-mode.
INFO Enter the Gitea instance URL (for example, https://gitea.com/): [输入服务器地址]
INFO Enter the runner token: [输入 Runner 令牌]
INFO Enter the runner name (if set empty, use hostname:ubuntu ): [输入 Runner 名称]
INFO Enter the runner labels, leave blank to use the default labels (comma-separated, for example, ubuntu-20.04:docker://node:16-bullseye,ubuntu-18.04:docker://node:16-buster): [输入 Runner 标签]

...
DEBU Successfully pinged the Gitea instance server
INFO Runner registered successfully.
  • 方法二:非交互式命令
    • --no-interactive
    • --instance 填写服务器地址
    • --token 填写管理员从服务器获取的 Actions 令牌(/admin/runners
./act_runner register --instance http:// --token--no-interactive

启动程序

./act_runner daemon

3.为仓库启用 Actions 功能

您可以新建一个仓库并手动开启仓库设置中的 Actions 功能。

启用 Actions 功能

刷新页面后,我们可以发现仓库的顶部功能导航栏中多了一个 Actions 功能,点击 Actions 进入可以看到目前为空的 All Workflows 任务列表。

4.上传 Workflows 配置到仓库目录 .gitea/workflows/build.yaml。由于 Gitea Actions 兼容 GitHub Actions,因此您可以从 GitHub 文档中复制示例。开始学习使用 Gitea Actions 吧!

🚀 阅读文档
https://docs.github.com/en/actions/quickstart

以下是一个示例,将它保存到 .gitea/workflows/build.yaml 时会触发 CI 工作:

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 功能面板,可以看到刚刚创建 Workflow 已经执行并且记录下了运行日志。

5.检查 CI 执行过程产生的日志。不难看出 Gitea Runner 拉取了 Docker 镜像作为 CI 构建过程所需的基础环境。

6.从 GitHub 文档中了解更多 Actions 用法,同时可以为我们提出改进意见!

🤖 Implement actions
https://github.com/go-gitea/gitea/pull/21937

🔧 GitHub Actions
https://docs.github.com/zh/actions/using-workflows

相關推薦

2023-03-24

Gitea 1.19.0 已发布,主要变化: 引入 Gitea Actions 支持 Asciicast 新增对 Cargo, Chef, Conda package registries 包管理的支持 提供预构建的 FreeBSD 二进制文件 在 Markdown 引用中高亮显示Note和Warning内容 支持使用电子邮件进行回复

2022-08-03

apply-patch命令添加了方便使用的 Web UI。 优化移动端体验 #19546 新版本重构了许多前端代码,但没有对当前的 UI 进行重大改变。由于增加了更多响应式设计,因此在移动端浏览 Gitea 的体验也得到了进一步提升。 Before&

2022-10-29

诞生 6 年后,Gitea 项目终于成立了商业公司:Gitea Limited。官方称此举是为了给项目带来更好的支持,以及提供更专业的服务,确保 Gitea 能够长期且可持续发展。 Gitea 是开源社区驱动的轻量级代码托管解决方案,后端采用 Go

2022-10-17

十月中旬,我们推出了 Gitea 1.17.3 版本。与此同时,1.18版本的新特性也几乎确定,追踪 Gitea 的代码仓库可以发现最新的 feature 大部分已进入冻结状态,相信不久之后会放出预览版,心急的小伙伴已经使用 Docker 快速切换到 Dev 分

2023-02-10

开发团队宣布已完成将代码托管平台从 Phabricator 迁移到 Gitea 的工作。 Blender 代码仓库地址:https://projects.blender.org/blender Phabricator 最初是 Facebook 内部使用的开发工具,核心开发者是 Evan Priestley,他在离开 Facebook 后,在名为

2023-10-30

使用 Fast Refresh 进行代码更新的速度提升 94% Server Actions (Stable): 渐进式的增强突变 重新验证缓存数据 支持简单的函数调用 本地支持表单 Partial Prerendering (Preview): 快速初始化静态响应 + 流式动态内容 Next.js Learn

2022-08-20

Gitea 1.17.1 已正式发布。在这个小的版本更新中我们合并了 35 个 PR,没有包含功能性的更改,但我们强烈建议用户升级到此版本以获得重要的修复补丁。 致谢:感谢报告问题的安全研究人员,同时感谢 @zeripath 的修复工作!

2023-10-30

举办的 Next.js Conf 2023,里面的代码使用了名为「Server Actions」的特性——在前端代码中使用 SQL 语句直接操作数据库。 Next.js 是流行的开源前端框架,其开发商是知名创业公司 Vercel。 Next.js 提供了包括服务器端渲染和为 W

2022-12-12

xxx # 可选值(Owner/Maintainer/Developer/Reporter/Guest) role: Guest gitea: allow-login: user: - xxx organization: - account: xxx # 可选值(admin/member) role: member gitlink: # gitlink暂不支持配置organization allow-login: user: - xxx docker-compose.yml配置示例: # gitee J

2022-05-24

在管理节点上默认启用并提供诸多开箱即用的软件模板:gitea,bytebase, pgadmin, pgweb, postgrest, minio等。 基础设施自我监控:Nginx, ETCD, Consul, Prometheus, Grafana, Loki 自我监控 CMDB升级:兼容性改善,支持Redis集群/Greenplum集群元

2022-08-24

tea 是 Gitea 的 CLI 前端命令行程序,已被 Manjaro 、Arch Linux 等多个 Linux 发行版采用。但网友 Artemis Everfree 在打包 tea 程序的时候,意外发现该程序的多个依赖项都没有明确的开源许可。  举个例子,在使用 Golicense(一个扫

2022-04-15

用户 @Matt Greensmith 晒出一张高达 1.27 亿美金的 GitHub Actions 天价账单,并 @GitHub 质问到底咋回事。 GitHub Action 是 GitHub 于 2018 年推出的一个 CI\CD 服务。该账单显示,Matt 在一个月内使用了大约 160 亿分钟 Actions 服务,换算一

2023-01-09

语义。 { "name": "AllowDeveloperOrIpRange", "effect": "allow", "actions": [ { "type": "all" } ], "condition": { "type": "bool", "bool": { "and": [ { "type": "authenticated" } ], "or": [ { "type": "in", "part": "context.principal.id", "in": [ "developerId" ] }, { "type": "path", "part": "r

2023-01-07

IP区域匹配器。 { "name": "RegionWhitelist", "effect": "deny", "actions": [ { "type": "all" } ], "conditions": [ { "negate": true, "type": "reg", "part": "request.attributes.ipRegion", "pattern": "^中国\\|0\\|(上海|广东省)\\|.*" } ] } 认证 授权 OAuth 建模类图