add commit count expression for Git context

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2026-09-15 12:33:44 +02:00
parent 8e671d84a3
commit 3b768d063f
No known key found for this signature in database
GPG key ID: ADE44D8C9D44FBE4
5 changed files with 83 additions and 0 deletions

View file

@ -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;
}

View file

@ -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, '');