From bb9c6dd583a49d62ae562ac4ffd1170304febcd1 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Thu, 31 Oct 2024 10:11:17 +0100 Subject: [PATCH] increase short commit hash length to 12 for uniqueness Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- README.md | 3 +- __tests__/meta.test.ts | 126 ++++++++++++++++++++--------------------- src/meta.ts | 4 +- 3 files changed, 67 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 4ee7399..1ed98cd 100644 --- a/README.md +++ b/README.md @@ -722,7 +722,8 @@ tags: | type=sha,format=long ``` -Output Git short commit (or long if specified) as Docker tag like `sha-ad132f5`. +Output Git short commit (or long if specified) as Docker tag like +`sha-860c1904a1ce`. Extended attributes and default values: diff --git a/__tests__/meta.test.ts b/__tests__/meta.test.ts index 5a03f79..fb00174 100644 --- a/__tests__/meta.test.ts +++ b/__tests__/meta.test.ts @@ -310,14 +310,14 @@ describe('push', () => { } as Inputs, { main: 'dev', - partial: ['sha-860c190'], + partial: ['sha-860c1904a1ce'], latest: false } as Version, [ 'org/app:dev', - 'org/app:sha-860c190', + 'org/app:sha-860c1904a1ce', 'ghcr.io/user/app:dev', - 'ghcr.io/user/app:sha-860c190' + 'ghcr.io/user/app:sha-860c1904a1ce' ], [ "org.opencontainers.image.created=2020-01-10T00:30:00.000Z", @@ -343,14 +343,14 @@ describe('push', () => { } as Inputs, { main: 'edge', - partial: ['sha-2665741'], + partial: ['sha-266574110acf'], latest: false } as Version, [ 'org/app:edge', - 'org/app:sha-2665741', + 'org/app:sha-266574110acf', 'ghcr.io/user/app:edge', - 'ghcr.io/user/app:sha-2665741' + 'ghcr.io/user/app:sha-266574110acf' ], [ "org.opencontainers.image.created=2020-01-10T00:30:00.000Z", @@ -376,14 +376,14 @@ describe('push', () => { } as Inputs, { main: 'edge', - partial: ['sha-860c190'], + partial: ['sha-860c1904a1ce'], latest: false } as Version, [ 'org/app:edge', - 'org/app:sha-860c190', + 'org/app:sha-860c1904a1ce', 'ghcr.io/user/app:edge', - 'ghcr.io/user/app:sha-860c190' + 'ghcr.io/user/app:sha-860c1904a1ce' ], [ "org.opencontainers.image.created=2020-01-10T00:30:00.000Z", @@ -408,13 +408,13 @@ describe('push', () => { ], } as Inputs, { - main: 'sha-2665741', + main: 'sha-266574110acf', partial: [], latest: false } as Version, [ - 'org/app:sha-2665741', - 'ghcr.io/user/app:sha-2665741' + 'org/app:sha-266574110acf', + 'ghcr.io/user/app:sha-266574110acf' ], [ "org.opencontainers.image.created=2020-01-10T00:30:00.000Z", @@ -424,7 +424,7 @@ describe('push', () => { "org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.title=Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World", - "org.opencontainers.image.version=sha-2665741" + "org.opencontainers.image.version=sha-266574110acf" ], undefined ], @@ -439,13 +439,13 @@ describe('push', () => { ], } as Inputs, { - main: 'sha-983315b', + main: 'sha-983315b5e8d4', partial: [], latest: false } as Version, [ - 'org/app:sha-983315b', - 'ghcr.io/user/app:sha-983315b' + 'org/app:sha-983315b5e8d4', + 'ghcr.io/user/app:sha-983315b5e8d4' ], [ "org.opencontainers.image.created=2020-01-10T00:30:00.000Z", @@ -455,7 +455,7 @@ describe('push', () => { "org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.title=Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World", - "org.opencontainers.image.version=sha-983315b" + "org.opencontainers.image.version=sha-983315b5e8d4" ], undefined ], @@ -1341,17 +1341,17 @@ describe('tag', () => { } as Inputs, { main: '1.0.0', - partial: ['1.0', 'sha-860c190'], + partial: ['1.0', 'sha-860c1904a1ce'], latest: true } as Version, [ 'org/app:1.0.0', 'org/app:1.0', - 'org/app:sha-860c190', + 'org/app:sha-860c1904a1ce', 'org/app:latest', 'ghcr.io/user/app:1.0.0', 'ghcr.io/user/app:1.0', - 'ghcr.io/user/app:sha-860c190', + 'ghcr.io/user/app:sha-860c1904a1ce', 'ghcr.io/user/app:latest' ], [ @@ -1381,17 +1381,17 @@ describe('tag', () => { } as Inputs, { main: '1.0.0', - partial: ['1.0', 'sha-860c190'], + partial: ['1.0', 'sha-860c1904a1ce'], latest: true } as Version, [ 'org/app:1.0.0', 'org/app:1.0', - 'org/app:sha-860c190', + 'org/app:sha-860c1904a1ce', 'org/app:latest', 'ghcr.io/user/app:1.0.0', 'ghcr.io/user/app:1.0', - 'ghcr.io/user/app:sha-860c190', + 'ghcr.io/user/app:sha-860c1904a1ce', 'ghcr.io/user/app:latest' ], [ @@ -1423,17 +1423,17 @@ describe('tag', () => { } as Inputs, { main: '1.0.0-dev', - partial: ['1.0', 'sha-860c190-dev'], + partial: ['1.0', 'sha-860c1904a1ce-dev'], latest: true } as Version, [ 'org/app:1.0.0-dev', 'org/app:1.0', - 'org/app:sha-860c190-dev', + 'org/app:sha-860c1904a1ce-dev', 'org/app:latest', 'ghcr.io/user/app:1.0.0-dev', 'ghcr.io/user/app:1.0', - 'ghcr.io/user/app:sha-860c190-dev', + 'ghcr.io/user/app:sha-860c1904a1ce-dev', 'ghcr.io/user/app:latest' ], [ @@ -1460,16 +1460,16 @@ describe('tag', () => { ] } as Inputs, { - main: 'v1.1.1-860c190-foo', + main: 'v1.1.1-860c1904a1ce-foo', partial: [ 'master-foo' ], latest: false } as Version, [ - 'org/app:v1.1.1-860c190-foo', + 'org/app:v1.1.1-860c1904a1ce-foo', 'org/app:master-foo', - 'ghcr.io/user/app:v1.1.1-860c190-foo', + 'ghcr.io/user/app:v1.1.1-860c1904a1ce-foo', 'ghcr.io/user/app:master-foo' ], [ @@ -1480,7 +1480,7 @@ describe('tag', () => { "org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.title=Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World", - "org.opencontainers.image.version=v1.1.1-860c190-foo" + "org.opencontainers.image.version=v1.1.1-860c1904a1ce-foo" ], undefined ], @@ -2334,14 +2334,14 @@ describe('pr', () => { } as Inputs, { main: 'pr-15', - partial: ['sha-a9c8c58'], + partial: ['sha-a9c8c5828b91'], latest: false } as Version, [ 'org/app:pr-15', - 'org/app:sha-a9c8c58', + 'org/app:sha-a9c8c5828b91', 'ghcr.io/user/app:pr-15', - 'ghcr.io/user/app:sha-a9c8c58' + 'ghcr.io/user/app:sha-a9c8c5828b91' ], [ "org.opencontainers.image.created=2020-01-10T00:30:00.000Z", @@ -2366,14 +2366,14 @@ describe('pr', () => { ] } as Inputs, { - main: 'sha-a9c8c58', + main: 'sha-a9c8c5828b91', partial: ['pr-15'], latest: false } as Version, [ - 'org/app:sha-a9c8c58', + 'org/app:sha-a9c8c5828b91', 'org/app:pr-15', - 'ghcr.io/user/app:sha-a9c8c58', + 'ghcr.io/user/app:sha-a9c8c5828b91', 'ghcr.io/user/app:pr-15' ], [ @@ -2384,7 +2384,7 @@ describe('pr', () => { "org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.title=Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World", - "org.opencontainers.image.version=sha-a9c8c58" + "org.opencontainers.image.version=sha-a9c8c5828b91" ], undefined ], @@ -2467,14 +2467,14 @@ describe('pr', () => { ] } as Inputs, { - main: 'sha-2665741', + main: 'sha-266574110acf', partial: ['pr-15'], latest: false } as Version, [ - 'org/app:sha-2665741', + 'org/app:sha-266574110acf', 'org/app:pr-15', - 'ghcr.io/user/app:sha-2665741', + 'ghcr.io/user/app:sha-266574110acf', 'ghcr.io/user/app:pr-15' ], [ @@ -2485,7 +2485,7 @@ describe('pr', () => { "org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.title=Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World", - "org.opencontainers.image.version=sha-2665741" + "org.opencontainers.image.version=sha-266574110acf" ], undefined ], @@ -2539,14 +2539,14 @@ describe('pr', () => { { main: 'pr-15', partial: [ - 'sha-2665741', + 'sha-266574110acf', 'sha-266574110acf203503badf966df2ea24b5d732d7' ], latest: false } as Version, [ 'org/app:pr-15', - 'org/app:sha-2665741', + 'org/app:sha-266574110acf', 'org/app:sha-266574110acf203503badf966df2ea24b5d732d7' ], [ @@ -2691,14 +2691,14 @@ describe('pr-head-sha', () => { } as Inputs, { main: 'pr-15', - partial: ['sha-3370e22'], + partial: ['sha-3370e228f220'], latest: false } as Version, [ 'org/app:pr-15', - 'org/app:sha-3370e22', + 'org/app:sha-3370e228f220', 'ghcr.io/user/app:pr-15', - 'ghcr.io/user/app:sha-3370e22' + 'ghcr.io/user/app:sha-3370e228f220' ], [ "org.opencontainers.image.created=2020-01-10T00:30:00.000Z", @@ -2722,14 +2722,14 @@ describe('pr-head-sha', () => { ] } as Inputs, { - main: 'sha-3370e22', + main: 'sha-3370e228f220', partial: ['pr-15'], latest: false } as Version, [ - 'org/app:sha-3370e22', + 'org/app:sha-3370e228f220', 'org/app:pr-15', - 'ghcr.io/user/app:sha-3370e22', + 'ghcr.io/user/app:sha-3370e228f220', 'ghcr.io/user/app:pr-15' ], [ @@ -2740,7 +2740,7 @@ describe('pr-head-sha', () => { "org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.title=Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World", - "org.opencontainers.image.version=sha-3370e22" + "org.opencontainers.image.version=sha-3370e228f220" ] ], [ @@ -2820,14 +2820,14 @@ describe('pr-head-sha', () => { ] } as Inputs, { - main: 'sha-3370e22', + main: 'sha-3370e228f220', partial: ['pr-15'], latest: false } as Version, [ - 'org/app:sha-3370e22', + 'org/app:sha-3370e228f220', 'org/app:pr-15', - 'ghcr.io/user/app:sha-3370e22', + 'ghcr.io/user/app:sha-3370e228f220', 'ghcr.io/user/app:pr-15' ], [ @@ -2838,7 +2838,7 @@ describe('pr-head-sha', () => { "org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.title=Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World", - "org.opencontainers.image.version=sha-3370e22" + "org.opencontainers.image.version=sha-3370e228f220" ] ], [ @@ -2890,14 +2890,14 @@ describe('pr-head-sha', () => { { main: 'pr-15', partial: [ - 'sha-3370e22', + 'sha-3370e228f220', 'sha-3370e228f2209994d57af4427fe64e71bb79ac96' ], latest: false } as Version, [ 'org/app:pr-15', - 'org/app:sha-3370e22', + 'org/app:sha-3370e228f220', 'org/app:sha-3370e228f2209994d57af4427fe64e71bb79ac96' ], [ @@ -3121,14 +3121,14 @@ describe('schedule', () => { } as Inputs, { main: 'nightly', - partial: ['sha-860c190'], + partial: ['sha-860c1904a1ce'], latest: false } as Version, [ 'org/app:nightly', - 'org/app:sha-860c190', + 'org/app:sha-860c1904a1ce', 'ghcr.io/user/app:nightly', - 'ghcr.io/user/app:sha-860c190' + 'ghcr.io/user/app:sha-860c1904a1ce' ], [ "org.opencontainers.image.created=2020-01-10T00:30:00.000Z", @@ -3154,7 +3154,7 @@ describe('schedule', () => { ] } as Inputs, { - main: 'sha-860c190', + main: 'sha-860c1904a1ce', partial: [ 'nightly', 'defbranch' @@ -3162,10 +3162,10 @@ describe('schedule', () => { latest: false } as Version, [ - 'org/app:sha-860c190', + 'org/app:sha-860c1904a1ce', 'org/app:nightly', 'org/app:defbranch', - 'ghcr.io/user/app:sha-860c190', + 'ghcr.io/user/app:sha-860c1904a1ce', 'ghcr.io/user/app:nightly', 'ghcr.io/user/app:defbranch' ], @@ -3177,7 +3177,7 @@ describe('schedule', () => { "org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.title=Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World", - "org.opencontainers.image.version=sha-860c190" + "org.opencontainers.image.version=sha-860c1904a1ce" ], undefined ], diff --git a/src/meta.ts b/src/meta.ts index f7d47a6..d80fa31 100644 --- a/src/meta.ts +++ b/src/meta.ts @@ -307,7 +307,7 @@ export class Meta { let val = this.context.sha; if (tag.attrs['format'] === tcl.ShaFormat.Short) { - val = this.context.sha.substring(0, 7); + val = this.context.sha.substring(0, 12); } const vraw = this.setValue(val, tag); @@ -373,7 +373,7 @@ export class Meta { return context.ref.replace(/^refs\/tags\//g, ''); }, sha: function () { - return context.sha.substring(0, 7); + return context.sha.substring(0, 12); }, base_ref: function () { if (/^refs\/tags\//.test(context.ref) && context.payload?.base_ref != undefined) {