dsaltares / fetch-gh-release-asset

Github Action to download an asset from a Github release
MIT License
114 stars 70 forks source link

Version doesn't actually default to latest #50

Closed elibosley closed 1 year ago

elibosley commented 2 years ago

In the readme it says:

# version

The release version to fetch from in the form tags/<tag_name> or <release_id>. Defaults to latest.

But from reading the code and my own testing it doesn't actually default to using latest. Maybe just update readme to say that latest is an option but not that it defaults to that?

Btw I love this workflow thank you for making this!

lumpidu commented 1 year ago

Yes, latest is totally misleading! Because one assumes, that the workflow will download the latest release in a timely meaning and not that there needs to be a release version with the name latest. The default value doesn't make much sense, because there isn't necessarily a release version latest. The documentation should be made clearer.

dsaltares commented 1 year ago

I think the problem is that the value of version doesn't actually default to latest:

const version = core.getInput('version', { required: false });

const getRelease = (
  octokit: ReturnType<typeof github.getOctokit>,
  { owner, repo, version }: GetReleaseOptions
) => {
  const tagsMatch = version.match(/^tags\/(.*)$/);
  if (version === 'latest') {
    return octokit.rest.repos.getLatestRelease({ owner, repo });
  } else if (tagsMatch !== null && tagsMatch[1]) {
    return octokit.rest.repos.getReleaseByTag({
      owner,
      repo,
      tag: tagsMatch[1],
    });
  } else {
    return octokit.rest.repos.getRelease({
      owner,
      repo,
      release_id: Math.trunc(Number(version)),
    });
  }
};

By changing it to

const version = core.getInput('version', { required: false }) || 'latest';

It should actually fetch the latest (chronologically speaking) version released when the version parameter is not present.

dsaltares commented 1 year ago

This is now fixed if you point your job to master.

dsaltares commented 1 year ago

New version with this fix released https://github.com/dsaltares/fetch-gh-release-asset/releases/tag/1.1.1