Skip to content

Commit

Permalink
fix: everything, hopefully
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Jan 28, 2023
1 parent 128460a commit d324e76
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

26 changes: 20 additions & 6 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ export const getRelease = async (
version: string,
githubToken: string
): Promise<Release | null> => {
if (version === 'latest') {
return getLatestRelease(distribution, githubToken);
}
const tag: string = (await resolveVersion(distribution, version)) || version;
core.info(`getting tag ${resolveVersion}...`);
return getReleaseTag(distribution, tag, githubToken);
};

export const getReleaseTag = async (repo: string, tag: string, githubToken: string): Promise<Release> => {
core.info(`Getting tag ${resolveVersion}...`);
return (
await github
.getOctokit(githubToken, {
Expand All @@ -38,17 +41,28 @@ export const getReleaseTag = async (repo: string, tag: string, githubToken: stri
).data as Release;
};

export const getLatestRelease = async (repo: string, githubToken: string): Promise<Release> => {
core.info(`Getting tag latest...`);
return (
await github
.getOctokit(githubToken)
.rest.repos.getLatestRelease({
owner,
repo
})
.catch(error => {
throw new Error(`Cannot get latest release: ${error}`);
})
).data as Release;
};

const resolveVersion = async (distribution: string, version: string): Promise<string | null> => {
const allTags: Array<string> | null = await getAllTags(distribution);
if (!allTags) {
throw new Error(`Cannot download ${distribution} tags`);
}
core.debug(`Found ${allTags.length} tags in total`);

if (version === 'latest' || !goreleaser.isPro(distribution)) {
return semver.maxSatisfying(allTags, version);
}

const cleanTags: Array<string> = allTags.map(tag => cleanTag(tag));
const cleanVersion: string = cleanTag(version);
return semver.maxSatisfying(cleanTags, cleanVersion) + goreleaser.distribSuffix(distribution);
Expand All @@ -62,7 +76,7 @@ const getAllTags = async (distribution: string): Promise<Array<string>> => {
const http: httpm.HttpClient = new httpm.HttpClient('goreleaser-action');
const suffix: string = goreleaser.distribSuffix(distribution);
const url = `https://goreleaser.com/static/releases${suffix}.json`;
core.info(`downloading ${url}`);
core.info(`Downloading ${url}`);
const getTags = http.getJson<Array<GitHubTag>>(url);
return getTags.then(response => {
if (response.result == null) {
Expand Down

0 comments on commit d324e76

Please sign in to comment.