mirror of
https://gitea.com/docker/metadata-action.git
synced 2024-11-22 03:59:33 +01:00
wip
Signed-off-by: Trim21 <trim21.me@gmail.com>
This commit is contained in:
parent
35e9aff4f5
commit
27abb2813b
4 changed files with 29 additions and 4 deletions
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
|
@ -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
6
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
24
src/meta.ts
24
src/meta.ts
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue