简体   繁体   English

如何在 Github 操作中对版本进行版本控制

[英]How to versioning releases in Github Actions

Is there a way to publish releases on GitHub using Actions with custom version numbers?有没有办法使用带有自定义版本号的ActionsGitHub上发布版本? Currently, I'm using github.run_number provided by GitHub Context and as mentioned in the docs:目前,我正在使用github.run_numberGitHub 上下文提供,如文档中所述:

github.run_number (string) - A unique number for each run 
of a particular workflow in a repository. This number begins
at 1 for the workflow's first run, and increments with each new run.

Not every run of my workflow creates a release (eg when a workflow fails), resulting in inconsistent version numbers.并非我的工作流的每次运行都会创建一个版本(例如,当工作流失败时),从而导致版本号不一致。 I've created a demo repository and as you can see, the release numbers are ...38,39,40,47,49 .我创建了一个演示存储库,如您所见,版本号为...38,39,40,47,49 I didn't find any solution for this in GitHub Actions Docs .我没有在GitHub Actions Docs中找到任何解决方案。

I want to have consistent incrementally growing version numbers or even a vxx structure if it's possible.如果可能的话,我希望拥有一致的递增版本号,甚至是vxx结构。

My complete workflow can be found here , my release-project job is:我的完整工作流程可以在这里找到,我的release-project工作是:

...previous jobs: build, test, deploy...
release-project:
    name: Release project
    needs: deploy-project
    ...
      - name: Create release
        id: create_release_id
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.run_number }}
          release_name: Release ${{ github.run_number }}
      - name: Upload release asset
        id: upload-release-asset
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ steps.create_release_id.outputs.upload_url }}
          asset_path: ./project.zip
          asset_name: project-v${{ github.run_number }}.zip
          asset_content_type: application/zip

I would suggest not relying on run_number and using the latest tag from the repo to generate the next version based on it.我建议不要依赖run_number并使用 repo 中的最新标签来生成基于它的下一个版本。 For example, you can use the Get Latest Tag , Next SemVers , and Next Monotonic Release version GH Actions.例如,您可以使用Get Latest TagNext SemVersNext Monotonic Release version GH Actions。

Semantic versioning workflow:语义版本控制工作流程:

...

jobs:
  test-next-release:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0 # required for github-action-get-previous-tag

      - name: Get previous tag
        id: previoustag
        uses: 'WyriHaximus/github-action-get-previous-tag@v1'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Get next minor version
        id: semver
        uses: 'WyriHaximus/github-action-next-semvers@v1'
        with:
          version: ${{ steps.previoustag.outputs.tag }}

      - name: Create release
        id: create_release_id
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ steps.semver.outputs.patch }}
          release_name: Release ${{ steps.semver.outputs.patch }}

Consecutive numbers versioning workflow:连续数字版本控制工作流程:

...

jobs:
  test-next-release-custom:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0 # required for github-action-get-previous-tag

      - name: Get Previous tag
        id: previoustag
        uses: 'WyriHaximus/github-action-get-previous-tag@v1'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          
      - name: Get next version
        id: next
        uses: 'WyriHaximus/github-action-next-release-version@1.0.0'
        with:
          version: ${{ steps.previoustag.outputs.tag }}

      - name: Create release
        id: create_release_id
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ steps.next.outputs.version }}
          release_name: Release ${{ steps.next.outputs.version }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM