Renovate工作流无法检测.pre-commit-config.yaml进行版本更新
问题描述
我配置了Renovate工作流扫描仓库版本更新,它能正常处理.github目录文件、Terraform文件的版本更新并创建PR,但无法检测或更新根目录下.pre-commit-config.yaml文件中的ghcr.io/super-linter/super-linter:slim-v7.4.0版本。之前尝试Dependabot也遇到同样问题,它能处理工作流文件,但无法处理.pre-commit-config.yaml。
Renovate工作流配置
# .github/workflows/renovate.yml name: Renovate on: schedule: - cron: "0 18 * * 6" workflow_dispatch: permissions: contents: read pull-requests: write id-token: write jobs: renovate: runs-on: ubuntu-latest permissions: contents: write pull-requests: write steps: - name: Checkout uses: actions/checkout@v4 - name: Generate token uses: actions/create-github-app-token@v1 id: generate-token with: app-id: ${{ secrets.GH_RUNNER_IAC_APP_ID }} owner: ${{ github.repository_owner }} private-key: ${{ secrets.GH_RUNNER_APP_PEM }} - name: Self-hosted Renovate uses: renovatebot/github-action@v43.0.8 with: token: ${{ steps.generate-token.outputs.token }} env: RENOVATE_REPOSITORIES: ${{ github.repository }} RENOVATE_PLATFORM: github LOG_LEVEL: debug
renovate.json配置
{ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": ["config:recommended"], "baseBranches": ["main", "709/dcloud_core_refactor", "dev"], "enabledManagers": ["custom.regex"], "customManagers": [ { "customType": "regex", "description": "Track super-linter Docker image in pre-commit script", "managerFilePatterns": [".pre-commit-config.yaml"], "matchStrings": [ "ghcr\.io/super-linter/super-linter:(?:slim-)?(?<currentValue>v\d\.\d\.\d)" ], "depNameTemplate": "super-linter/super-linter", "datasourceTemplate": "docker" } ], "packageRules": [ { "description": "Group all super-linter updates into a single PR", "matchDepNames": ["super-linter/super-linter"], "groupName": "super-linter" }, { "description": "Automerge minor updates for super-linter", "matchDepNames": ["super-linter/super-linter"], "matchUpdateTypes": ["minor", "patch"], "automerge": true, "automergeType": "branch" } ] }
.pre-commit-config.yaml配置(仓库根目录)
# .pre-commit-config.yaml --- default_install_hook_types: - pre-commit - commit-msg repos: - repo: https://github.com/commitizen-tools/commitizen rev: v4.8.3 hooks: - id: commitizen - repo: local hooks: - id: docker-super-linter name: "Run Super-linter workflow locally with Docker" description: "Uses Docker to run the CI linter workflow on local files." entry: /bin/bash args: - -c - | set -euo pipefail echo "--- Running Super-Linter via Docker ---" docker run --rm --platform linux/amd64 \ -e RUN_LOCAL=true \ -e LINTER_RULES_PATH=".github/linters" \ -e VALIDATE_TERRAFORM_TERRASCAN=false \ -e VALIDATE_ALL_CODEBASE=false \ -e DEFAULT_BRANCH=main \ -v "$(pwd)":/tmp/lint \ ghcr.io/super-linter/super-linter:slim-v7.4.0 language: script pass_filenames: false always_run: true stages: [pre-commit]
问题分析与解决方案
核心问题:正则表达式匹配错误
当前customManagers中的正则表达式只捕获了v7.4.0作为版本值,但实际镜像标签是slim-v7.4.0。Renovate用v7.4.0去Docker数据源查找版本时,无法匹配到对应的slim-vX.X.X标签,导致无法检测更新。
修复步骤
修正正则表达式:
将matchStrings中的正则修改为捕获完整的标签内容,包括slim-前缀:"matchStrings": [ "ghcr\.io/super-linter/super-linter:(?<currentValue>(?:slim-)?v\\d\\.\\d\\.\\d)" ]这样
currentValue会完整捕获slim-v7.4.0或v7.4.0,确保Renovate能正确匹配Docker镜像的版本标签。恢复默认管理器(可选):
当前enabledManagers仅设置了custom.regex,会覆盖config:recommended中的默认管理器(比如github-actions、terraform)。如果需要继续处理这些类型的文件,需要把它们添加到enabledManagers中:"enabledManagers": ["custom.regex", "github-actions", "terraform"]验证配置:
运行Renovate工作流(可通过workflow_dispatch手动触发),查看debug日志确认是否成功匹配到.pre-commit-config.yaml中的Super-linter版本,并生成对应的更新PR。
内容的提问来源于stack exchange,提问作者Gowthamakanthan Gopal

