Skip to content

Commit 9b90a2e

Browse files
authored
Merge pull request #467 from crazy-max/increase-short-sha-size
increase short commit hash length to 12 for uniqueness
2 parents d31acd5 + aa662cf commit 9b90a2e

File tree

6 files changed

+138
-72
lines changed

6 files changed

+138
-72
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,3 +549,33 @@ jobs:
549549
cwd://${{ steps.docker_meta.outputs.bake-file-labels }}
550550
targets: |
551551
release
552+
553+
sha-short:
554+
runs-on: ubuntu-latest
555+
strategy:
556+
fail-fast: false
557+
matrix:
558+
short-length:
559+
- ''
560+
- 16
561+
steps:
562+
-
563+
name: Checkout
564+
uses: actions/checkout@v4
565+
-
566+
name: Set up Docker Buildx
567+
uses: docker/setup-buildx-action@v3
568+
with:
569+
version: ${{ env.BUILDX_VERSION }}
570+
driver: docker
571+
-
572+
name: Docker meta
573+
uses: ./
574+
with:
575+
images: |
576+
${{ env.DOCKER_IMAGE }}
577+
ghcr.io/name/app
578+
tags: |
579+
type=sha
580+
env:
581+
DOCKER_METADATA_SHORT_SHA_LENGTH: ${{ matrix.short-length }}

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,11 @@ So it can be used with our [Docker Build Push action](https://github.com/docker/
360360

361361
### environment variables
362362

363-
| Name | Type | Description |
364-
|--------------------------------------|--------|------------------------------------------------------------------------------------------------------------|
365-
| `DOCKER_METADATA_PR_HEAD_SHA` | Bool | If `true`, set associated head SHA instead of commit SHA that triggered the workflow on pull request event |
366-
| `DOCKER_METADATA_ANNOTATIONS_LEVELS` | String | Comma separated list of annotations levels to set for annotations output separated (default `manifest`) |
363+
| Name | Type | Description |
364+
|--------------------------------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------|
365+
| `DOCKER_METADATA_PR_HEAD_SHA` | Bool | If `true`, set associated head SHA instead of commit SHA that triggered the workflow on pull request event |
366+
| `DOCKER_METADATA_SHORT_SHA_LENGTH` | Number | Specifies the length of the [short commit SHA](#typesha) to ensure uniqueness. Default is `12`, but can be increased for larger repositories. |
367+
| `DOCKER_METADATA_ANNOTATIONS_LEVELS` | String | Comma separated list of annotations levels to set for annotations output separated (default `manifest`) |
367368

368369
## `context` input
369370

@@ -722,7 +723,26 @@ tags: |
722723
type=sha,format=long
723724
```
724725

725-
Output Git short commit (or long if specified) as Docker tag like `sha-ad132f5`.
726+
Output Git short commit (or long if specified) as Docker tag like
727+
`sha-860c1904a1ce`.
728+
729+
By default, the length of the short commit SHA is `12` characters. You can
730+
increase this length for larger repositories by setting the
731+
[`DOCKER_METADATA_SHORT_SHA_LENGTH` environment variable](#environment-variables):
732+
733+
```yaml
734+
-
735+
name: Docker meta
736+
id: meta
737+
uses: docker/metadata-action@v5
738+
with:
739+
images: |
740+
name/app
741+
tags: |
742+
type=sha
743+
env:
744+
DOCKER_METADATA_SHORT_SHA_LENGTH: 16
745+
```
726746

727747
Extended attributes and default values:
728748

0 commit comments

Comments
 (0)