I’ve release two tags, 0.1.0
and then 0.0.1
. The latest release tag is 0.1.0
.
How do I check inside the GitHub Action if the workflow was dispatched by the latest release?
name: Test
on:
workflow_dispatch:
branches:
- main
release:
types: [published]
jobs:
test:
name: Test
runs-on: ubuntu-20.04
steps:
- run: echo ${{ github.ref_name }}
${{ github.ref_name }} returns the tag version 0.1.0
or 0.0.1
, I want to tag Docker images in action the same as GitHub: as image:latest
only if the action was dispatched by 0.1.0
, 0.1.0
is the latest even if 0.0.1
was dispatched later like displayed in the screenshot below:
2
Answers
Unfortunately, github context doesn’t provide this information.
As a walkaround you can use git command to retrieve the latest version:
and then compare it to the current tag in the github actions context:
example:
To retrieve the Github release that is marked as
latest
by the maintainers (does not have to be chronologically or alphabetically the latest created git tag):This uses the
tag_name
attribute in the REST API response (docs)