[2025-06-26] 添加GiteaRunner Host 模式配置教程
All checks were successful
Publish to Confluence / confluence (push) Successful in 15s

This commit is contained in:
liuxiaohua 2025-06-26 16:29:13 +08:00
parent b0bb0a3568
commit 09b97b7e95

View File

@ -0,0 +1,221 @@
# GiteaRunner Host 模式配置教程
## 下载二进制文件
- https://gitea.com/gitea/act_runner/releases
- 这边下载 `act_runner-0.2.12-linux-amd64`
- 配置 `act_runner`
```shell
#- 重命名
mv act_runner-0.2.12-linux-amd64 act_runner`
#- 授予执行权限
chmod +x act_runner
```
## 配置
### 生成配置文件
```shell
./act_runner generate-config > config.yaml
```
### 修改配置文件
#### 修改下面的配置
```yaml
runner:
labels:
#- 添加
- "linux-ubuntu-24.04:host"
host:
#- 不填写会提示文件找不到
workdir_parent: /.cache/act
```
## 编写启动脚本
### 启动脚本内容
```shell
#!/bin/bash
/${path}/act_runner register --no-interactive --instance ${gitea_url} --token ${runner_token} --name host-runner --labels host-runner
echo register
/${path}/act_runner daemon --config /${path}/config.yaml
```
- ${path}: act_runner 所在目录
- ${gitea_url}: gitea 访问地址
- ${runner_token}: gitea 获取到的 runner token
### 配置启动脚本执行权限
```shell
chmod +x register.sh
```
## 配置开机启动
```shell
vi /etc/systemd/system/gitea_runner.service
#- 填入下面的内容
[Unit]
#- 服务名称,可自定义
Description = gitlab runner host server
After = network.target syslog.target
Wants = network.target
[Service]
Type = simple
#- 启动frps的命令需修改为您的frps的安装路径
ExecStart = /${path}/register.sh
[Install]
WantedBy = multi-user.target
```
- ${path}: register.sh 所在文件目录
## 启动
```shell
#- 配置开机启动
systemctl enable gitea_runner.service
#- 启动服务
systemctl start gitea_runner.service
#- 重启
systemctl restart gitea_runner.service
#- 停止
systemctl stop gitea_runner.service
#- 查看状态
systemctl status gitea_runner.service
```
## 安装 Git
```shell
apt install git
```
## 配置Markmarkdown to confluence
### Mark 下载
- https://github.com/kovetskiy/mark/releases
- 这边使用的是 `mark_Linux_x86_64.tar.gz` 14.1.0 版本
### 解压到指定目录
```shell
tar -zxvf mark_Linux_x86_64.tar.gz
chmod +x mark
```
## 配置 Gitea Workflow
```yaml
name: Publish to Confluence
on:
push:
branches: [ master ]
#- paths:
#- - '**'
#- - '!.gitignore'
#- - '!README.md'
#- workflow_dispatch: # 允许手动触发工作流
#- schedule:
#- # 每天晚六点十分执行一次
#- - cron: '10 10 * * *'
env:
SEPARATOR: "," #- 定义多文件分割符
START_PREFIX: "<!--" #- 定义需要同步的文件
HOME: ./.git #- 定义 git 工作目录
jobs:
confluence:
runs-on: linux-ubuntu-24.04
steps:
# 检出文件
- uses: https://texous.cn/actions/checkout@v4
with:
fetch-depth: 0
- name: Print current path
run: |
pwd
ls
# 获取变更的文件
- name: Get changed files
id: changed-markdown-files
uses: https://texous.cn/actions/changed-files@v44.5.5
with:
files: |
**.md
**.png
files_ignore: |
**.tpl.md
quotepath: false
separator: ${{env.SEPARATOR}}
old_new_files_separator: ";"
# 打印所有变更的文件
- name: Print all changed files
if: steps.changed-markdown-files.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-markdown-files.outputs.all_changed_files }}
run: |
IFS=${SEPARATOR}
for file in ${ALL_CHANGED_FILES}; do
echo "$file was changed, realfile $(echo $file | tr -d '\\')"
done
# 编译以及发布到
- name: Mark and to confluence
if: steps.changed-markdown-files.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-markdown-files.outputs.all_changed_files }}
MARK_PASS: ${{ secrets.ATLASSIAN_API_TOKEN }}
MARK_URL: ${{ secrets.ATLASSIAN_BASE_URL }}
run: |
IFS=${SEPARATOR}
for file in ${ALL_CHANGED_FILES}; do
if [[ $(head -n 1 $(echo $file | tr -d '\\')) =~ ^$START_PREFIX ]]; then
export temp_path=$(echo $file | tr -d '\\')
export temp_filename=${temp_path##*/}
export temp_filename=${temp_filename%.*}
export temp_filename=${temp_filename%.*}
echo "file: $temp_path, filename: $temp_filename"
# 打印文件第一行信息
head -n 1 $(echo $file | tr -d '\\')
# 配置图片大小为 750
# sed -i -E 's/(.*\!\[.*\]\(.*\))([ ]*<\!\-\-[ ]*width=[0-9]*[ ]*\-\->)*/\1<!-- width=750 -->/g' $temp_path
# path 替换
# sed -i -E 's/(.*\!\[.*\]\([ \t]*([a-zA-Z]\:)?(\.*(\/|\\))?([^:\r\n\t\!]*\.[a-zA-Z]+)[ \t]*\))([ ]*<\!\-\-[ \t]*width=[0-9]*[ \t]*\-\->)*/\1<!-- width-attach=750 -->/g' $temp_path
# url 替换
sed -i -E 's/(.*\!\[.*\]\([ \t]*(http(s)?:\/\/)([^:\r\n\t\!]*(\.[a-zA-Z]+)?)[ \t]*\))([ ]*<\!\-\-[ \t]*width=[0-9]*[ \t]*\-\->)*/\1<!-- width=750 -->/g' $temp_path
# 不支持的代码块替换
sed -i -E 's/(.*)(```(dockerfile|json|toml|properties))(.*)/\1```shell\4/g' $temp_path
# 标题添加锚点
sed -i -E 's/([#]+[ ]+)(.*)/\1\2 :anchor(\2):/g' $temp_path
sed -i -E "s@(\[.*\])(\(#)(.*)(\))@\1\2id-$(echo $temp_filename | tr -d '-')-\3\4@g" $temp_path
# 构建及发布
/usr/local/programs/gitea/gitea_runner_host/mark --ci --log-level trace --include-path $(pwd) -p $MARK_PASS -b $MARK_URL -f $temp_path || exit 1;
else
echo "$temp_path not config metadata info, ignore file"
fi
done
```
- 配置Confluence相关信息
- 在对应的仓库中配置密钥
- ${{ secrets.ATLASSIAN_API_TOKEN }}
- ${{ secrets.ATLASSIAN_BASE_URL }}