A tiny GitHub action to fetch the latest GitHub Release for a given repository. Originally forked from https://github.com/gregziegan/fetch-latest-release on 2023/04/27.
| Parameter | Description | Required | Default |
|---|---|---|---|
github_token |
A Github token, usually ${{ github.token }}. |
N | ${{ github.token }} |
repo_path |
Provide a "owner/repo" string for fetching from a different repo. If not provided the repository the composite action is ran in will be used. | N | The current repo |
urlThe HTTP URL for this releaseassets_url: The REST API HTTP URL for this release's assetsupload_url: The REST API HTTP URL for uploading to this releasehtml_url: The REST API HTTP URL for this releaseid: ''node_id: The unique identifier for accessing this release in the GraphQL APItag_name: The name of the release's Git tagtarget_commitish: ''name: The title of the releasebody: The description of the releasedraft: Whether or not the release is a draftprerelease: Whether or not the release is a prereleaseauthor_id: ''author_node_id: The unique identifier for accessing this release's author in the GraphQL APIauthor_url: The REST API HTTP URL for this release's authorauthor_login: The username used to login.author_html_url: The HTTP URL for this release's authorauthor_type: ''author_site_admin: Whether or not this user is a site administrator
Example 1: Fetch the latest release from the repository this composite action was ran from.
steps:
- id: fetch-latest-github-release
uses: cityoflosangeles/fetch-latest-github-release@{latest-release} # ex. v1, v2, v3 etc. See https://github.com/CityOfLosAngeles/fetch-latest-github-release/releasesExample 2: Fetch the latest release from another repository. Make sure the generated token passed in has the appropriate permissions.
steps:
- id: fetch-latest-github-release
uses: cityoflosangeles/fetch-latest-github-release@{latest-release} # ex. v1, v2, v3 etc. See https://github.com/CityOfLosAngeles/fetch-latest-github-release/releases
with:
github_token: ${{ github.token }}
repo_path: 'user/repo-name'You will retrieve the output from subsequent GitHub Actions steps like:
- name: 'Obtain Latest Tag Name & Run a Cool Process Against It'
uses: 'hiimbex/some-cool-action@v1'
with:
version: ${{ steps.fetch-latest-github-release.outputs.tag_name }}steps.fetch-latest-github-release.outputs.tag_name is important, you can fetch
other outputs that are defined in action.yml.
To run the tests locally, run npm test. The unit tests have been updated to
work with the latest GitHub Actions dependencies using proper mocking strategies
for ESM modules.
This project uses Vercel NCC to bundle the GitHub Action into a single distributable file.
To build the action, run:
npm run build
This will:
- Use NCC to bundle all dependencies from
src/index.tsinto a single file atdist/index.cjs. - Generate a source map for debugging.
- The output file is
dist/index.cjs(CommonJS format). - You do not need to ship
node_moduleswith your action; everything is bundled. - If you change the source code, always re-run
npm run buildbefore committing or releasing.
"scripts": {
"build": "ncc build src/index.ts -o dist --source-map && mv dist/index.js dist/index.cjs",
...
}
In your action.yml, set the entrypoint to dist/index.cjs:
runs:
using: 'node20'
main: 'dist/index.cjs'