回顾 GitHub Actions
GitHub Actions 是一种持续集成和持续交付 (CI/CD 平台,可用于自动执行任务、测试和部署。用户可以创建工作流程来构建和测试存储库的每个拉取请求,或将合并的拉取请求部署到生产环境。
GitHub 提供 Linux、Windows 和 macOS 虚拟机来运行工作流程,或者在自有的数据中心或云基础架构中托管运行器。
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
好消息是,经过两年的调研与讨论,我们终于将 Gitea 内置CI/CD系统的开发任务提上了日程。(#13539)
开发进展
https://github.com/go-gitea/gitea/issues/13539
系统由三部分组成:
Gitea Actions 协议的定义和Golang实现
Actions Runner: 基于 nektos/act 实现的任务子系统
在 Gitea 主程序上实现 Runner 任务管理和调度模块
运行截图
尝鲜体验
准备环境
内存:至少 4GB,用于编译 Gitea
Docker:可执行 docker 命令,用于拉取和运行容器
搭建
1.编译运行 Gitea
# 目前可以从 @wolfogre 的开发分支克隆带有 Actions 模块的源代码到本地编译。
git clone https://github.com/wolfogre/gitea.git --branch=feature/bots
cd gitea
编译方法可以参考从源代码安装。这里我们需要准备开发环境 Node.js LTS (nvm instal --lts
和 Golang。
TAGS="bindata sqlite sqlite_unlock_notify" make build
启动 Gitea 主程序。这里先走完初始化步骤,会生成一个配置文件,位于当前目录下的
./custom/conf/app.ini
编辑上述配置文件,打开 Actions 功能。
[actions]
ENABLED = true
重新启动程序:./gitea web
首先编译 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://<your_gitea_instance> --token <my_runner_token> --no-interactive
启动程序
./act_runner daemon
3.为仓库启用 Actions 功能
.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 已经执行并且记录下了运行日志。
6.从 GitHub 文档中了解更多 Actions 用法,同时可以为我们提出改进意见!
🤖 Implement actions
https://github.com/go-gitea/gitea/pull/21937
🔧 GitHub Actions
https://docs.github.com/zh/actions/using-workflows