mirror of
https://github.com/docker/metadata-action.git
synced 2026-11-16 14:55:01 +08:00
add commit count expression for Git context
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
8e671d84a3
commit
3b768d063f
5 changed files with 83 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ type GithubContext = typeof GitHub.context;
|
|||
|
||||
export interface Context extends GithubContext {
|
||||
commitDate: Date;
|
||||
commitCount?: number;
|
||||
}
|
||||
|
||||
export interface Inputs {
|
||||
|
|
@ -90,6 +91,7 @@ async function getContextFromGit(workdir?: string): Promise<Context> {
|
|||
|
||||
return {
|
||||
commitDate: await Git.commitDate(ctx.sha, workdir),
|
||||
commitCount: await Git.commitCount(workdir),
|
||||
...ctx
|
||||
} as Context;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -416,6 +416,12 @@ export class Meta {
|
|||
sha: function () {
|
||||
return Meta.shortSha(context.sha);
|
||||
},
|
||||
commit_count: function () {
|
||||
if (context.commitCount === undefined) {
|
||||
throw new Error('The commit_count expression requires Git context (context: git or git:<path>)');
|
||||
}
|
||||
return context.commitCount;
|
||||
},
|
||||
base_ref: function () {
|
||||
if (/^refs\/tags\//.test(context.ref) && context.payload?.base_ref != undefined) {
|
||||
return context.payload.base_ref.replace(/^refs\/heads\//g, '');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue