Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Trim21 <[email protected]>
  • Loading branch information
trim21 committed Jul 13, 2023
1 parent 35e9aff commit 27abb28
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
6 changes: 3 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions src/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
});
}
Expand Down

0 comments on commit 27abb28

Please sign in to comment.