From aad230bbd9e00bbe791f9611c51db0a4de823b69 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 6 Dec 2021 17:15:06 +0100 Subject: [PATCH] fix: handle raw statement for pep440 pre-release Signed-off-by: CrazyMax --- README.md | 14 ++++++---- __tests__/fixtures/event_tag_v1.2.3rc2.env | 23 ++++++++++++++++ __tests__/meta.test.ts | 32 ++++++++++++++++++++++ dist/index.js | 7 ++++- src/meta.ts | 6 +++- 5 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 __tests__/fixtures/event_tag_v1.2.3rc2.env diff --git a/README.md b/README.md index d9ac0c3..b4cf7f7 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/__tests__/fixtures/event_tag_v1.2.3rc2.env b/__tests__/fixtures/event_tag_v1.2.3rc2.env new file mode 100644 index 0000000..998a3c9 --- /dev/null +++ b/__tests__/fixtures/event_tag_v1.2.3rc2.env @@ -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 diff --git a/__tests__/meta.test.ts b/__tests__/meta.test.ts index 58cdd54..1b5852b 100644 --- a/__tests__/meta.test.ts +++ b/__tests__/meta.test.ts @@ -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); }); diff --git a/dist/index.js b/dist/index.js index e21525c..de6d333 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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'])({ diff --git a/src/meta.ts b/src/meta.ts index b04e95f..52b4a2e 100644 --- a/src/meta.ts +++ b/src/meta.ts @@ -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'])({