Get the current pushed tag in Github Actions

前端 未结 4 487
别跟我提以往
别跟我提以往 2021-01-31 08:12

Is there a way to access the current tag that has been pushed in a Github Action? In CircleCI you can access this value with the $CIRCLE_TAG variable.

My Wor

4条回答
  •  独厮守ぢ
    2021-01-31 09:00

    As far as I know there is no tag variable. However, it can be extracted from GITHUB_REF which contains the checked out ref, e.g. refs/tags/v1.2.3

    Try this workflow. It creates a new environment variable with the extracted version that you can use in later steps.

    on:
      push:
        tags:
          - 'v*.*.*'
    jobs:
      test:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2
          - name: Set env
            run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
          - name: Test
            run: |
              echo $RELEASE_VERSION
              echo ${{ env.RELEASE_VERSION }}
    

    Alternatively, use set-output:

    on:
      push:
        tags:
          - 'v*.*.*'
    jobs:
      test:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2
          - name: Set output
            id: vars
            run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
          - name: Check output
            env:
              RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
            run: |
              echo $RELEASE_VERSION
              echo ${{ steps.vars.outputs.tag }}
    

提交回复
热议问题