【问题标题】:Github action increment version on push to main推送到主服务器时的 Github 操作增量版本
【发布时间】:2021-11-19 09:41:36
【问题描述】:

我想在 GitHub 操作中使用纯解决方案来增加包的版本。我不想使用 GitHub 市场中的任何现有操作,例如“gh-action-bump-version "。我有这个工作流,会增加版本并创建标签。

name: Version Increment

on:
  push:
    branches:
      - main
    tags-ignore:
      - v*

jobs:
  version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.ACCESS_TOKEN }}
      - run: git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
      - run: git config user.name "$GITHUB_ACTOR"
      - run: npm version minor -m "v%s"
      - run: VERSION=$(node -p "require('./package.json').version")
      - run: git tag ${VERSION}
      - run: git push origin --tags
      - run: git push origin --follow-tags

它有效,但由于最后一行,它也会导致动作循环运行。我知道我可以使用像“[RELEASE]”这样的自定义消息并在那里放置一个“if”条件并跳过这些提交。但我的问题是,有没有更好的解决方案可以从这个操作中跳过这些提交并且不使用“if”条件?因为“tags-ignore”显然不起作用。

【问题讨论】:

  • tags-ignore 不起作用,因为您告诉操作在推送到 master 的提交上运行,而 tags-ignore 仅在您让操作在推送的标签上运行时才有效。

标签: github-actions


【解决方案1】:

所以我找到了几个解决方案。第一个是您可以将“[跳过操作]”添加到您的提交消息中,并且该提交将跳过应该在提交中运行的任何 github 操作。第二种是使用带有访问令牌的存储库地址。

这对我来说效果很好:

name: Version Increment

on:
  push:
    branches:
      - main

jobs:
  version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
      - run: git config user.name "$GITHUB_ACTOR"
      - run: npm version minor -m "v%s"
      - run: VERSION=$(node -p "require('./package.json').version")
      - run: git tag ${VERSION}
      - run: git push "https://$GITHUB_ACTOR:${{ secrets.ACCESS_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" --follow-tags
      - run: git push "https://$GITHUB_ACTOR:${{ secrets.ACCESS_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" --tags

【讨论】:

    猜你喜欢
    • 2020-11-22
    • 2013-06-26
    • 1970-01-01
    • 2020-01-15
    • 2011-11-10
    • 1970-01-01
    • 2020-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多