在Github Actions中获取当前的推送标签
是否可以访问在Github Action中推送的当前标签?在CircleCI中,您可以使用 $ CIRCLE_TAG
变量来访问此值。
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.
我的工作流程yaml由标签触发像这样:
My Workflow yaml is being triggered by a tag like so:
on:
push:
tags:
- 'v*.*.*'
我想在以后的工作流程中使用该版本号作为文件路径。
And I want to use that version number as a file path later on in the workflow.
我已将基于所选答案的最终解决方案作为下面的另一个答案: https://*.com/a/58195087/756514
I have included my final solution based on the chosen answer as another answer below: https://*.com/a/58195087/756514
据我所知没有标签变量。但是,它可以从 GITHUB_REF
中提取,其中包含已签出的引用,例如 refs / tags / v1.2.3
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@v1
- name: Set env
run: echo ::set-env name=RELEASE_VERSION::${GITHUB_REF#refs/*/}
- name: Test
run: |
echo $RELEASE_VERSION
echo ${{ env.RELEASE_VERSION }}
,使用 set-output
:
on:
push:
tags:
- 'v*.*.*'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- 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 }}