3
0
Fork 0
mirror of https://gitea.com/docker/metadata-action.git synced 2024-11-25 21:49:33 +01:00
Signed-off-by: Trim21 <trim21.me@gmail.com>
This commit is contained in:
Trim21 2023-07-13 20:05:16 +08:00
parent 35e9aff4f5
commit 27abb2813b
No known key found for this signature in database
GPG key ID: A3F35EA8C368A6CE
4 changed files with 29 additions and 4 deletions

View file

@ -196,6 +196,7 @@ jobs:
tags: |
type=sha
type=raw,value=gexp-branch-{{branch}}
type=raw,value=gexp-date-{{commit_date 'YYYYMMDD'}}
type=raw,value=gexp-date-{{date 'YYYYMMDD'}}
type=raw,value=gexp-tag-{{tag}}
type=raw,value=gexp-baseref-{{base_ref}}

6
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -8,6 +8,7 @@ import * as core from '@actions/core';
import {Context} from '@actions/github/lib/context';
import {Context as ToolkitContext} from '@docker/actions-toolkit/lib/context';
import {GitHubRepo} from '@docker/actions-toolkit/lib/types/github';
import {execSync} from 'child_process';
import {Inputs} from './context';
import * as icl from './image';
@ -30,6 +31,7 @@ export class Meta {
private readonly tags: tcl.Tag[];
private readonly flavor: fcl.Flavor;
private readonly date: Date;
private readonly commit_date: Date;
constructor(inputs: Inputs, context: Context, repo: GitHubRepo) {
this.inputs = inputs;
@ -39,9 +41,16 @@ export class Meta {
this.tags = tcl.Transform(inputs.tags);
this.flavor = fcl.Transform(inputs.flavor);
this.date = new Date();
this.commit_date = this.getCommitDate();
this.version = this.getVersion();
}
private getCommitDate(): Date {
const myOutput = execSync('git show -s --format="%ci" HEAD');
return new Date(myOutput.toString());
}
private getVersion(): Version {
let version: Version = {
main: undefined,
@ -359,6 +368,7 @@ export class Meta {
private setGlobalExp(val): string {
const context = this.context;
const currentDate = this.date;
const commitDate = this.commit_date;
return handlebars.compile(val)({
branch: function () {
if (!/^refs\/heads\//.test(context.ref)) {
@ -421,6 +431,20 @@ export class Meta {
}
});
return m.tz(tz).format(format);
},
commit_date: function (format, options) {
const m = moment(commitDate);
let tz = 'UTC';
Object.keys(options.hash).forEach(key => {
switch (key) {
case 'tz':
tz = options.hash[key];
break;
default:
throw new Error(`Unknown ${key} attribute`);
}
});
return m.tz(tz).format(format);
}
});
}