refactor: setup context (#325)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
a80c8fd82d
commit
39419c3fac
|
@ -0,0 +1,33 @@
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import * as goreleaser from '../src/goreleaser';
|
||||||
|
|
||||||
|
describe('install', () => {
|
||||||
|
it('acquires v0.182.0 version of GoReleaser', async () => {
|
||||||
|
const bin = await goreleaser.install('goreleaser', 'v0.182.0');
|
||||||
|
expect(fs.existsSync(bin)).toBe(true);
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
|
it('acquires latest version of GoReleaser', async () => {
|
||||||
|
const bin = await goreleaser.install('goreleaser', 'latest');
|
||||||
|
expect(fs.existsSync(bin)).toBe(true);
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
|
it('acquires v0.182.0-pro version of GoReleaser Pro', async () => {
|
||||||
|
const bin = await goreleaser.install('goreleaser-pro', 'v0.182.0-pro');
|
||||||
|
expect(fs.existsSync(bin)).toBe(true);
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
|
it('acquires latest version of GoReleaser Pro', async () => {
|
||||||
|
const bin = await goreleaser.install('goreleaser-pro', 'latest');
|
||||||
|
expect(fs.existsSync(bin)).toBe(true);
|
||||||
|
}, 100000);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('distribSuffix', () => {
|
||||||
|
it('suffixes pro distribution', async () => {
|
||||||
|
expect(goreleaser.distribSuffix('goreleaser-pro')).toEqual('-pro');
|
||||||
|
});
|
||||||
|
it('does not suffix oss distribution', async () => {
|
||||||
|
expect(goreleaser.distribSuffix('goreleaser')).toEqual('');
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,24 +0,0 @@
|
||||||
import fs = require('fs');
|
|
||||||
import * as installer from '../src/installer';
|
|
||||||
|
|
||||||
describe('installer', () => {
|
|
||||||
it('acquires v0.182.0 version of GoReleaser', async () => {
|
|
||||||
const goreleaser = await installer.getGoReleaser('goreleaser', 'v0.182.0');
|
|
||||||
expect(fs.existsSync(goreleaser)).toBe(true);
|
|
||||||
}, 100000);
|
|
||||||
|
|
||||||
it('acquires latest version of GoReleaser', async () => {
|
|
||||||
const goreleaser = await installer.getGoReleaser('goreleaser', 'latest');
|
|
||||||
expect(fs.existsSync(goreleaser)).toBe(true);
|
|
||||||
}, 100000);
|
|
||||||
|
|
||||||
it('acquires v0.182.0-pro version of GoReleaser Pro', async () => {
|
|
||||||
const goreleaser = await installer.getGoReleaser('goreleaser-pro', 'v0.182.0-pro');
|
|
||||||
expect(fs.existsSync(goreleaser)).toBe(true);
|
|
||||||
}, 100000);
|
|
||||||
|
|
||||||
it('acquires latest version of GoReleaser Pro', async () => {
|
|
||||||
const goreleaser = await installer.getGoReleaser('goreleaser-pro', 'latest');
|
|
||||||
expect(fs.existsSync(goreleaser)).toBe(true);
|
|
||||||
}, 100000);
|
|
||||||
});
|
|
|
@ -1,10 +0,0 @@
|
||||||
import * as pro from '../src/pro';
|
|
||||||
|
|
||||||
describe('pro', () => {
|
|
||||||
it('suffixes pro distribution', async () => {
|
|
||||||
expect(pro.suffix('goreleaser-pro')).toEqual('-pro');
|
|
||||||
});
|
|
||||||
it('does not suffix oss distribution', async () => {
|
|
||||||
expect(pro.suffix('goreleaser')).toEqual('');
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,6 +1,61 @@
|
||||||
/******/ (() => { // webpackBootstrap
|
/******/ (() => { // webpackBootstrap
|
||||||
/******/ var __webpack_modules__ = ({
|
/******/ var __webpack_modules__ = ({
|
||||||
|
|
||||||
|
/***/ 842:
|
||||||
|
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
|
exports.getInputs = exports.osArch = exports.osPlat = void 0;
|
||||||
|
const os = __importStar(__nccwpck_require__(87));
|
||||||
|
const core = __importStar(__nccwpck_require__(186));
|
||||||
|
exports.osPlat = os.platform();
|
||||||
|
exports.osArch = os.arch();
|
||||||
|
function getInputs() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
return {
|
||||||
|
distribution: core.getInput('distribution') || 'goreleaser',
|
||||||
|
version: core.getInput('version'),
|
||||||
|
args: core.getInput('args'),
|
||||||
|
workdir: core.getInput('workdir') || '.',
|
||||||
|
installOnly: core.getBooleanInput('install-only')
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.getInputs = getInputs;
|
||||||
|
//# sourceMappingURL=context.js.map
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
/***/ 374:
|
/***/ 374:
|
||||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||||
|
|
||||||
|
@ -129,10 +184,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.getRelease = void 0;
|
exports.getRelease = void 0;
|
||||||
const httpm = __importStar(__nccwpck_require__(925));
|
const goreleaser = __importStar(__nccwpck_require__(823));
|
||||||
const core = __importStar(__nccwpck_require__(186));
|
|
||||||
const semver = __importStar(__nccwpck_require__(911));
|
const semver = __importStar(__nccwpck_require__(911));
|
||||||
const pro = __importStar(__nccwpck_require__(989));
|
const core = __importStar(__nccwpck_require__(186));
|
||||||
|
const httpm = __importStar(__nccwpck_require__(925));
|
||||||
const getRelease = (distribution, version) => __awaiter(void 0, void 0, void 0, function* () {
|
const getRelease = (distribution, version) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const resolvedVersion = (yield resolveVersion(distribution, version)) || version;
|
const resolvedVersion = (yield resolveVersion(distribution, version)) || version;
|
||||||
const url = `https://github.com/goreleaser/${distribution}/releases/${resolvedVersion}`;
|
const url = `https://github.com/goreleaser/${distribution}/releases/${resolvedVersion}`;
|
||||||
|
@ -146,16 +201,16 @@ const resolveVersion = (distribution, version) => __awaiter(void 0, void 0, void
|
||||||
throw new Error(`Cannot find GoReleaser tags`);
|
throw new Error(`Cannot find GoReleaser tags`);
|
||||||
}
|
}
|
||||||
core.debug(`Found ${allTags.length} tags in total`);
|
core.debug(`Found ${allTags.length} tags in total`);
|
||||||
if (version === 'latest' || !pro.isPro(distribution)) {
|
if (version === 'latest' || !goreleaser.isPro(distribution)) {
|
||||||
return semver.maxSatisfying(allTags, version);
|
return semver.maxSatisfying(allTags, version);
|
||||||
}
|
}
|
||||||
const cleanTags = allTags.map(tag => cleanTag(tag));
|
const cleanTags = allTags.map(tag => cleanTag(tag));
|
||||||
const cleanVersion = cleanTag(version);
|
const cleanVersion = cleanTag(version);
|
||||||
return semver.maxSatisfying(cleanTags, cleanVersion) + pro.suffix(distribution);
|
return semver.maxSatisfying(cleanTags, cleanVersion) + goreleaser.distribSuffix(distribution);
|
||||||
});
|
});
|
||||||
const getAllTags = (distribution) => __awaiter(void 0, void 0, void 0, function* () {
|
const getAllTags = (distribution) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const http = new httpm.HttpClient('goreleaser-action');
|
const http = new httpm.HttpClient('goreleaser-action');
|
||||||
const suffix = pro.suffix(distribution);
|
const suffix = goreleaser.distribSuffix(distribution);
|
||||||
const url = `https://goreleaser.com/static/releases${suffix}.json`;
|
const url = `https://goreleaser.com/static/releases${suffix}.json`;
|
||||||
const getTags = http.getJson(url);
|
const getTags = http.getJson(url);
|
||||||
return getTags.then(response => {
|
return getTags.then(response => {
|
||||||
|
@ -172,7 +227,7 @@ const cleanTag = (tag) => {
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 480:
|
/***/ 823:
|
||||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
@ -206,17 +261,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.getGoReleaser = void 0;
|
exports.isPro = exports.distribSuffix = exports.install = void 0;
|
||||||
const os = __importStar(__nccwpck_require__(87));
|
|
||||||
const path = __importStar(__nccwpck_require__(622));
|
const path = __importStar(__nccwpck_require__(622));
|
||||||
const util = __importStar(__nccwpck_require__(669));
|
const util = __importStar(__nccwpck_require__(669));
|
||||||
|
const context = __importStar(__nccwpck_require__(842));
|
||||||
const github = __importStar(__nccwpck_require__(928));
|
const github = __importStar(__nccwpck_require__(928));
|
||||||
const pro = __importStar(__nccwpck_require__(989));
|
|
||||||
const core = __importStar(__nccwpck_require__(186));
|
const core = __importStar(__nccwpck_require__(186));
|
||||||
const tc = __importStar(__nccwpck_require__(784));
|
const tc = __importStar(__nccwpck_require__(784));
|
||||||
const osPlat = os.platform();
|
function install(distribution, version) {
|
||||||
const osArch = os.arch();
|
|
||||||
function getGoReleaser(distribution, version) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const release = yield github.getRelease(distribution, version);
|
const release = yield github.getRelease(distribution, version);
|
||||||
if (!release) {
|
if (!release) {
|
||||||
|
@ -229,7 +281,7 @@ function getGoReleaser(distribution, version) {
|
||||||
core.debug(`Downloaded to ${downloadPath}`);
|
core.debug(`Downloaded to ${downloadPath}`);
|
||||||
core.info('Extracting GoReleaser');
|
core.info('Extracting GoReleaser');
|
||||||
let extPath;
|
let extPath;
|
||||||
if (osPlat == 'win32') {
|
if (context.osPlat == 'win32') {
|
||||||
extPath = yield tc.extractZip(downloadPath);
|
extPath = yield tc.extractZip(downloadPath);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -238,15 +290,23 @@ function getGoReleaser(distribution, version) {
|
||||||
core.debug(`Extracted to ${extPath}`);
|
core.debug(`Extracted to ${extPath}`);
|
||||||
const cachePath = yield tc.cacheDir(extPath, 'goreleaser-action', release.tag_name.replace(/^v/, ''));
|
const cachePath = yield tc.cacheDir(extPath, 'goreleaser-action', release.tag_name.replace(/^v/, ''));
|
||||||
core.debug(`Cached to ${cachePath}`);
|
core.debug(`Cached to ${cachePath}`);
|
||||||
const exePath = path.join(cachePath, osPlat == 'win32' ? 'goreleaser.exe' : 'goreleaser');
|
const exePath = path.join(cachePath, context.osPlat == 'win32' ? 'goreleaser.exe' : 'goreleaser');
|
||||||
core.debug(`Exe path is ${exePath}`);
|
core.debug(`Exe path is ${exePath}`);
|
||||||
return exePath;
|
return exePath;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.getGoReleaser = getGoReleaser;
|
exports.install = install;
|
||||||
|
const distribSuffix = (distribution) => {
|
||||||
|
return exports.isPro(distribution) ? '-pro' : '';
|
||||||
|
};
|
||||||
|
exports.distribSuffix = distribSuffix;
|
||||||
|
const isPro = (distribution) => {
|
||||||
|
return distribution === 'goreleaser-pro';
|
||||||
|
};
|
||||||
|
exports.isPro = isPro;
|
||||||
const getFilename = (distribution) => {
|
const getFilename = (distribution) => {
|
||||||
let arch;
|
let arch;
|
||||||
switch (osArch) {
|
switch (context.osArch) {
|
||||||
case 'x64': {
|
case 'x64': {
|
||||||
arch = 'x86_64';
|
arch = 'x86_64';
|
||||||
break;
|
break;
|
||||||
|
@ -261,19 +321,19 @@ const getFilename = (distribution) => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
arch = osArch;
|
arch = context.osArch;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (osPlat == 'darwin') {
|
if (context.osPlat == 'darwin') {
|
||||||
arch = 'all';
|
arch = 'all';
|
||||||
}
|
}
|
||||||
const platform = osPlat == 'win32' ? 'Windows' : osPlat == 'darwin' ? 'Darwin' : 'Linux';
|
const platform = context.osPlat == 'win32' ? 'Windows' : context.osPlat == 'darwin' ? 'Darwin' : 'Linux';
|
||||||
const ext = osPlat == 'win32' ? 'zip' : 'tar.gz';
|
const ext = context.osPlat == 'win32' ? 'zip' : 'tar.gz';
|
||||||
const suffix = pro.suffix(distribution);
|
const suffix = exports.distribSuffix(distribution);
|
||||||
return util.format('goreleaser%s_%s_%s.%s', suffix, platform, arch, ext);
|
return util.format('goreleaser%s_%s_%s.%s', suffix, platform, arch, ext);
|
||||||
};
|
};
|
||||||
//# sourceMappingURL=installer.js.map
|
//# sourceMappingURL=goreleaser.js.map
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
|
@ -311,42 +371,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
|
const path = __importStar(__nccwpck_require__(622));
|
||||||
|
const context = __importStar(__nccwpck_require__(842));
|
||||||
const git = __importStar(__nccwpck_require__(374));
|
const git = __importStar(__nccwpck_require__(374));
|
||||||
const installer = __importStar(__nccwpck_require__(480));
|
const goreleaser = __importStar(__nccwpck_require__(823));
|
||||||
const core = __importStar(__nccwpck_require__(186));
|
const core = __importStar(__nccwpck_require__(186));
|
||||||
const exec = __importStar(__nccwpck_require__(514));
|
const exec = __importStar(__nccwpck_require__(514));
|
||||||
const path_1 = __nccwpck_require__(622);
|
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
const distribution = core.getInput('distribution') || 'goreleaser';
|
const inputs = yield context.getInputs();
|
||||||
const version = core.getInput('version') || 'latest';
|
const bin = yield goreleaser.install(inputs.distribution, inputs.version);
|
||||||
const args = core.getInput('args');
|
core.info(`GoReleaser ${inputs.version} installed successfully`);
|
||||||
const workdir = core.getInput('workdir') || '.';
|
if (inputs.installOnly) {
|
||||||
const isInstallOnly = /^true$/i.test(core.getInput('install-only'));
|
const goreleaserDir = path.dirname(bin);
|
||||||
const goreleaser = yield installer.getGoReleaser(distribution, version);
|
|
||||||
core.info(`GoReleaser ${version} installed successfully`);
|
|
||||||
if (isInstallOnly) {
|
|
||||||
const goreleaserDir = path_1.dirname(goreleaser);
|
|
||||||
core.addPath(goreleaserDir);
|
core.addPath(goreleaserDir);
|
||||||
core.debug(`Added ${goreleaserDir} to PATH`);
|
core.debug(`Added ${goreleaserDir} to PATH`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (!args) {
|
else if (!inputs.args) {
|
||||||
core.setFailed('args input required');
|
core.setFailed('args input required');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (workdir && workdir !== '.') {
|
if (inputs.workdir && inputs.workdir !== '.') {
|
||||||
core.info(`Using ${workdir} as working directory`);
|
core.info(`Using ${inputs.workdir} as working directory`);
|
||||||
process.chdir(workdir);
|
process.chdir(inputs.workdir);
|
||||||
}
|
}
|
||||||
const commit = yield git.getShortCommit();
|
const commit = yield git.getShortCommit();
|
||||||
const tag = yield git.getTag();
|
const tag = yield git.getTag();
|
||||||
const isTagDirty = yield git.isTagDirty(tag);
|
const isTagDirty = yield git.isTagDirty(tag);
|
||||||
let snapshot = '';
|
let snapshot = '';
|
||||||
if (args.split(' ').indexOf('release') > -1) {
|
if (inputs.args.split(' ').indexOf('release') > -1) {
|
||||||
if (isTagDirty) {
|
if (isTagDirty) {
|
||||||
if (!args.includes('--snapshot') && !args.includes('--nightly')) {
|
if (!inputs.args.includes('--snapshot') && !inputs.args.includes('--nightly')) {
|
||||||
core.info(`No tag found for commit ${commit}. Snapshot forced`);
|
core.info(`No tag found for commit ${commit}. Snapshot forced`);
|
||||||
snapshot = ' --snapshot';
|
snapshot = ' --snapshot';
|
||||||
}
|
}
|
||||||
|
@ -355,10 +412,11 @@ function run() {
|
||||||
core.info(`${tag} tag found for commit ${commit}`);
|
core.info(`${tag} tag found for commit ${commit}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!('GORELEASER_CURRENT_TAG' in process.env)) {
|
yield exec.exec(`${bin} ${inputs.args}${snapshot}`, undefined, {
|
||||||
process.env.GORELEASER_CURRENT_TAG = tag;
|
env: Object.assign({}, process.env, {
|
||||||
}
|
GORELEASER_CURRENT_TAG: tag || process.env.GORELEASER_CURRENT_TAG || ''
|
||||||
yield exec.exec(`${goreleaser} ${args}${snapshot}`);
|
})
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
|
@ -370,26 +428,7 @@ run();
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 989:
|
/***/ 351:
|
||||||
/***/ ((__unused_webpack_module, exports) => {
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
||||||
exports.isPro = exports.suffix = void 0;
|
|
||||||
const suffix = (distribution) => {
|
|
||||||
return exports.isPro(distribution) ? '-pro' : '';
|
|
||||||
};
|
|
||||||
exports.suffix = suffix;
|
|
||||||
const isPro = (distribution) => {
|
|
||||||
return distribution === 'goreleaser-pro';
|
|
||||||
};
|
|
||||||
exports.isPro = isPro;
|
|
||||||
//# sourceMappingURL=pro.js.map
|
|
||||||
|
|
||||||
/***/ }),
|
|
||||||
|
|
||||||
/***/ 241:
|
|
||||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
@ -523,7 +562,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.getIDToken = exports.getState = exports.saveState = exports.group = exports.endGroup = exports.startGroup = exports.info = exports.notice = exports.warning = exports.error = exports.debug = exports.isDebug = exports.setFailed = exports.setCommandEcho = exports.setOutput = exports.getBooleanInput = exports.getMultilineInput = exports.getInput = exports.addPath = exports.setSecret = exports.exportVariable = exports.ExitCode = void 0;
|
exports.getIDToken = exports.getState = exports.saveState = exports.group = exports.endGroup = exports.startGroup = exports.info = exports.notice = exports.warning = exports.error = exports.debug = exports.isDebug = exports.setFailed = exports.setCommandEcho = exports.setOutput = exports.getBooleanInput = exports.getMultilineInput = exports.getInput = exports.addPath = exports.setSecret = exports.exportVariable = exports.ExitCode = void 0;
|
||||||
const command_1 = __nccwpck_require__(241);
|
const command_1 = __nccwpck_require__(351);
|
||||||
const file_command_1 = __nccwpck_require__(717);
|
const file_command_1 = __nccwpck_require__(717);
|
||||||
const utils_1 = __nccwpck_require__(278);
|
const utils_1 = __nccwpck_require__(278);
|
||||||
const os = __importStar(__nccwpck_require__(87));
|
const os = __importStar(__nccwpck_require__(87));
|
||||||
|
@ -1136,7 +1175,7 @@ const os = __importStar(__nccwpck_require__(87));
|
||||||
const events = __importStar(__nccwpck_require__(614));
|
const events = __importStar(__nccwpck_require__(614));
|
||||||
const child = __importStar(__nccwpck_require__(129));
|
const child = __importStar(__nccwpck_require__(129));
|
||||||
const path = __importStar(__nccwpck_require__(622));
|
const path = __importStar(__nccwpck_require__(622));
|
||||||
const io = __importStar(__nccwpck_require__(351));
|
const io = __importStar(__nccwpck_require__(436));
|
||||||
const ioUtil = __importStar(__nccwpck_require__(962));
|
const ioUtil = __importStar(__nccwpck_require__(962));
|
||||||
const timers_1 = __nccwpck_require__(213);
|
const timers_1 = __nccwpck_require__(213);
|
||||||
/* eslint-disable @typescript-eslint/unbound-method */
|
/* eslint-disable @typescript-eslint/unbound-method */
|
||||||
|
@ -2582,7 +2621,7 @@ exports.getCmdPath = getCmdPath;
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 351:
|
/***/ 436:
|
||||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
@ -3194,7 +3233,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.evaluateVersions = exports.isExplicitVersion = exports.findFromManifest = exports.getManifestFromRepo = exports.findAllVersions = exports.find = exports.cacheFile = exports.cacheDir = exports.extractZip = exports.extractXar = exports.extractTar = exports.extract7z = exports.downloadTool = exports.HTTPError = void 0;
|
exports.evaluateVersions = exports.isExplicitVersion = exports.findFromManifest = exports.getManifestFromRepo = exports.findAllVersions = exports.find = exports.cacheFile = exports.cacheDir = exports.extractZip = exports.extractXar = exports.extractTar = exports.extract7z = exports.downloadTool = exports.HTTPError = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(186));
|
const core = __importStar(__nccwpck_require__(186));
|
||||||
const io = __importStar(__nccwpck_require__(351));
|
const io = __importStar(__nccwpck_require__(436));
|
||||||
const fs = __importStar(__nccwpck_require__(747));
|
const fs = __importStar(__nccwpck_require__(747));
|
||||||
const mm = __importStar(__nccwpck_require__(473));
|
const mm = __importStar(__nccwpck_require__(473));
|
||||||
const os = __importStar(__nccwpck_require__(87));
|
const os = __importStar(__nccwpck_require__(87));
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
import * as os from 'os';
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
|
export const osPlat: string = os.platform();
|
||||||
|
export const osArch: string = os.arch();
|
||||||
|
|
||||||
|
export interface Inputs {
|
||||||
|
distribution: string;
|
||||||
|
version: string;
|
||||||
|
args: string;
|
||||||
|
workdir: string;
|
||||||
|
installOnly: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getInputs(): Promise<Inputs> {
|
||||||
|
return {
|
||||||
|
distribution: core.getInput('distribution') || 'goreleaser',
|
||||||
|
version: core.getInput('version'),
|
||||||
|
args: core.getInput('args'),
|
||||||
|
workdir: core.getInput('workdir') || '.',
|
||||||
|
installOnly: core.getBooleanInput('install-only')
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
import * as httpm from '@actions/http-client';
|
import * as goreleaser from './goreleaser';
|
||||||
import * as core from '@actions/core';
|
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import * as pro from './pro';
|
import * as core from '@actions/core';
|
||||||
|
import * as httpm from '@actions/http-client';
|
||||||
|
|
||||||
export interface GitHubRelease {
|
export interface GitHubRelease {
|
||||||
id: number;
|
id: number;
|
||||||
|
@ -22,13 +22,13 @@ const resolveVersion = async (distribution: string, version: string): Promise<st
|
||||||
}
|
}
|
||||||
core.debug(`Found ${allTags.length} tags in total`);
|
core.debug(`Found ${allTags.length} tags in total`);
|
||||||
|
|
||||||
if (version === 'latest' || !pro.isPro(distribution)) {
|
if (version === 'latest' || !goreleaser.isPro(distribution)) {
|
||||||
return semver.maxSatisfying(allTags, version);
|
return semver.maxSatisfying(allTags, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
const cleanTags: Array<string> = allTags.map(tag => cleanTag(tag));
|
const cleanTags: Array<string> = allTags.map(tag => cleanTag(tag));
|
||||||
const cleanVersion: string = cleanTag(version);
|
const cleanVersion: string = cleanTag(version);
|
||||||
return semver.maxSatisfying(cleanTags, cleanVersion) + pro.suffix(distribution);
|
return semver.maxSatisfying(cleanTags, cleanVersion) + goreleaser.distribSuffix(distribution);
|
||||||
};
|
};
|
||||||
|
|
||||||
interface GitHubTag {
|
interface GitHubTag {
|
||||||
|
@ -37,15 +37,13 @@ interface GitHubTag {
|
||||||
|
|
||||||
const getAllTags = async (distribution: string): Promise<Array<string>> => {
|
const getAllTags = async (distribution: string): Promise<Array<string>> => {
|
||||||
const http: httpm.HttpClient = new httpm.HttpClient('goreleaser-action');
|
const http: httpm.HttpClient = new httpm.HttpClient('goreleaser-action');
|
||||||
const suffix: string = pro.suffix(distribution);
|
const suffix: string = goreleaser.distribSuffix(distribution);
|
||||||
const url: string = `https://goreleaser.com/static/releases${suffix}.json`;
|
const url: string = `https://goreleaser.com/static/releases${suffix}.json`;
|
||||||
const getTags = http.getJson<Array<GitHubTag>>(url);
|
const getTags = http.getJson<Array<GitHubTag>>(url);
|
||||||
|
|
||||||
return getTags.then(response => {
|
return getTags.then(response => {
|
||||||
if (response.result == null) {
|
if (response.result == null) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.result.map(obj => obj.tag_name);
|
return response.result.map(obj => obj.tag_name);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
import * as os from 'os';
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as util from 'util';
|
import * as util from 'util';
|
||||||
|
import * as context from './context';
|
||||||
import * as github from './github';
|
import * as github from './github';
|
||||||
import * as pro from './pro';
|
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
|
|
||||||
const osPlat: string = os.platform();
|
export async function install(distribution: string, version: string): Promise<string> {
|
||||||
const osArch: string = os.arch();
|
|
||||||
|
|
||||||
export async function getGoReleaser(distribution: string, version: string): Promise<string> {
|
|
||||||
const release: github.GitHubRelease | null = await github.getRelease(distribution, version);
|
const release: github.GitHubRelease | null = await github.getRelease(distribution, version);
|
||||||
if (!release) {
|
if (!release) {
|
||||||
throw new Error(`Cannot find GoReleaser ${version} release`);
|
throw new Error(`Cannot find GoReleaser ${version} release`);
|
||||||
|
@ -29,7 +25,7 @@ export async function getGoReleaser(distribution: string, version: string): Prom
|
||||||
|
|
||||||
core.info('Extracting GoReleaser');
|
core.info('Extracting GoReleaser');
|
||||||
let extPath: string;
|
let extPath: string;
|
||||||
if (osPlat == 'win32') {
|
if (context.osPlat == 'win32') {
|
||||||
extPath = await tc.extractZip(downloadPath);
|
extPath = await tc.extractZip(downloadPath);
|
||||||
} else {
|
} else {
|
||||||
extPath = await tc.extractTar(downloadPath);
|
extPath = await tc.extractTar(downloadPath);
|
||||||
|
@ -39,15 +35,23 @@ export async function getGoReleaser(distribution: string, version: string): Prom
|
||||||
const cachePath: string = await tc.cacheDir(extPath, 'goreleaser-action', release.tag_name.replace(/^v/, ''));
|
const cachePath: string = await tc.cacheDir(extPath, 'goreleaser-action', release.tag_name.replace(/^v/, ''));
|
||||||
core.debug(`Cached to ${cachePath}`);
|
core.debug(`Cached to ${cachePath}`);
|
||||||
|
|
||||||
const exePath: string = path.join(cachePath, osPlat == 'win32' ? 'goreleaser.exe' : 'goreleaser');
|
const exePath: string = path.join(cachePath, context.osPlat == 'win32' ? 'goreleaser.exe' : 'goreleaser');
|
||||||
core.debug(`Exe path is ${exePath}`);
|
core.debug(`Exe path is ${exePath}`);
|
||||||
|
|
||||||
return exePath;
|
return exePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const distribSuffix = (distribution: string): string => {
|
||||||
|
return isPro(distribution) ? '-pro' : '';
|
||||||
|
};
|
||||||
|
|
||||||
|
export const isPro = (distribution: string): boolean => {
|
||||||
|
return distribution === 'goreleaser-pro';
|
||||||
|
};
|
||||||
|
|
||||||
const getFilename = (distribution: string): string => {
|
const getFilename = (distribution: string): string => {
|
||||||
let arch: string;
|
let arch: string;
|
||||||
switch (osArch) {
|
switch (context.osArch) {
|
||||||
case 'x64': {
|
case 'x64': {
|
||||||
arch = 'x86_64';
|
arch = 'x86_64';
|
||||||
break;
|
break;
|
||||||
|
@ -62,15 +66,15 @@ const getFilename = (distribution: string): string => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
arch = osArch;
|
arch = context.osArch;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (osPlat == 'darwin') {
|
if (context.osPlat == 'darwin') {
|
||||||
arch = 'all';
|
arch = 'all';
|
||||||
}
|
}
|
||||||
const platform: string = osPlat == 'win32' ? 'Windows' : osPlat == 'darwin' ? 'Darwin' : 'Linux';
|
const platform: string = context.osPlat == 'win32' ? 'Windows' : context.osPlat == 'darwin' ? 'Darwin' : 'Linux';
|
||||||
const ext: string = osPlat == 'win32' ? 'zip' : 'tar.gz';
|
const ext: string = context.osPlat == 'win32' ? 'zip' : 'tar.gz';
|
||||||
const suffix: string = pro.suffix(distribution);
|
const suffix: string = distribSuffix(distribution);
|
||||||
return util.format('goreleaser%s_%s_%s.%s', suffix, platform, arch, ext);
|
return util.format('goreleaser%s_%s_%s.%s', suffix, platform, arch, ext);
|
||||||
};
|
};
|
40
src/main.ts
40
src/main.ts
|
@ -1,32 +1,29 @@
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as context from './context';
|
||||||
import * as git from './git';
|
import * as git from './git';
|
||||||
import * as installer from './installer';
|
import * as goreleaser from './goreleaser';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import {dirname} from 'path';
|
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const distribution = core.getInput('distribution') || 'goreleaser';
|
const inputs: context.Inputs = await context.getInputs();
|
||||||
const version = core.getInput('version') || 'latest';
|
const bin = await goreleaser.install(inputs.distribution, inputs.version);
|
||||||
const args = core.getInput('args');
|
core.info(`GoReleaser ${inputs.version} installed successfully`);
|
||||||
const workdir = core.getInput('workdir') || '.';
|
|
||||||
const isInstallOnly = /^true$/i.test(core.getInput('install-only'));
|
|
||||||
const goreleaser = await installer.getGoReleaser(distribution, version);
|
|
||||||
core.info(`GoReleaser ${version} installed successfully`);
|
|
||||||
|
|
||||||
if (isInstallOnly) {
|
if (inputs.installOnly) {
|
||||||
const goreleaserDir = dirname(goreleaser);
|
const goreleaserDir = path.dirname(bin);
|
||||||
core.addPath(goreleaserDir);
|
core.addPath(goreleaserDir);
|
||||||
core.debug(`Added ${goreleaserDir} to PATH`);
|
core.debug(`Added ${goreleaserDir} to PATH`);
|
||||||
return;
|
return;
|
||||||
} else if (!args) {
|
} else if (!inputs.args) {
|
||||||
core.setFailed('args input required');
|
core.setFailed('args input required');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (workdir && workdir !== '.') {
|
if (inputs.workdir && inputs.workdir !== '.') {
|
||||||
core.info(`Using ${workdir} as working directory`);
|
core.info(`Using ${inputs.workdir} as working directory`);
|
||||||
process.chdir(workdir);
|
process.chdir(inputs.workdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
const commit = await git.getShortCommit();
|
const commit = await git.getShortCommit();
|
||||||
|
@ -34,9 +31,9 @@ async function run(): Promise<void> {
|
||||||
const isTagDirty = await git.isTagDirty(tag);
|
const isTagDirty = await git.isTagDirty(tag);
|
||||||
|
|
||||||
let snapshot = '';
|
let snapshot = '';
|
||||||
if (args.split(' ').indexOf('release') > -1) {
|
if (inputs.args.split(' ').indexOf('release') > -1) {
|
||||||
if (isTagDirty) {
|
if (isTagDirty) {
|
||||||
if (!args.includes('--snapshot') && !args.includes('--nightly')) {
|
if (!inputs.args.includes('--snapshot') && !inputs.args.includes('--nightly')) {
|
||||||
core.info(`No tag found for commit ${commit}. Snapshot forced`);
|
core.info(`No tag found for commit ${commit}. Snapshot forced`);
|
||||||
snapshot = ' --snapshot';
|
snapshot = ' --snapshot';
|
||||||
}
|
}
|
||||||
|
@ -45,10 +42,13 @@ async function run(): Promise<void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!('GORELEASER_CURRENT_TAG' in process.env)) {
|
await exec.exec(`${bin} ${inputs.args}${snapshot}`, undefined, {
|
||||||
process.env.GORELEASER_CURRENT_TAG = tag;
|
env: Object.assign({}, process.env, {
|
||||||
|
GORELEASER_CURRENT_TAG: tag || process.env.GORELEASER_CURRENT_TAG || ''
|
||||||
|
}) as {
|
||||||
|
[key: string]: string;
|
||||||
}
|
}
|
||||||
await exec.exec(`${goreleaser} ${args}${snapshot}`);
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
export const suffix = (distribution: string): string => {
|
|
||||||
return isPro(distribution) ? '-pro' : '';
|
|
||||||
};
|
|
||||||
|
|
||||||
export const isPro = (distribution: string): boolean => {
|
|
||||||
return distribution === 'goreleaser-pro';
|
|
||||||
};
|
|
Loading…
Reference in New Issue