fix: handle raw statement for pep440 pre-release

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2021-12-06 17:15:06 +01:00
parent 6d7c94a41e
commit aad230bbd9
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
5 changed files with 74 additions and 8 deletions

View file

@ -404,12 +404,13 @@ attribute.
| `v1.2.3` | `v{{major}}` | `v1` |
| `v1.2.3` | `{{minor}}` | `2` |
| `v1.2.3` | `{{patch}}` | `3` |
| `v2.0.8-beta.67` | `{{raw}}` | `2.0.8-beta.67`* |
| `v2.0.8-beta.67` | `{{raw}}` | `v2.0.8-beta.67` |
| `v2.0.8-beta.67` | `{{version}}` | `2.0.8-beta.67` |
| `v2.0.8-beta.67` | `{{major}}.{{minor}}` | `2.0.8-beta.67`* |
> *Pre-release (rc, beta, alpha) will only extend `{{version}}` as tag because they are updated frequently,
> and contain many breaking changes that are (by the author's design) not yet fit for public consumption.
> *Pre-release (rc, beta, alpha) will only extend `{{version}}` (or `{{raw}}` if specified) as tag
> because they are updated frequently, and contain many breaking changes that are (by the author's design)
> not yet fit for public consumption.
Extended attributes and default values:
@ -446,15 +447,16 @@ custom value through `value` attribute.
| `v1.2.3` | `{{version}}` | `1.2.3` |
| `1.2.3` | `{{major}}.{{minor}}` | `1.2` |
| `1.2.3` | `v{{major}}` | `v1` |
| `1.2.3rc2` | `{{raw}}` | `1.2.3rc2`* |
| `v1.2.3rc2` | `{{raw}}` | `v1.2.3rc2` |
| `1.2.3rc2` | `{{version}}` | `1.2.3rc2` |
| `1.2.3rc2` | `{{major}}.{{minor}}` | `1.2.3rc2`* |
| `1.2.3post1` | `{{major}}.{{minor}}` | `1.2.3.post1`* |
| `1.2.3beta2` | `{{major}}.{{minor}}` | `1.2.3b2`* |
| `1.0dev4` | `{{major}}.{{minor}}` | `1.0.dev4`* |
> *dev/pre/post release will only extend `{{version}}` as tag because they are updated frequently,
> and contain many breaking changes that are (by the author's design) not yet fit for public consumption.
> *dev/pre/post release will only extend `{{version}}` (or `{{raw}}` if specified) as tag
> because they are updated frequently, and contain many breaking changes that are (by the author's design)
> not yet fit for public consumption.
Extended attributes and default values:

View file

@ -0,0 +1,23 @@
GITHUB_ACTION=crazy-maxghaction-dump-context
GITHUB_ACTIONS=true
GITHUB_ACTION_PATH=/home/runner/work/_actions/crazy-max/ghaction-dump-context/v1
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_6ee180c2-b331-434a-a867-89534cbefd83
GITHUB_EVENT_NAME=push
#GITHUB_EVENT_PATH=/home/runner/work/_temp/_github_workflow/event.json
GITHUB_GRAPHQL_URL=https://api.github.com/graphql
GITHUB_HEAD_REF=
GITHUB_JOB=event
GITHUB_PATH=/home/runner/work/_temp/_runner_file_commands/add_path_6ee180c2-b331-434a-a867-89534cbefd83
GITHUB_REF=refs/tags/v1.2.3rc2
GITHUB_REPOSITORY=crazy-max/test-docker-action
GITHUB_REPOSITORY_OWNER=crazy-max
GITHUB_RETENTION_DAYS=90
GITHUB_RUN_ID=325968230
GITHUB_RUN_NUMBER=4
GITHUB_SERVER_URL=https://github.com
GITHUB_SHA=90dd6032fac8bda1b6c4436a2e65de27961ed071
GITHUB_WORKFLOW=event
GITHUB_WORKSPACE=/home/runner/work/test-docker-action/test-docker-action

View file

@ -1700,6 +1700,38 @@ describe('tag', () => {
"org.opencontainers.image.licenses=MIT"
]
],
[
'tag32',
'event_tag_v1.2.3rc2.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=pep440,pattern={{raw}}`,
`type=pep440,pattern={{major}}.{{minor}}`
]
} as Inputs,
{
main: 'v1.2.3rc2',
partial: ['1.2.3rc2'],
latest: false
} as Version,
[
'org/app:v1.2.3rc2',
'org/app:1.2.3rc2',
'ghcr.io/user/app:v1.2.3rc2',
'ghcr.io/user/app:1.2.3rc2'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=v1.2.3rc2",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
])('given %p with %p event', tagsLabelsTest);
});

7
dist/index.js generated vendored
View file

@ -557,7 +557,12 @@ class Meta {
let latest = false;
const pver = pep440.explain(vraw);
if (pver.is_prerelease || pver.is_postrelease || pver.is_devrelease) {
vraw = this.setValue(pep440.clean(vraw), tag);
if (Meta.isRawStatement(tag.attrs['pattern'])) {
vraw = this.setValue(vraw, tag);
}
else {
vraw = this.setValue(pep440.clean(vraw), tag);
}
}
else {
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])({

View file

@ -175,7 +175,11 @@ export class Meta {
let latest: boolean = false;
const pver = pep440.explain(vraw);
if (pver.is_prerelease || pver.is_postrelease || pver.is_devrelease) {
vraw = this.setValue(pep440.clean(vraw), tag);
if (Meta.isRawStatement(tag.attrs['pattern'])) {
vraw = this.setValue(vraw, tag);
} else {
vraw = this.setValue(pep440.clean(vraw), tag);
}
} else {
vraw = this.setValue(
handlebars.compile(tag.attrs['pattern'])({