目前,我正在尝试使用 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