You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions推送标签未触发及正则模式报错问题排查

问题:GitHub Actions标签触发与正则表达式错误排查

背景

我有一个需要基于标签进行发布的项目,为此编写了如下GitHub Actions YAML配置文件:

name: publish open-electrons-templates

on:
  push:
    # 匹配 refs/tags 的模式序列
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z]*'
  release:
    types: [ created ]

env:
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
  publish:
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/v')
    steps:
      - name: checkout
        uses: actions/checkout@v3

      - name: capture changelog
        id: changelog
        uses: metcalfc/changelog-generator@v4.0.1
        with:
          myToken: ${{ secrets.GITHUB_TOKEN }}

      - name: sbt ci-publish-github
        run: sbt compile publish

      - name: ci-release-github
        id: create-release
        uses: actions/create-release@latest
        with:
          allowUpdates: true
          tag_name: ${{ github.ref }}
          release_name: Release ${{ github.ref }}
          body: |
            ## What's Changed
            ${{ steps.changelog.outputs.changelog }}
          draft: false
          prerelease: false

我执行了以下带注释的标签操作:

git tag -a v2.2.2 -m "Your comments" // 创建带注释的标签
git push origin --tags               // 推送标签到远程仓库

原本期望GitHub Actions会触发流水线,但实际并未触发,且不知如何调试原因。

修改正则后的报错

之后我将标签匹配的正则表达式修改为:

v[0-9]+.[0-9]+.[0-9](?:[+-[a-zA-Z]*])?

修改后流水线似乎触发了,但随即报错:

push event contained invalid tags patterns: the following globs were invalid: v[0-9]+.[0-9]+.[0-9](?:[+-[a-zA-Z]*])?

这个正则看起来是有效的,应该能匹配我需要的如下格式标签:

v0.0.1
v0.0.1-SNAPSHOT
v0.0.1-BETA
v0.0.1-RC

请问我的正则表达式存在什么问题?


内容的提问来源于stack exchange,提问作者joesan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 07:10:28