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

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

有没有办法使用

GitHub
和自定义版本号在
Actions
上发布版本?目前,我正在使用
GitHub Context
提供的 github.run_number 以及文档中提到的:

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.

并非工作流程的每次运行都会创建版本(例如,当工作流程失败时),从而导致版本号不一致。我创建了一个演示存储库,如您所见,版本号是

...38,39,40,47,49
。我在 GitHub Actions Docs 中没有找到任何解决方案。

如果可能的话,我希望拥有一致的增量增长版本号,甚至是

v.x.x
结构。

我的完整工作流程可以在这里找到,我的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
    
github continuous-integration github-actions continuous-deployment
2个回答
3
投票
我建议不要依赖

run_number

 并使用存储库中的 
latest 标签 来基于它生成下一个版本。例如,您可以使用 获取最新标签Next SemVersNext Monotonic Release 版本 GH 操作。

语义版本控制工作流程:

... 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 }}

连续数字版本控制工作流程:

... 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/[email protected]' 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 }}
    

0
投票
env: # TO DETERMINE WHAT VERSION INCREASE YOU SHOULD DO WE USE THIS CONDITITION ISMASTER: ${{ github.ref == 'refs/heads/master' }} jobs: RELEASE: runs-on: - self-hosted #or whatever you'd like outputs: VERSIONLATEST: ${{ steps.tag_version.outputs.new_tag }} #IN MY SITUATION I NEED THE VERSIONLATEST IN A DIFFERENT WORKFLOW SO I OUTPUT IT HERE steps: - name: Push Tag id: tag_version uses: mathieudutour/[email protected] if: ${{ success() }} with: github_token: ${{ secrets.GITHUB_TOKEN }} default_bump: ${{ env.ISMASTER == 'true' && 'major' || 'minor' }} #DETERMINE THE VERSION INCREASE - name: Create a GitHub release uses: ncipollo/release-action@v1 if: ${{ success() && env.ISMASTER == 'true' }} with: tag: ${{ steps.tag_version.outputs.new_tag }} #the new version we received from previous step name: Release ${{ steps.tag_version.outputs.new_tag }} body: ${{ steps.tag_version.outputs.changelog }} artifacts: ./release_items #ARTIFACTS I SAFED ON MY LINUX MACHINE THAT I WILL UPLOAD TO GITHUB RELEASES ON TOP OF THE SRC CODE.
    
© www.soinside.com 2019 - 2024. All rights reserved.