Skip to content

Commit

Permalink
Warn on invalid semver (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
2 people authored and GitHub committed Dec 1, 2020
1 parent ef12c77 commit 4c2760b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ jobs:
tag-semver:
runs-on: ubuntu-latest
steps:
- name: Checkout
-
name: Checkout
uses: actions/checkout@v2
- name: Docker meta
-
name: Docker meta
uses: ./
with:
images: |
Expand Down
26 changes: 26 additions & 0 deletions __tests__/meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,32 @@ describe('push tag', () => {
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_sometag.env',
{
images: ['ghcr.io/user/app'],
tagSemver: ['{{version}}', '{{major}}.{{minor}}', '{{major}}'],
} as Inputs,
{
main: 'sometag',
partial: [],
latest: true
} as Version,
[
'ghcr.io/user/app:sometag',
'ghcr.io/user/app:latest',
],
[
"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=sometag",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
])('given %p event ', tagsLabelsTest);
});

Expand Down
4 changes: 4 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as handlebars from 'handlebars';
import * as moment from 'moment';
import * as semver from 'semver';
import {Inputs} from './context';
import * as core from '@actions/core';
import {Context} from '@actions/github/lib/context';
import {ReposGetResponseData} from '@octokit/types';

Expand Down Expand Up @@ -46,6 +47,9 @@ export class Meta {
});
} else if (/^refs\/tags\//.test(this.context.ref)) {
version.main = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
if (this.inputs.tagSemver.length > 0 && !semver.valid(version.main)) {
core.warning(`${version.main} is not a valid semver. More info: https://semver.org/`);
}
if (this.inputs.tagSemver.length > 0 && semver.valid(version.main)) {
const sver = semver.parse(version.main, {
includePrerelease: true
Expand Down

0 comments on commit 4c2760b

Please sign in to comment.