Github:在文件中添加版本号

问题描述 投票:0回答:1

假设两个开发人员正在处理不同的 PR。他们各自的 PR 包含相同的文件,其中有版本号。作为 PR 的一部分,两位开发者都打算提高这个版本号。如何确保第二个合并 PR 进行开发的人,即使只晚于第一个开发人员一秒钟,相对于第一个开发人员的版本号会增加版本号? PR 的合并是在 GitHub 中完成的。

版本是开放的api规范号。存储库中实际上有几个这样的文档。请注意,在第一个 PR 之后合并的 PR 中不会出现合并冲突,因为两个开发人员都会使用相同的版本。

我想要什么:

  1. 开发者 1 首次提交:1.123.0
  2. Dev 2 的第二次提交:1.124.0

实际发生了什么:

  1. 开发者 1 首次提交:1.123.0
  2. Dev 2 的第二次提交:1.123.0
git github version-control pull-request
1个回答
0
投票

两家开发人员都打算在其 PR 中提高此版本号。

他们不应该这样做。
当 PR 被接受并合并到 main 时,只有 GitHub 工作流程可以更新 API 版本,如此示例所示。

类似:

name: Auto Increment OpenAPI Version

on:
  pull_request:
    branches:
      - main
    types: [closed]

jobs:
  increment-version:
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Increment OpenAPI Spec Version
        run: |
          # Script to increment version numbers in OpenAPI documents
          ./increment-openapi-version.sh
          git config --local user.email "[email protected]"
          git config --local user.name "GitHub Action"
          git commit -am "Automatically bump OpenAPI spec version"
          git push

您可以尝试使用 GitHub Action“增量语义版本”

name: Auto Increment OpenAPI Version

on:
  pull_request:
    branches:
      - main
    types: [closed]

jobs:
  increment-version:
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Determine Current Version
        id: get_version
        run: |
          # Add your logic here to determine the current version from your OpenAPI document
          # For example, using grep or another tool to extract the version from a file
          CURRENT_VERSION=$(cat path/to/your/version/file.txt)
          echo "::set-output name=CURRENT_VERSION::$CURRENT_VERSION"

      - name: Bump release version
        id: bump_version
        uses: christian-draeger/[email protected]
        with:
          current-version: ${{ steps.get_version.outputs.CURRENT_VERSION }}
          version-fragment: 'feature' # Adjust this based on your versioning scheme

      - name: Update OpenAPI Document Version
        run: |
          # Add your script/command here to update the OpenAPI document with the new version
          NEW_VERSION=${{ steps.bump_version.outputs.next-version }}
          # Example: sed -i 's/oldversion/$NEW_VERSION/g' path/to/your/version/file.txt
          echo "Updated version to $NEW_VERSION"

      - name: Commit and Push the New Version
        run: |
          git config --local user.email "[email protected]"
          git config --local user.name "GitHub Action"
          git add path/to/your/version/file.txt # Update to include the actual file you modified
          git commit -m "Automatically bump OpenAPI spec version to ${{ steps.bump_version.outputs.next-version }}"
          git push
© www.soinside.com 2019 - 2024. All rights reserved.