Compare commits

..

6 Commits

Author SHA1 Message Date
CrazyMax
369eb591f4 Merge pull request #480 from crazy-max/back-to-sha-7
back to commit sha length of 7
2024-11-19 18:26:39 +01:00
CrazyMax
7d870ce854 chore: update generated content
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-11-19 18:24:29 +01:00
CrazyMax
e44a9cd788 back to commit sha length of 7
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-11-19 18:24:29 +01:00
CrazyMax
8cb0002d6a Merge pull request #478 from crazy-max/commit-date-request
commiter_date: fix github api request fallback
2024-11-19 17:54:49 +01:00
CrazyMax
e01ddd3e3c chore: update generated content
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-11-19 17:22:11 +01:00
CrazyMax
861d98a3bd commiter_date: fix github api request fallback
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-11-19 17:22:11 +01:00
7 changed files with 103 additions and 82 deletions

View File

@@ -361,11 +361,11 @@ So it can be used with our [Docker Build Push action](https://github.com/docker/
### environment variables ### environment variables
| Name | Type | Description | | Name | Type | Description |
|--------------------------------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------| |--------------------------------------|--------|----------------------------------------------------------------------------------------------------------------------------------------------|
| `DOCKER_METADATA_PR_HEAD_SHA` | Bool | If `true`, set associated head SHA instead of commit SHA that triggered the workflow on pull request event | | `DOCKER_METADATA_PR_HEAD_SHA` | Bool | If `true`, set associated head SHA instead of commit SHA that triggered the workflow on pull request event |
| `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. | | `DOCKER_METADATA_SHORT_SHA_LENGTH` | Number | Specifies the length of the [short commit SHA](#typesha) to ensure uniqueness. Default is `7`, but can be increased for larger repositories. |
| `DOCKER_METADATA_ANNOTATIONS_LEVELS` | String | Comma separated list of annotations levels to set for annotations output separated (default `manifest`) | | `DOCKER_METADATA_ANNOTATIONS_LEVELS` | String | Comma separated list of annotations levels to set for annotations output separated (default `manifest`) |
## `context` input ## `context` input
@@ -725,9 +725,9 @@ tags: |
``` ```
Output Git short commit (or long if specified) as Docker tag like Output Git short commit (or long if specified) as Docker tag like
`sha-860c1904a1ce`. `sha-860c190`.
By default, the length of the short commit SHA is `12` characters. You can By default, the length of the short commit SHA is `7` characters. You can
increase this length for larger repositories by setting the increase this length for larger repositories by setting the
[`DOCKER_METADATA_SHORT_SHA_LENGTH` environment variable](#environment-variables): [`DOCKER_METADATA_SHORT_SHA_LENGTH` environment variable](#environment-variables):
@@ -742,7 +742,7 @@ increase this length for larger repositories by setting the
tags: | tags: |
type=sha type=sha
env: env:
DOCKER_METADATA_SHORT_SHA_LENGTH: 16 DOCKER_METADATA_SHORT_SHA_LENGTH: 12
``` ```
Extended attributes and default values: Extended attributes and default values:

View File

@@ -205,5 +205,19 @@ export const context = {
}; };
export const getOctokit = jest.fn(() => ({ export const getOctokit = jest.fn(() => ({
request: () => Promise.resolve({data: {committer: {date: '2024-11-13T13:42:28Z'}}}) rest: {
repos: {
getCommit: jest.fn(() =>
Promise.resolve({
data: {
commit: {
committer: {
date: '2024-11-13T13:42:28Z'
}
}
}
})
)
}
}
})); }));

View File

@@ -319,14 +319,14 @@ describe('push', () => {
} as Inputs, } as Inputs,
{ {
main: 'dev', main: 'dev',
partial: ['sha-860c1904a1ce'], partial: ['sha-860c190'],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:dev', 'org/app:dev',
'org/app:sha-860c1904a1ce', 'org/app:sha-860c190',
'ghcr.io/user/app:dev', 'ghcr.io/user/app:dev',
'ghcr.io/user/app:sha-860c1904a1ce' 'ghcr.io/user/app:sha-860c190'
], ],
[ [
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z", "org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
@@ -352,14 +352,14 @@ describe('push', () => {
} as Inputs, } as Inputs,
{ {
main: 'edge', main: 'edge',
partial: ['sha-266574110acf'], partial: ['sha-2665741'],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:edge', 'org/app:edge',
'org/app:sha-266574110acf', 'org/app:sha-2665741',
'ghcr.io/user/app:edge', 'ghcr.io/user/app:edge',
'ghcr.io/user/app:sha-266574110acf' 'ghcr.io/user/app:sha-2665741'
], ],
[ [
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z", "org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
@@ -385,14 +385,14 @@ describe('push', () => {
} as Inputs, } as Inputs,
{ {
main: 'edge', main: 'edge',
partial: ['sha-860c1904a1ce'], partial: ['sha-860c190'],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:edge', 'org/app:edge',
'org/app:sha-860c1904a1ce', 'org/app:sha-860c190',
'ghcr.io/user/app:edge', 'ghcr.io/user/app:edge',
'ghcr.io/user/app:sha-860c1904a1ce' 'ghcr.io/user/app:sha-860c190'
], ],
[ [
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z", "org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
@@ -417,13 +417,13 @@ describe('push', () => {
], ],
} as Inputs, } as Inputs,
{ {
main: 'sha-266574110acf', main: 'sha-2665741',
partial: [], partial: [],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:sha-266574110acf', 'org/app:sha-2665741',
'ghcr.io/user/app:sha-266574110acf' 'ghcr.io/user/app:sha-2665741'
], ],
[ [
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z", "org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
@@ -433,7 +433,7 @@ describe('push', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.title=Hello-World", "org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=sha-266574110acf" "org.opencontainers.image.version=sha-2665741"
], ],
undefined undefined
], ],
@@ -448,13 +448,13 @@ describe('push', () => {
], ],
} as Inputs, } as Inputs,
{ {
main: 'sha-983315b5e8d4', main: 'sha-983315b',
partial: [], partial: [],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:sha-983315b5e8d4', 'org/app:sha-983315b',
'ghcr.io/user/app:sha-983315b5e8d4' 'ghcr.io/user/app:sha-983315b'
], ],
[ [
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z", "org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
@@ -464,7 +464,7 @@ describe('push', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.title=Hello-World", "org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=sha-983315b5e8d4" "org.opencontainers.image.version=sha-983315b"
], ],
undefined undefined
], ],
@@ -1356,17 +1356,17 @@ describe('tag', () => {
} as Inputs, } as Inputs,
{ {
main: '1.0.0', main: '1.0.0',
partial: ['1.0', 'sha-860c1904a1ce'], partial: ['1.0', 'sha-860c190'],
latest: true latest: true
} as Version, } as Version,
[ [
'org/app:1.0.0', 'org/app:1.0.0',
'org/app:1.0', 'org/app:1.0',
'org/app:sha-860c1904a1ce', 'org/app:sha-860c190',
'org/app:latest', 'org/app:latest',
'ghcr.io/user/app:1.0.0', 'ghcr.io/user/app:1.0.0',
'ghcr.io/user/app:1.0', 'ghcr.io/user/app:1.0',
'ghcr.io/user/app:sha-860c1904a1ce', 'ghcr.io/user/app:sha-860c190',
'ghcr.io/user/app:latest' 'ghcr.io/user/app:latest'
], ],
[ [
@@ -1396,17 +1396,17 @@ describe('tag', () => {
} as Inputs, } as Inputs,
{ {
main: '1.0.0', main: '1.0.0',
partial: ['1.0', 'sha-860c1904a1ce'], partial: ['1.0', 'sha-860c190'],
latest: true latest: true
} as Version, } as Version,
[ [
'org/app:1.0.0', 'org/app:1.0.0',
'org/app:1.0', 'org/app:1.0',
'org/app:sha-860c1904a1ce', 'org/app:sha-860c190',
'org/app:latest', 'org/app:latest',
'ghcr.io/user/app:1.0.0', 'ghcr.io/user/app:1.0.0',
'ghcr.io/user/app:1.0', 'ghcr.io/user/app:1.0',
'ghcr.io/user/app:sha-860c1904a1ce', 'ghcr.io/user/app:sha-860c190',
'ghcr.io/user/app:latest' 'ghcr.io/user/app:latest'
], ],
[ [
@@ -1438,17 +1438,17 @@ describe('tag', () => {
} as Inputs, } as Inputs,
{ {
main: '1.0.0-dev', main: '1.0.0-dev',
partial: ['1.0', 'sha-860c1904a1ce-dev'], partial: ['1.0', 'sha-860c190-dev'],
latest: true latest: true
} as Version, } as Version,
[ [
'org/app:1.0.0-dev', 'org/app:1.0.0-dev',
'org/app:1.0', 'org/app:1.0',
'org/app:sha-860c1904a1ce-dev', 'org/app:sha-860c190-dev',
'org/app:latest', 'org/app:latest',
'ghcr.io/user/app:1.0.0-dev', 'ghcr.io/user/app:1.0.0-dev',
'ghcr.io/user/app:1.0', 'ghcr.io/user/app:1.0',
'ghcr.io/user/app:sha-860c1904a1ce-dev', 'ghcr.io/user/app:sha-860c190-dev',
'ghcr.io/user/app:latest' 'ghcr.io/user/app:latest'
], ],
[ [
@@ -1475,16 +1475,16 @@ describe('tag', () => {
] ]
} as Inputs, } as Inputs,
{ {
main: 'v1.1.1-860c1904a1ce-foo', main: 'v1.1.1-860c190-foo',
partial: [ partial: [
'master-foo' 'master-foo'
], ],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:v1.1.1-860c1904a1ce-foo', 'org/app:v1.1.1-860c190-foo',
'org/app:master-foo', 'org/app:master-foo',
'ghcr.io/user/app:v1.1.1-860c1904a1ce-foo', 'ghcr.io/user/app:v1.1.1-860c190-foo',
'ghcr.io/user/app:master-foo' 'ghcr.io/user/app:master-foo'
], ],
[ [
@@ -1495,7 +1495,7 @@ describe('tag', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.title=Hello-World", "org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=v1.1.1-860c1904a1ce-foo" "org.opencontainers.image.version=v1.1.1-860c190-foo"
], ],
undefined undefined
], ],
@@ -2349,14 +2349,14 @@ describe('pr', () => {
} as Inputs, } as Inputs,
{ {
main: 'pr-15', main: 'pr-15',
partial: ['sha-a9c8c5828b91'], partial: ['sha-a9c8c58'],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:pr-15', 'org/app:pr-15',
'org/app:sha-a9c8c5828b91', 'org/app:sha-a9c8c58',
'ghcr.io/user/app:pr-15', 'ghcr.io/user/app:pr-15',
'ghcr.io/user/app:sha-a9c8c5828b91' 'ghcr.io/user/app:sha-a9c8c58'
], ],
[ [
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z", "org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
@@ -2381,14 +2381,14 @@ describe('pr', () => {
] ]
} as Inputs, } as Inputs,
{ {
main: 'sha-a9c8c5828b91', main: 'sha-a9c8c58',
partial: ['pr-15'], partial: ['pr-15'],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:sha-a9c8c5828b91', 'org/app:sha-a9c8c58',
'org/app:pr-15', 'org/app:pr-15',
'ghcr.io/user/app:sha-a9c8c5828b91', 'ghcr.io/user/app:sha-a9c8c58',
'ghcr.io/user/app:pr-15' 'ghcr.io/user/app:pr-15'
], ],
[ [
@@ -2399,7 +2399,7 @@ describe('pr', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.title=Hello-World", "org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=sha-a9c8c5828b91" "org.opencontainers.image.version=sha-a9c8c58"
], ],
undefined undefined
], ],
@@ -2482,14 +2482,14 @@ describe('pr', () => {
] ]
} as Inputs, } as Inputs,
{ {
main: 'sha-266574110acf', main: 'sha-2665741',
partial: ['pr-15'], partial: ['pr-15'],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:sha-266574110acf', 'org/app:sha-2665741',
'org/app:pr-15', 'org/app:pr-15',
'ghcr.io/user/app:sha-266574110acf', 'ghcr.io/user/app:sha-2665741',
'ghcr.io/user/app:pr-15' 'ghcr.io/user/app:pr-15'
], ],
[ [
@@ -2500,7 +2500,7 @@ describe('pr', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.title=Hello-World", "org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=sha-266574110acf" "org.opencontainers.image.version=sha-2665741"
], ],
undefined undefined
], ],
@@ -2554,14 +2554,14 @@ describe('pr', () => {
{ {
main: 'pr-15', main: 'pr-15',
partial: [ partial: [
'sha-266574110acf', 'sha-2665741',
'sha-266574110acf203503badf966df2ea24b5d732d7' 'sha-266574110acf203503badf966df2ea24b5d732d7'
], ],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:pr-15', 'org/app:pr-15',
'org/app:sha-266574110acf', 'org/app:sha-2665741',
'org/app:sha-266574110acf203503badf966df2ea24b5d732d7' 'org/app:sha-266574110acf203503badf966df2ea24b5d732d7'
], ],
[ [
@@ -2735,14 +2735,14 @@ describe('pr-head-sha', () => {
} as Inputs, } as Inputs,
{ {
main: 'pr-15', main: 'pr-15',
partial: ['sha-3370e228f220'], partial: ['sha-3370e22'],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:pr-15', 'org/app:pr-15',
'org/app:sha-3370e228f220', 'org/app:sha-3370e22',
'ghcr.io/user/app:pr-15', 'ghcr.io/user/app:pr-15',
'ghcr.io/user/app:sha-3370e228f220' 'ghcr.io/user/app:sha-3370e22'
], ],
[ [
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z", "org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
@@ -2766,14 +2766,14 @@ describe('pr-head-sha', () => {
] ]
} as Inputs, } as Inputs,
{ {
main: 'sha-3370e228f220', main: 'sha-3370e22',
partial: ['pr-15'], partial: ['pr-15'],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:sha-3370e228f220', 'org/app:sha-3370e22',
'org/app:pr-15', 'org/app:pr-15',
'ghcr.io/user/app:sha-3370e228f220', 'ghcr.io/user/app:sha-3370e22',
'ghcr.io/user/app:pr-15' 'ghcr.io/user/app:pr-15'
], ],
[ [
@@ -2784,7 +2784,7 @@ describe('pr-head-sha', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.title=Hello-World", "org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=sha-3370e228f220" "org.opencontainers.image.version=sha-3370e22"
] ]
], ],
[ [
@@ -2864,14 +2864,14 @@ describe('pr-head-sha', () => {
] ]
} as Inputs, } as Inputs,
{ {
main: 'sha-3370e228f220', main: 'sha-3370e22',
partial: ['pr-15'], partial: ['pr-15'],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:sha-3370e228f220', 'org/app:sha-3370e22',
'org/app:pr-15', 'org/app:pr-15',
'ghcr.io/user/app:sha-3370e228f220', 'ghcr.io/user/app:sha-3370e22',
'ghcr.io/user/app:pr-15' 'ghcr.io/user/app:pr-15'
], ],
[ [
@@ -2882,7 +2882,7 @@ describe('pr-head-sha', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.title=Hello-World", "org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=sha-3370e228f220" "org.opencontainers.image.version=sha-3370e22"
] ]
], ],
[ [
@@ -2934,14 +2934,14 @@ describe('pr-head-sha', () => {
{ {
main: 'pr-15', main: 'pr-15',
partial: [ partial: [
'sha-3370e228f220', 'sha-3370e22',
'sha-3370e228f2209994d57af4427fe64e71bb79ac96' 'sha-3370e228f2209994d57af4427fe64e71bb79ac96'
], ],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:pr-15', 'org/app:pr-15',
'org/app:sha-3370e228f220', 'org/app:sha-3370e22',
'org/app:sha-3370e228f2209994d57af4427fe64e71bb79ac96' 'org/app:sha-3370e228f2209994d57af4427fe64e71bb79ac96'
], ],
[ [
@@ -3197,14 +3197,14 @@ describe('schedule', () => {
} as Inputs, } as Inputs,
{ {
main: 'nightly', main: 'nightly',
partial: ['sha-860c1904a1ce'], partial: ['sha-860c190'],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:nightly', 'org/app:nightly',
'org/app:sha-860c1904a1ce', 'org/app:sha-860c190',
'ghcr.io/user/app:nightly', 'ghcr.io/user/app:nightly',
'ghcr.io/user/app:sha-860c1904a1ce' 'ghcr.io/user/app:sha-860c190'
], ],
[ [
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z", "org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
@@ -3230,7 +3230,7 @@ describe('schedule', () => {
] ]
} as Inputs, } as Inputs,
{ {
main: 'sha-860c1904a1ce', main: 'sha-860c190',
partial: [ partial: [
'nightly', 'nightly',
'defbranch' 'defbranch'
@@ -3238,10 +3238,10 @@ describe('schedule', () => {
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:sha-860c1904a1ce', 'org/app:sha-860c190',
'org/app:nightly', 'org/app:nightly',
'org/app:defbranch', 'org/app:defbranch',
'ghcr.io/user/app:sha-860c1904a1ce', 'ghcr.io/user/app:sha-860c190',
'ghcr.io/user/app:nightly', 'ghcr.io/user/app:nightly',
'ghcr.io/user/app:defbranch' 'ghcr.io/user/app:defbranch'
], ],
@@ -3253,7 +3253,7 @@ describe('schedule', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.title=Hello-World", "org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=sha-860c1904a1ce" "org.opencontainers.image.version=sha-860c190"
], ],
undefined undefined
], ],

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -119,11 +119,18 @@ async function getCommitDateFromWorkflow(sha: string, toolkit: Toolkit): Promise
} }
// fallback to github api for commit date // fallback to github api for commit date
const commit = await toolkit.github.octokit.request('GET /repos/{owner}/{repo}/commits/{commit_sha}', { try {
commit_sha: sha, const commit = await toolkit.github.octokit.rest.repos.getCommit({
owner: GitHub.context.repo.owner, owner: GitHub.context.repo.owner,
repo: GitHub.context.repo.repo repo: GitHub.context.repo.repo,
}); ref: sha
});
return new Date(commit.data.committer.date); if (commit.data.commit.committer?.date) {
return new Date(commit.data.commit.committer.date);
}
throw new Error('Committer date not found');
} catch (error) {
core.debug(`Failed to get commit date from GitHub API: ${error.message}`);
return new Date();
}
} }

View File

@@ -13,7 +13,7 @@ import * as icl from './image';
import * as tcl from './tag'; import * as tcl from './tag';
import * as fcl from './flavor'; import * as fcl from './flavor';
const defaultShortShaLength = 12; const defaultShortShaLength = 7;
export interface Version { export interface Version {
main: string | undefined; main: string | undefined;