Checkout with code from the latest release #25199
-
I’ve built a workflow that is triggered by calling GitHub API. The idea is to deploy the latest release to FTP server on demand.
above code works great, the problem is that it will always deploy latest code from my master branch. How can I specify that I want to deploy code from the latest release? I’m always creating a tag when I create a release, so I’d like to be able to do a checkout for the latest tag or release. Is this possible? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
You could trigger when a released is published and then checkout would be the ref of the published release.
|
Beta Was this translation helpful? Give feedback.
-
Hi @misiu , You can specify the ‘tag’ value in the ‘actions/checkout’ args, code sample as below:
It will checkout the code which tagged with v1.1.9. Please refer to the usage of ‘actions/checkout’ for more details. Besides, you can use rest api to get the latest release, parse the release tagname to the ‘ref’ value then. Code sample as below, it will automatically get the latest release tag and checkout the release code:
Thanks. |
Beta Was this translation helpful? Give feedback.
-
I’ve tried your code, and it works for public repo, but I have a private repo. How should I modify curl request to pass authentication token? when I do a request with Postman (and pass token in the header) I get the correct response. My tag looks like this: “2020-03-18-05” Got it. I had to add:
|
Beta Was this translation helpful? Give feedback.
-
Or you can use this action https://github.com/marketplace/actions/github-script - uses: actions/github-script@v6
id: get-release
with:
# result-encoding: string
retries: 3
script: |
if (${{ startsWith(github.event.inputs.ref, 'v') }}) {
return github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: "${{ github.event.inputs.ref }}"
})
} else {
return github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo
})
} |
Beta Was this translation helpful? Give feedback.
Hi @misiu ,
You can specify the ‘tag’ value in the ‘actions/checkout’ args, code sample as below:
It will checkout the code which tagged with v1.1.9. Please refer to the usage of ‘actions/checkout’ for more details.
Besides, you can use rest api to get the latest release, parse the release tagname to the ‘ref’ value then. Code sample as below, it will automatically get the latest release tag and checkout the release code: