gitea 安装 Renovate Bot 实现自动更新项目软件包依赖
在gitea服务创建Renovate Bot账号
创建一个普通账号,然后申请一个令牌(需要赋予权限),需要的权限如下:
https://docs.renovatebot.com/modules/platform/gitea/
安装renovate
这里以docker的方式安装,方便安装和升级
打开 https://hub.docker.com/r/renovate/renovate ,找到最新的tag
创建docker-compose.yml
文件,示例:
version: '3'
services:
renovate:
image: renovate/renovate:36
container_name: renovate
environment:
RENOVATE_AUTODISCOVER: 'true'
RENOVATE_ENDPOINT: 'https://XXX.com'
RENOVATE_GIT_AUTHOR: 'Development Bot <bot@renovatebot.com>'
RENOVATE_PLATFORM: "gitea"
RENOVATE_TOKEN: "XXX"
GITHUB_COM_TOKEN: 'XXX'
GitHub.com token for release notes
If you are running on any platform except github.com, you should also set the environment variable GITHUB_COM_TOKEN and put the Personal Access Token for github.com in it. This account can be any account on GitHub, and needs only read-only access. It’s used when fetching release notes for repositories in order to increase the hourly API limit. It’s also OK to configure the same as a host rule instead, if you prefer that.
GitHub的token是为了拉取软件的发行说明用的(无token也可以请求GitHub的API,但是次数有限制,使用token可以可以增大次数限制,非GitHub平台的renovate需要GitHub的token才能生成软件的发行说明),创建token时要选择经典token,不需要勾选任何权限(不勾选权限则默认为公开仓库可读权限)
启动
第一次运行执行如下命令,docker compose语法参考:https://docs.docker.com/engine/reference/commandline/compose_up/
docker compose up
看到日志exit code 0就代表没问题
然后需要在自己的项目里将renovate bot加入协作者
再次运行renovate
docker start renovate
此时会renovate bot提交一个增加了renovate.json
文件的pr,然后我们将该pr合并到项目的主分支,这就告诉renovate bot下次可以为该仓库提交软件包依赖更新的pr
定时运行
renovate容器每次执行完就结束了,不会自动执行,我们可以使用crontab来定时启动renovate容器,达到定期监控并更新仓库软件包依赖的目的
crontab定时任务示例(每天早上6点启动renovate容器)(定时任务语法参考:https://crontab.guru/ )
0 6 * * * /usr/bin/docker start renovate
其它
由于我的gitea服务安装的比较早,早期gitea在创建表结构的时候还使用的是utf8字符集,后来换成了utf8mb4,但是表的字符集gitea一直没有自动更新。而renovate在提交pr的时候评论里经常有很多表情符号,这就导致存不进去数据库,此时需要将表的字符集改为utf8mb4,这里我没有手动修改,而是使用了gitea提供的命令,注意在执行之前要先备份数据库
./gitea convert
执行完执行重新启动
./gitea web
此时启动日志可能会有很多警告,大多数是字段类型与代码的定义不完全一致,这个问题gitea文档( https://docs.gitea.com/next/help/faq#warnings-about-struct-defaults-during-database-startup )给了说明,可以不用理会这个警告
参考
https://github.com/renovatebot/renovate
https://www.cnblogs.com/Gitea/p/renovate.html
https://github.com/renovatebot/renovate/blob/main/docs/usage/getting-started/running.md
https://docs.renovatebot.com/self-hosted-configuration/