小编Sri*_*Sri的帖子

是否可以通过 GitHub Actions 在合并过程中更新文件,而无需创建第二次提交?

目前,我正在尝试使用 GitHub Actions 将应用程序的凹凸版本自动化,作为 PR 合并的一部分。有一个自定义脚本可以识别应用程序的当前版本和 PR 附带的标签,并在存储版本号的文件上相应地更改主要|次要|补丁版本。重要的是,版本碰撞仅在合并 PR 时发生,并且作为 GitHub Actions 的一部分,因为它有助于避免版本文件中的合并冲突,并消除了手动碰撞版本的方式。

下面给出了 GitHub Actions 代码片段。

jobs:
  release:
    # Skip on Pull Request Close event.
    if: "!(github.event_name == 'pull_request' && !github.event.pull_request.merged)"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.ref }}

      - id: bumpversion
        if: github.event.pull_request.merged
        env:
          PR_LABELS: ${{ toJson(github.event.pull_request.labels) }}
        run: bash .github/scripts/bump_version.sh -l "${PR_LABELS}"
Run Code Online (Sandbox Code Playgroud)

bump_version.sh脚本具有下面给出的函数,该函数可以进行版本更改,然后将其推送到分支main

  git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"

  echo "commiting the version bump changes..."
  git add .
  git commit -m "Bump …
Run Code Online (Sandbox Code Playgroud)

versioning github pull-request semantic-versioning github-actions

7
推荐指数
1
解决办法
2326
查看次数