mirror of
https://github.com/goreleaser/goreleaser-action.git
synced 2026-05-20 17:31:54 +00:00
feat: support downloading goreleaser pro (#284)
This commit is contained in:
parent
a3b2f49e7c
commit
70eb4e573c
9 changed files with 140 additions and 47 deletions
|
|
@ -1,36 +1,44 @@
|
|||
import * as httpm from '@actions/http-client';
|
||||
import * as core from '@actions/core';
|
||||
import * as semver from 'semver';
|
||||
import * as pro from './pro';
|
||||
|
||||
export interface GitHubRelease {
|
||||
id: number;
|
||||
tag_name: string;
|
||||
}
|
||||
|
||||
export const getRelease = async (version: string): Promise<GitHubRelease | null> => {
|
||||
const resolvedVersion: string = (await resolveVersion(version)) || version;
|
||||
const url: string = `https://github.com/goreleaser/goreleaser/releases/${resolvedVersion}`;
|
||||
export const getRelease = async (distribution: string, version: string): Promise<GitHubRelease | null> => {
|
||||
const resolvedVersion: string = (await resolveVersion(distribution, version)) || version;
|
||||
const url: string = `https://github.com/goreleaser/${distribution}/releases/${resolvedVersion}`;
|
||||
const http: httpm.HttpClient = new httpm.HttpClient('goreleaser-action');
|
||||
return (await http.getJson<GitHubRelease>(url)).result;
|
||||
};
|
||||
|
||||
const resolveVersion = async (version: string): Promise<string | null> => {
|
||||
const allTags: Array<string> | null = await getAllTags();
|
||||
const resolveVersion = async (distribution: string, version: string): Promise<string | null> => {
|
||||
const allTags: Array<string> | null = await getAllTags(distribution);
|
||||
if (!allTags) {
|
||||
throw new Error(`Cannot find GoReleaser tags`);
|
||||
}
|
||||
core.debug(`Found ${allTags.length} tags in total`);
|
||||
|
||||
return semver.maxSatisfying(allTags, version);
|
||||
if (version === 'latest' || !pro.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) + pro.suffix(distribution);
|
||||
};
|
||||
|
||||
interface GitHubTag {
|
||||
tag_name: string;
|
||||
}
|
||||
|
||||
const getAllTags = async (): Promise<Array<string>> => {
|
||||
const getAllTags = async (distribution: string): Promise<Array<string>> => {
|
||||
const http: httpm.HttpClient = new httpm.HttpClient('goreleaser-action');
|
||||
const url: string = `https://goreleaser.com/static/releases.json`;
|
||||
const suffix: string = pro.suffix(distribution);
|
||||
const url: string = `https://goreleaser.com/static/releases${suffix}.json`;
|
||||
const getTags = http.getJson<Array<GitHubTag>>(url);
|
||||
|
||||
return getTags.then(response => {
|
||||
|
|
@ -41,3 +49,7 @@ const getAllTags = async (): Promise<Array<string>> => {
|
|||
return response.result.map(obj => obj.tag_name);
|
||||
});
|
||||
};
|
||||
|
||||
const cleanTag = (tag: string): string => {
|
||||
return tag.replace(/-pro$/, '');
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,22 +2,24 @@ import * as os from 'os';
|
|||
import * as path from 'path';
|
||||
import * as util from 'util';
|
||||
import * as github from './github';
|
||||
import * as pro from './pro';
|
||||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
|
||||
const osPlat: string = os.platform();
|
||||
const osArch: string = os.arch();
|
||||
|
||||
export async function getGoReleaser(version: string): Promise<string> {
|
||||
const release: github.GitHubRelease | null = await github.getRelease(version);
|
||||
export async function getGoReleaser(distribution: string, version: string): Promise<string> {
|
||||
const release: github.GitHubRelease | null = await github.getRelease(distribution, version);
|
||||
if (!release) {
|
||||
throw new Error(`Cannot find GoReleaser ${version} release`);
|
||||
}
|
||||
|
||||
core.info(`✅ GoReleaser version found: ${release.tag_name}`);
|
||||
const filename = getFilename();
|
||||
const filename = getFilename(distribution);
|
||||
const downloadUrl = util.format(
|
||||
'https://github.com/goreleaser/goreleaser/releases/download/%s/%s',
|
||||
'https://github.com/goreleaser/%s/releases/download/%s/%s',
|
||||
distribution,
|
||||
release.tag_name,
|
||||
filename
|
||||
);
|
||||
|
|
@ -44,9 +46,10 @@ export async function getGoReleaser(version: string): Promise<string> {
|
|||
return exePath;
|
||||
}
|
||||
|
||||
const getFilename = (): string => {
|
||||
const getFilename = (distribution: string): string => {
|
||||
const platform: string = osPlat == 'win32' ? 'Windows' : osPlat == 'darwin' ? 'Darwin' : 'Linux';
|
||||
const arch: string = osArch == 'x64' ? 'x86_64' : 'i386';
|
||||
const ext: string = osPlat == 'win32' ? 'zip' : 'tar.gz';
|
||||
return util.format('goreleaser_%s_%s.%s', platform, arch, ext);
|
||||
const suffix: string = pro.suffix(distribution);
|
||||
return util.format('goreleaser%s_%s_%s.%s', suffix, platform, arch, ext);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ import {dirname} from 'path';
|
|||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const distribution = core.getInput('distribution') || 'goreleaser';
|
||||
const version = core.getInput('version') || 'latest';
|
||||
const args = core.getInput('args');
|
||||
const workdir = core.getInput('workdir') || '.';
|
||||
const isInstallOnly = /^true$/i.test(core.getInput('install-only'));
|
||||
const goreleaser = await installer.getGoReleaser(version);
|
||||
const goreleaser = await installer.getGoReleaser(distribution, version);
|
||||
core.info(`✅ GoReleaser installed successfully`);
|
||||
|
||||
if (isInstallOnly) {
|
||||
|
|
|
|||
7
src/pro.ts
Normal file
7
src/pro.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
export const suffix = (distribution: string): string => {
|
||||
return isPro(distribution) ? '-pro' : '';
|
||||
};
|
||||
|
||||
export const isPro = (distribution: string): boolean => {
|
||||
return distribution === 'goreleaser-pro';
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue