mirror of
https://github.com/docker/metadata-action.git
synced 2025-08-17 03:39:54 +08:00
Use RegExp to match against a Git tag instead of coerce
This commit is contained in:
@@ -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`,
|
||||
|
29
src/meta.ts
29
src/meta.ts
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user