mirror of
https://gitea.com/docker/metadata-action.git
synced 2024-11-22 03:59:33 +01:00
Adding helpers for semver usage
Signed-off-by: Mehdi Benadel <mehdi.benadel@gmail.com>
This commit is contained in:
parent
8e5442c4ef
commit
17558baab6
5 changed files with 120 additions and 16 deletions
30
__tests__/fixtures/event_tag_v9.5.7-alpha.2+fork.3.1.8.env
Normal file
30
__tests__/fixtures/event_tag_v9.5.7-alpha.2+fork.3.1.8.env
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
GITHUB_ACTION=__crazy-max_ghaction-dump-context
|
||||||
|
GITHUB_ACTIONS=true
|
||||||
|
GITHUB_ACTION_PATH=/home/runner/work/_actions/crazy-max/ghaction-dump-context/v1
|
||||||
|
GITHUB_ACTION_REF=
|
||||||
|
GITHUB_ACTION_REPOSITORY=
|
||||||
|
GITHUB_ACTOR=crazy-max
|
||||||
|
GITHUB_API_URL=https://api.github.com
|
||||||
|
GITHUB_BASE_REF=
|
||||||
|
GITHUB_ENV=/home/runner/work/_temp/_runner_file_commands/set_env_7703d3cb-84db-438f-9f97-46e159388a55
|
||||||
|
GITHUB_EVENT_NAME=push
|
||||||
|
#GITHUB_EVENT_PATH=./__tests__/fixtures/event_tag_v9.5.7-alpha.2+fork.3.1.8.json
|
||||||
|
GITHUB_GRAPHQL_URL=https://api.github.com/graphql
|
||||||
|
GITHUB_HEAD_REF=
|
||||||
|
GITHUB_JOB=test
|
||||||
|
GITHUB_PATH=/home/runner/work/_temp/_runner_file_commands/add_path_7703d3cb-84db-438f-9f97-46e159388a55
|
||||||
|
GITHUB_REF=refs/tags/v9.5.7-alpha.2+fork.3.1.8
|
||||||
|
GITHUB_REF_NAME=v9.5.7-alpha.2+fork.3.1.8
|
||||||
|
GITHUB_REF_PROTECTED=false
|
||||||
|
GITHUB_REF_TYPE=tag
|
||||||
|
GITHUB_REPOSITORY=docker/test-docker-action
|
||||||
|
GITHUB_REPOSITORY_OWNER=docker
|
||||||
|
GITHUB_RETENTION_DAYS=90
|
||||||
|
GITHUB_RUN_ATTEMPT=1
|
||||||
|
GITHUB_RUN_ID=2188815933
|
||||||
|
GITHUB_RUN_NUMBER=21
|
||||||
|
GITHUB_SERVER_URL=https://github.com
|
||||||
|
GITHUB_SHA=860c1904a1ce19322e91ac35af1ab07466440c37
|
||||||
|
GITHUB_STEP_SUMMARY=/home/runner/work/_temp/_runner_file_commands/step_summary_7703d3cb-84db-438f-9f97-46e159388a55
|
||||||
|
GITHUB_WORKFLOW=metadata
|
||||||
|
GITHUB_WORKSPACE=/home/runner/work/test-docker-action/test-docker-action
|
|
@ -1201,13 +1201,15 @@ describe('tag', () => {
|
||||||
]
|
]
|
||||||
} as Inputs,
|
} as Inputs,
|
||||||
{
|
{
|
||||||
main: '2.0.8-beta.67',
|
main: '2.0',
|
||||||
partial: [],
|
partial: ["2"],
|
||||||
latest: false
|
latest: false
|
||||||
} as Version,
|
} as Version,
|
||||||
[
|
[
|
||||||
'org/app:2.0.8-beta.67',
|
'org/app:2.0',
|
||||||
'ghcr.io/user/app:2.0.8-beta.67'
|
'org/app:2',
|
||||||
|
'ghcr.io/user/app:2.0',
|
||||||
|
'ghcr.io/user/app:2'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||||
|
@ -1217,7 +1219,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=2.0.8-beta.67"
|
"org.opencontainers.image.version=2.0"
|
||||||
],
|
],
|
||||||
undefined
|
undefined
|
||||||
],
|
],
|
||||||
|
@ -1292,6 +1294,66 @@ describe('tag', () => {
|
||||||
],
|
],
|
||||||
undefined
|
undefined
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'tag15.1',
|
||||||
|
'event_tag_v9.5.7-alpha.2+fork.3.1.8.env',
|
||||||
|
{
|
||||||
|
images: ['org/app', 'ghcr.io/user/app'],
|
||||||
|
tags: [
|
||||||
|
`type=semver,pattern={{> completeVersion}}`
|
||||||
|
]
|
||||||
|
} as Inputs,
|
||||||
|
{
|
||||||
|
main: '9.5.7-alpha.2+fork.3.1.8',
|
||||||
|
partial: [],
|
||||||
|
latest: false
|
||||||
|
} as Version,
|
||||||
|
[
|
||||||
|
'org/app:9.5.7-alpha.2+fork.3.1.8',
|
||||||
|
'ghcr.io/user/app:9.5.7-alpha.2+fork.3.1.8'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||||
|
"org.opencontainers.image.description=This your first repo!",
|
||||||
|
"org.opencontainers.image.licenses=MIT",
|
||||||
|
"org.opencontainers.image.revision=860c1904a1ce19322e91ac35af1ab07466440c37",
|
||||||
|
"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=9.5.7-alpha.2+fork.3.1.8",
|
||||||
|
],
|
||||||
|
undefined
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'tag15.1',
|
||||||
|
'event_tag_v9.5.7-alpha.2+fork.3.1.8.env',
|
||||||
|
{
|
||||||
|
images: ['org/app', 'ghcr.io/user/app'],
|
||||||
|
tags: [
|
||||||
|
`type=semver,pattern={{> buildMetadata}}{{> prereleaseMetadata}}.{{major}}.{{minor}}.{{patch}}`
|
||||||
|
]
|
||||||
|
} as Inputs,
|
||||||
|
{
|
||||||
|
main: '+fork.3.1.8-alpha.2.9.5.7',
|
||||||
|
partial: [],
|
||||||
|
latest: false
|
||||||
|
} as Version,
|
||||||
|
[
|
||||||
|
'org/app:+fork.3.1.8-alpha.2.9.5.7',
|
||||||
|
'ghcr.io/user/app:+fork.3.1.8-alpha.2.9.5.7'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||||
|
"org.opencontainers.image.description=This your first repo!",
|
||||||
|
"org.opencontainers.image.licenses=MIT",
|
||||||
|
"org.opencontainers.image.revision=860c1904a1ce19322e91ac35af1ab07466440c37",
|
||||||
|
"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=+fork.3.1.8-alpha.2.9.5.7",
|
||||||
|
],
|
||||||
|
undefined
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'tag16',
|
'tag16',
|
||||||
'event_tag_v1.1.1.env',
|
'event_tag_v1.1.1.env',
|
||||||
|
|
2
dist/index.js
generated
vendored
2
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
30
src/meta.ts
30
src/meta.ts
|
@ -156,17 +156,29 @@ export class Meta {
|
||||||
const sver = semver.parse(vraw, {
|
const sver = semver.parse(vraw, {
|
||||||
loose: true
|
loose: true
|
||||||
});
|
});
|
||||||
if (semver.prerelease(vraw)) {
|
|
||||||
if (Meta.isRawStatement(tag.attrs['pattern'])) {
|
const hbEnv = handlebars.create();
|
||||||
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
|
||||||
} else {
|
hbEnv.registerPartial('prereleaseMetadata', (data: semver.SemVer) => {
|
||||||
vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
|
return data.prerelease.length > 0 ? '-' + data.prerelease.join('.') : '';
|
||||||
}
|
});
|
||||||
} else {
|
|
||||||
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
hbEnv.registerPartial('buildMetadata', (data: semver.SemVer) => {
|
||||||
|
return data.build.length > 0 ? '+' + data.build.join('.') : '';
|
||||||
|
});
|
||||||
|
|
||||||
|
hbEnv.registerPartial('completeVersion', (data: semver.SemVer) => {
|
||||||
|
return [data.major, data.minor, data.patch].join('.') + (data.prerelease.length > 0 ? '-' + data.prerelease.join('.') : '') + (data.build.length > 0 ? '+' + data.build.join('.') : '');
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!semver.prerelease(vraw)) {
|
||||||
latest = true;
|
latest = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hbTemplate = hbEnv.compile(tag.attrs['pattern']);
|
||||||
|
|
||||||
|
vraw = this.setValue(hbTemplate(sver), tag);
|
||||||
|
|
||||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true');
|
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,6 +603,6 @@ export class Meta {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static sanitizeTag(tag: string): string {
|
private static sanitizeTag(tag: string): string {
|
||||||
return tag.replace(/[^a-zA-Z0-9._-]+/g, '-');
|
return tag.replace(/[^a-zA-Z0-9+._-]+/g, '-');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue