1

体验 Gitea Actions - Gitea

 1 year ago
source link: https://www.cnblogs.com/Gitea/p/actions.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

即将推出的 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
  • Drone
  • Ghorg
  • gickup
  • Jenkins
  • 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://<your_gitea_instance> --token <my_runner_token> --no-interactive
./act_runner daemon

3.为仓库启用 Actions 功能

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

2956540-20221216190134436-2076710159.png

启用 Actions 功能

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

2956540-20221216190004464-1714128000.png

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 已经执行并且记录下了运行日志。

2956540-20221216185806634-746050733.png

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

2956540-20221216190105074-1283893610.png

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

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

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

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK