Add json output

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2021-05-22 21:23:06 +02:00
parent 01dc739d69
commit e6f3e4aa91
6 changed files with 359 additions and 20 deletions

View File

@ -60,6 +60,13 @@ async function run() {
core.endGroup();
setOutput('labels', labels.join(inputs.sepLabels));
// JSON
const jsonOutput = meta.getJSON();
core.startGroup(`JSON output`);
core.info(JSON.stringify(jsonOutput, null, 2));
core.endGroup();
setOutput('json', jsonOutput);
// Bake definition file
const bakeFile: string = meta.getBakeFile();
core.startGroup(`Bake definition file`);

View File

@ -318,16 +318,21 @@ export class Meta {
return labels;
}
public getBakeFile(): string {
let jsonLabels = {};
for (let label of this.getLabels()) {
const matches = label.match(/([^=]*)=(.*)/);
if (!matches) {
continue;
}
jsonLabels[matches[1]] = matches[2];
}
public getJSON(): {} {
return {
tags: this.getTags(),
labels: this.getLabels().reduce((res, label) => {
const matches = label.match(/([^=]*)=(.*)/);
if (!matches) {
return res;
}
res[matches[1]] = matches[2];
return res;
}, {})
};
}
public getBakeFile(): string {
const bakeFile = path.join(tmpDir(), 'docker-metadata-action-bake.json').split(path.sep).join(path.posix.sep);
fs.writeFileSync(
bakeFile,
@ -336,7 +341,14 @@ export class Meta {
target: {
[this.inputs.bakeTarget]: {
tags: this.getTags(),
labels: jsonLabels,
labels: this.getLabels().reduce((res, label) => {
const matches = label.match(/([^=]*)=(.*)/);
if (!matches) {
return res;
}
res[matches[1]] = matches[2];
return res;
}, {}),
args: {
DOCKER_META_IMAGES: this.inputs.images.join(','),
DOCKER_META_VERSION: this.version.main