mirror of
https://github.com/docker/build-push-action.git
synced 2025-04-19 01:46:45 +00:00
Add metadata
output
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
ad1d2e93be
commit
c0b121fe44
9 changed files with 104 additions and 47 deletions
|
@ -18,6 +18,18 @@ export async function getImageID(): Promise<string | undefined> {
|
|||
return fs.readFileSync(iidFile, {encoding: 'utf-8'});
|
||||
}
|
||||
|
||||
export async function getMetadataFile(): Promise<string> {
|
||||
return path.join(context.tmpDir(), 'metadata-file').split(path.sep).join(path.posix.sep);
|
||||
}
|
||||
|
||||
export async function getMetadata(): Promise<string | undefined> {
|
||||
const metadataFile = await getMetadataFile();
|
||||
if (!fs.existsSync(metadataFile)) {
|
||||
return undefined;
|
||||
}
|
||||
return fs.readFileSync(metadataFile, {encoding: 'utf-8'});
|
||||
}
|
||||
|
||||
export async function getSecretString(kvp: string): Promise<string> {
|
||||
return getSecret(kvp, false);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ import csvparse from 'csv-parse/lib/sync';
|
|||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import * as tmp from 'tmp';
|
||||
|
||||
import * as core from '@actions/core';
|
||||
|
@ -122,6 +121,9 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio
|
|||
if (!buildx.isLocalOrTarExporter(inputs.outputs) && (inputs.platforms.length == 0 || buildx.satisfies(buildxVersion, '>=0.4.2'))) {
|
||||
args.push('--iidfile', await buildx.getImageIDFile());
|
||||
}
|
||||
if (buildx.satisfies(buildxVersion, '>=0.6.0')) {
|
||||
args.push('--metadata-file', await buildx.getMetadataFile());
|
||||
}
|
||||
await asyncForEach(inputs.cacheFrom, async cacheFrom => {
|
||||
args.push('--cache-from', cacheFrom);
|
||||
});
|
||||
|
|
19
src/main.ts
19
src/main.ts
|
@ -33,13 +33,18 @@ async function run(): Promise<void> {
|
|||
}
|
||||
});
|
||||
|
||||
const imageID = await buildx.getImageID();
|
||||
if (imageID) {
|
||||
core.startGroup(`Extracting digest`);
|
||||
core.info(`${imageID}`);
|
||||
context.setOutput('digest', imageID);
|
||||
core.endGroup();
|
||||
}
|
||||
await core.group(`Setting outputs`, async () => {
|
||||
const imageID = await buildx.getImageID();
|
||||
const metadata = await buildx.getMetadata();
|
||||
if (imageID) {
|
||||
core.info(`digest=${imageID}`);
|
||||
context.setOutput('digest', imageID);
|
||||
}
|
||||
if (metadata) {
|
||||
core.info(`metadata=${metadata}`);
|
||||
context.setOutput('metadata', metadata);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue