mirror of
https://github.com/goreleaser/goreleaser-action
synced 2026-06-29 23:47:30 +00:00
improvement: Review snapshot behavior (#95)
* Improve git tag detection (#77) * Only handle snapshot flag for release cmd (#94) * Use core.info instead of console.log * Update gitattributes
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
import * as child_process from 'child_process';
|
||||
|
||||
const git = async (args: string[] = []) => {
|
||||
const stdout = child_process.execSync(`git ${args.join(' ')}`, {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
return stdout.trim();
|
||||
};
|
||||
|
||||
export async function isTagDirty(currentTag: string): Promise<boolean> {
|
||||
try {
|
||||
await git(['describe', '--exact-match', '--tags', '--match', currentTag]);
|
||||
} catch (err) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function getTag(): Promise<string> {
|
||||
return await git(['describe', '--tags', '--abbrev=0']);
|
||||
}
|
||||
|
||||
export async function getShortCommit(): Promise<string> {
|
||||
return await git(['show', "--format='%h'", 'HEAD', '--quiet']);
|
||||
}
|
||||
+5
-5
@@ -1,3 +1,4 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import * as download from 'download';
|
||||
import * as fs from 'fs';
|
||||
@@ -15,7 +16,7 @@ export async function getGoReleaser(version: string): Promise<string> {
|
||||
version = selected;
|
||||
}
|
||||
|
||||
console.log(`✅ GoReleaser version found: ${version}`);
|
||||
core.info(`✅ GoReleaser version found: ${version}`);
|
||||
const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'goreleaser-'));
|
||||
const fileName = getFileName();
|
||||
const downloadUrl = util.format(
|
||||
@@ -24,10 +25,10 @@ export async function getGoReleaser(version: string): Promise<string> {
|
||||
fileName
|
||||
);
|
||||
|
||||
console.log(`⬇️ Downloading ${downloadUrl}...`);
|
||||
core.info(`⬇️ Downloading ${downloadUrl}...`);
|
||||
await download.default(downloadUrl, tmpdir, {filename: fileName});
|
||||
|
||||
console.log('📦 Extracting GoReleaser...');
|
||||
core.info('📦 Extracting GoReleaser...');
|
||||
let extPath: string = tmpdir;
|
||||
if (osPlat == 'win32') {
|
||||
extPath = await tc.extractZip(`${tmpdir}/${fileName}`);
|
||||
@@ -42,8 +43,7 @@ function getFileName(): 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';
|
||||
const filename: string = util.format('goreleaser_%s_%s.%s', platform, arch, ext);
|
||||
return filename;
|
||||
return util.format('goreleaser_%s_%s.%s', platform, arch, ext);
|
||||
}
|
||||
|
||||
interface GitHubRelease {
|
||||
|
||||
+16
-9
@@ -1,3 +1,4 @@
|
||||
import * as git from './git';
|
||||
import * as installer from './installer';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
@@ -11,23 +12,29 @@ export async function run(silent?: boolean) {
|
||||
const workdir = core.getInput('workdir') || '.';
|
||||
const goreleaser = await installer.getGoReleaser(version);
|
||||
|
||||
const commit = await git.getShortCommit();
|
||||
const tag = await git.getTag();
|
||||
const isTagDirty = await git.isTagDirty(tag);
|
||||
|
||||
if (workdir && workdir !== '.') {
|
||||
console.log(`📂 Using ${workdir} as working directory...`)
|
||||
core.info(`📂 Using ${workdir} as working directory...`);
|
||||
process.chdir(workdir);
|
||||
}
|
||||
|
||||
let snapshot = '';
|
||||
if (!process.env.GITHUB_REF || !process.env.GITHUB_REF.startsWith('refs/tags/')) {
|
||||
console.log(`⚠️ No tag found. Snapshot forced`);
|
||||
if (!args.includes('--snapshot')) {
|
||||
snapshot = ' --snapshot';
|
||||
if (args.split(' ').indexOf('release') > -1) {
|
||||
if (isTagDirty) {
|
||||
core.info(`⚠️ No tag found for commit ${commit}. Snapshot forced`);
|
||||
if (!args.includes('--snapshot')) {
|
||||
snapshot = ' --snapshot';
|
||||
}
|
||||
} else {
|
||||
core.info(`✅ ${tag} tag found for commit ${commit}`);
|
||||
}
|
||||
} else {
|
||||
console.log(`✅ ${process.env.GITHUB_REF!.split('/')[2]} tag found`);
|
||||
}
|
||||
|
||||
if (key) {
|
||||
console.log('🔑 Importing signing key...');
|
||||
core.info('🔑 Importing signing key...');
|
||||
let path = `${process.env.HOME}/key.asc`;
|
||||
fs.writeFileSync(path, key, {mode: 0o600});
|
||||
await exec.exec('gpg', ['--import', path], {
|
||||
@@ -35,7 +42,7 @@ export async function run(silent?: boolean) {
|
||||
});
|
||||
}
|
||||
|
||||
console.log('🏃 Running GoReleaser...');
|
||||
core.info('🏃 Running GoReleaser...');
|
||||
await exec.exec(`${goreleaser} ${args}${snapshot}`, undefined, {
|
||||
silent: silent
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user