feat: add artifacts and metadata outputs (#327)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2022-02-27 20:01:51 +01:00
committed by GitHub
parent affd781166
commit c127c9be61
9 changed files with 8176 additions and 132 deletions
+6
View File
@@ -1,5 +1,6 @@
import * as os from 'os';
import * as core from '@actions/core';
import {issueCommand} from '@actions/core/lib/command';
export const osPlat: string = os.platform();
export const osArch: string = os.arch();
@@ -21,3 +22,8 @@ export async function getInputs(): Promise<Inputs> {
installOnly: core.getBooleanInput('install-only')
};
}
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
export function setOutput(name: string, value: any): void {
issueCommand('set-output', {name}, value);
}
+31
View File
@@ -1,5 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import * as util from 'util';
import yaml from 'js-yaml';
import * as context from './context';
import * as github from './github';
import * as core from '@actions/core';
@@ -78,3 +80,32 @@ const getFilename = (distribution: string): string => {
const suffix: string = distribSuffix(distribution);
return util.format('goreleaser%s_%s_%s.%s', suffix, platform, arch, ext);
};
export async function getDistPath(yamlfile: string): Promise<string> {
const cfg = yaml.load(yamlfile);
return cfg.dist || 'dist';
}
export async function getArtifacts(distpath: string): Promise<string | undefined> {
const artifactsFile = path.join(distpath, 'artifacts.json');
if (!fs.existsSync(artifactsFile)) {
return undefined;
}
const content = fs.readFileSync(artifactsFile, {encoding: 'utf-8'}).trim();
if (content === 'null') {
return undefined;
}
return content;
}
export async function getMetadata(distpath: string): Promise<string | undefined> {
const metadataFile = path.join(distpath, 'metadata.json');
if (!fs.existsSync(metadataFile)) {
return undefined;
}
const content = fs.readFileSync(metadataFile, {encoding: 'utf-8'}).trim();
if (content === 'null') {
return undefined;
}
return content;
}
+31
View File
@@ -1,4 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';
import yargs from 'yargs';
import * as context from './context';
import * as git from './git';
import * as goreleaser from './goreleaser';
@@ -30,6 +32,18 @@ async function run(): Promise<void> {
const tag = await git.getTag();
const isTagDirty = await git.isTagDirty(tag);
let yamlfile: string | unknown;
const argv = yargs.parse(inputs.args);
if (argv.config) {
yamlfile = argv.config;
} else {
['.goreleaser.yaml', '.goreleaser.yml', 'goreleaser.yaml', 'goreleaser.yml'].forEach(f => {
if (fs.existsSync(f)) {
yamlfile = f;
}
});
}
let snapshot = '';
if (inputs.args.split(' ').indexOf('release') > -1) {
if (isTagDirty) {
@@ -49,6 +63,23 @@ async function run(): Promise<void> {
[key: string]: string;
}
});
if (typeof yamlfile === 'string') {
const artifacts = await goreleaser.getArtifacts(await goreleaser.getDistPath(yamlfile));
if (artifacts) {
await core.group(`Artifacts output`, async () => {
core.info(artifacts);
context.setOutput('artifacts', artifacts);
});
}
const metadata = await goreleaser.getMetadata(await goreleaser.getDistPath(yamlfile));
if (metadata) {
await core.group(`Metadata output`, async () => {
core.info(metadata);
context.setOutput('metadata', metadata);
});
}
}
} catch (error) {
core.setFailed(error.message);
}