Use RegExp to match against a Git tag instead of coerce

This commit is contained in:
CrazyMax
2020-10-27 00:57:32 +01:00
parent 4a3aaf409c
commit 983124bca8
7 changed files with 62 additions and 2339 deletions

View File

@@ -5,8 +5,8 @@ export interface Inputs {
tagSha: boolean;
tagEdge: boolean;
tagEdgeBranch: string;
tagCoerceTag: string;
tagLatestMatch: string;
tagMatch: string;
tagMatchLatest: boolean;
tagSchedule: string;
sepTags: string;
sepLabels: string;
@@ -19,8 +19,8 @@ export function getInputs(): Inputs {
tagSha: /true/i.test(core.getInput('tag-sha') || 'false'),
tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'),
tagEdgeBranch: core.getInput('tag-edge-branch'),
tagCoerceTag: core.getInput('tag-coerce-tag'),
tagLatestMatch: core.getInput('tag-latest-match'),
tagMatch: core.getInput('tag-match'),
tagMatchLatest: /true/i.test(core.getInput('tag-match-latest') || 'true'),
tagSchedule: core.getInput('tag-schedule') || 'nightly',
sepTags: core.getInput('sep-tags') || `\n`,
sepLabels: core.getInput('sep-labels') || `\n`,

View File

@@ -1,6 +1,5 @@
import * as handlebars from 'handlebars';
import * as moment from 'moment';
import * as semver from 'semver';
import {Inputs} from './context';
import {Context} from '@actions/github/lib/context';
import {ReposGetResponseData} from '@octokit/types';
@@ -40,24 +39,13 @@ export class Meta {
}
});
} else if (/^refs\/tags\//.test(this.context.ref)) {
const tag = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
const sver = semver.clean(tag);
if (this.inputs.tagCoerceTag) {
const coerce = semver.coerce(tag);
if (coerce) {
version.version = handlebars.compile(this.inputs.tagCoerceTag)(coerce);
version.latest = true;
} else if (sver) {
version.version = sver;
version.latest = true;
} else {
version.version = tag;
version.version = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
if (this.inputs.tagMatch) {
const tagMatch = version.version.match(this.inputs.tagMatch);
if (tagMatch) {
version.version = tagMatch[0];
version.latest = this.inputs.tagMatchLatest;
}
} else if (sver) {
version.version = sver;
version.latest = true;
} else {
version.version = tag;
}
} else if (/^refs\/heads\//.test(this.context.ref)) {
version.version = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
@@ -68,11 +56,6 @@ export class Meta {
version.version = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
}
if (this.inputs.tagLatestMatch) {
const match = version.version?.match(new RegExp(this.inputs.tagLatestMatch));
version.latest = match !== null;
}
return version;
}