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

@ -46,6 +46,7 @@ ___
* [`{{is_default_branch}}`](#is_default_branch)
* [`{{is_not_default_branch}}`](#is_not_default_branch)
* [`{{date '<format>' tz='<timezone>'}}`](#date-format-tztimezone)
* [`{{commit_count}}`](#commit_count)
* [`{{commit_date '<format>' tz='<timezone>'}}`](#commit_date-format-tztimezone)
* [Major version zero](#major-version-zero)
* [JSON output object](#json-output-object)
@ -908,6 +909,26 @@ Default `tz` is UTC.
| `{{date 'dddd, MMMM Do YYYY, h:mm:ss a'}}` | `Friday, January 10th 2020, 3:25:50 pm` |
| `{{date 'YYYYMMDD-HHmmss' tz='Asia/Tokyo'}}` | `20200110-093000` |
#### `{{commit_count}}`
Returns the number of commits reachable from `HEAD` in the selected Git checkout,
using `git rev-list --count HEAD`. Requires `context: git` or `context: git:<path>`;
using this expression with workflow context produces an error.
Shallow checkouts count only the available history. Use `fetch-depth: 0` to fetch
the full history when you need the complete count:
```yaml
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: docker/metadata-action@v6
with:
context: git
images: name/app
tags: type=raw,value=rev-{{commit_count}}
```
#### `{{commit_date '<format>' tz='<timezone>'}}`
Returns the date when the current git commit is committed, rendered by its