mirror of
https://github.com/docker/metadata-action.git
synced 2025-06-24 03:37:59 +02:00
Add image version output
This commit is contained in:
10
src/main.ts
10
src/main.ts
@ -28,14 +28,20 @@ async function run() {
|
||||
|
||||
const meta: Meta = new Meta(inputs, context, repo);
|
||||
|
||||
const version: string | undefined = meta.version();
|
||||
core.startGroup(`Docker image version`);
|
||||
core.info(`${version}`);
|
||||
core.endGroup();
|
||||
core.setOutput('version', version);
|
||||
|
||||
const tags: Array<string> = meta.tags();
|
||||
core.startGroup(`Generated Docker tags`);
|
||||
core.startGroup(`Docker tags`);
|
||||
core.info(JSON.stringify(tags));
|
||||
core.endGroup();
|
||||
core.setOutput('tags', tags.join(inputs.sepTags));
|
||||
|
||||
const labels: Array<string> = meta.labels();
|
||||
core.startGroup(`Generated Docker labels`);
|
||||
core.startGroup(`Docker labels`);
|
||||
core.info(JSON.stringify(labels));
|
||||
core.endGroup();
|
||||
core.setOutput('labels', labels.join(inputs.sepTags));
|
||||
|
34
src/meta.ts
34
src/meta.ts
@ -18,6 +18,22 @@ export class Meta {
|
||||
this.repo = repo;
|
||||
}
|
||||
|
||||
public version(): string | undefined {
|
||||
if (/schedule/.test(this.context.eventName)) {
|
||||
return 'nightly';
|
||||
} else if (/^refs\/tags\//.test(this.context.ref)) {
|
||||
const tag = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||
const sver = semver.clean(tag);
|
||||
return sver ? sver : tag;
|
||||
} else if (/^refs\/heads\//.test(this.context.ref)) {
|
||||
const branch = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
||||
return this.inputs.tagEdge === branch ? 'edge' : branch;
|
||||
} else if (/^refs\/pull\//.test(this.context.ref)) {
|
||||
const pr = this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '');
|
||||
return `pr-${pr}`;
|
||||
}
|
||||
}
|
||||
|
||||
public tags(): Array<string> {
|
||||
let tags: Array<string> = [];
|
||||
for (const image of this.inputs.images) {
|
||||
@ -45,7 +61,7 @@ export class Meta {
|
||||
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
||||
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
||||
`org.opencontainers.image.source=${this.repo.clone_url || ''}`,
|
||||
`org.opencontainers.image.version=${this.labelVersion() || ''}`,
|
||||
`org.opencontainers.image.version=${this.version() || ''}`,
|
||||
`org.opencontainers.image.created=${new Date().toISOString()}`,
|
||||
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
||||
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
|
||||
@ -77,20 +93,4 @@ export class Meta {
|
||||
const pr = this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '');
|
||||
return [`${image}:pr-${pr}`];
|
||||
}
|
||||
|
||||
private labelVersion(): string | undefined {
|
||||
if (/schedule/.test(this.context.eventName)) {
|
||||
return 'nightly';
|
||||
} else if (/^refs\/tags\//.test(this.context.ref)) {
|
||||
const tag = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||
const sver = semver.clean(tag);
|
||||
return sver ? sver : tag;
|
||||
} else if (/^refs\/heads\//.test(this.context.ref)) {
|
||||
const branch = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
||||
return this.inputs.tagEdge === branch ? 'edge' : branch;
|
||||
} else if (/^refs\/pull\//.test(this.context.ref)) {
|
||||
const pr = this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '');
|
||||
return `pr-${pr}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user