When publishing a release using the GitHub Action, get the triggered tag as the release number.

Methods a

Get the tag from step, using steps.get_version.elsion.version where needed, where get_version is the ID of step.

name: Release

on:
  push:
    tags:
    - 'v*'

jobs:

  release:
    name: Release
    runs-on: ubuntu-latest
    steps:
    
    - name: Get version
      id: get_version
      run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
    
    - name: Create Release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: The ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: The ${{ steps.get_version.outputs.VERSION }}
        release_name: The ${{ steps.get_version.outputs.VERSION }}
        draft: false
        prerelease: false
Copy the code

Way 2

Use github. Ref directly (trigger condition is tag).

name: Release

on:
  push:
    tags:
    - 'v*'

jobs:
  release:
    name: Create Release
    runs-on: ubuntu-latest
    steps:
    
    - name: Create Release
      id: create_release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: The ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: The ${{ github.ref }}
        release_name: The ${{ github.ref }}
        draft: false
        prerelease: false
Copy the code

conclusion

If you just want to get a tag, the second method is the easiest, but note that github. Of course, mode 1 serves as a usage reference and can be used in scenarios where output values are required.

Original link: k8scat.com/posts/githu…