mirror of
https://github.com/docker/metadata-action.git
synced 2025-07-05 09:48:24 +02:00
PEP 440 support
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
52
src/meta.ts
52
src/meta.ts
@ -2,6 +2,7 @@ import * as handlebars from 'handlebars';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import moment from 'moment';
|
||||
import * as pep440 from '@renovate/pep440';
|
||||
import * as semver from 'semver';
|
||||
import {Inputs, tmpDir} from './context';
|
||||
import {ReposGetResponseData} from './github';
|
||||
@ -62,6 +63,10 @@ export class Meta {
|
||||
version = this.procSemver(version, tag);
|
||||
break;
|
||||
}
|
||||
case tcl.Type.Pep440: {
|
||||
version = this.procPep440(version, tag);
|
||||
break;
|
||||
}
|
||||
case tcl.Type.Match: {
|
||||
version = this.procMatch(version, tag);
|
||||
break;
|
||||
@ -147,6 +152,53 @@ export class Meta {
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true');
|
||||
}
|
||||
|
||||
private procPep440(version: Version, tag: tcl.Tag): Version {
|
||||
if (!/^refs\/tags\//.test(this.context.ref) && tag.attrs['value'].length == 0) {
|
||||
return version;
|
||||
}
|
||||
|
||||
let vraw: string;
|
||||
if (tag.attrs['value'].length > 0) {
|
||||
vraw = this.setGlobalExp(tag.attrs['value']);
|
||||
} else {
|
||||
vraw = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||
}
|
||||
if (!pep440.valid(vraw)) {
|
||||
core.warning(`${vraw} does not conform to PEP 440. More info: https://www.python.org/dev/peps/pep-0440`);
|
||||
return version;
|
||||
}
|
||||
|
||||
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);
|
||||
} else {
|
||||
vraw = this.setValue(
|
||||
handlebars.compile(tag.attrs['pattern'])({
|
||||
raw: function () {
|
||||
return vraw;
|
||||
},
|
||||
version: function () {
|
||||
return pep440.clean(vraw);
|
||||
},
|
||||
major: function () {
|
||||
return pep440.major(vraw);
|
||||
},
|
||||
minor: function () {
|
||||
return pep440.minor(vraw);
|
||||
},
|
||||
patch: function () {
|
||||
return pep440.patch(vraw);
|
||||
}
|
||||
}),
|
||||
tag
|
||||
);
|
||||
latest = true;
|
||||
}
|
||||
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true');
|
||||
}
|
||||
|
||||
private procMatch(version: Version, tag: tcl.Tag): Version {
|
||||
if (!/^refs\/tags\//.test(this.context.ref) && tag.attrs['value'].length == 0) {
|
||||
return version;
|
||||
|
39
src/pep440.d.ts
vendored
Normal file
39
src/pep440.d.ts
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
interface ExplainedVersion {
|
||||
epoch: number;
|
||||
release: [number, number, number];
|
||||
pre?: [string, number];
|
||||
post?: number;
|
||||
dev?: number;
|
||||
local?: string;
|
||||
public: string;
|
||||
base_version: string;
|
||||
is_prerelease: boolean;
|
||||
is_devrelease: boolean;
|
||||
is_postrelease: boolean;
|
||||
}
|
||||
|
||||
interface Version {
|
||||
epoch: number;
|
||||
release: [number, number, number];
|
||||
pre?: [string, number] | null;
|
||||
post?: [string, number] | null;
|
||||
dev?: [string, number] | null;
|
||||
local?: Array<number> | null;
|
||||
public: string;
|
||||
base_version: string;
|
||||
}
|
||||
|
||||
declare module '@renovate/pep440' {
|
||||
function valid(version: string): string | null;
|
||||
function clean(version: string): string;
|
||||
function explain(version: string): ExplainedVersion;
|
||||
function major(input: string): string;
|
||||
function minor(input: string): string;
|
||||
function patch(input: string): string;
|
||||
function inc(input: string, release: string, preReleaseIdentifier?: string): string;
|
||||
}
|
||||
|
||||
declare module '@renovate/pep440/lib/version' {
|
||||
function stringify(parsed: Version): string;
|
||||
function parse(version: string): Version;
|
||||
}
|
@ -4,6 +4,7 @@ import * as core from '@actions/core';
|
||||
export enum Type {
|
||||
Schedule = 'schedule',
|
||||
Semver = 'semver',
|
||||
Pep440 = 'pep440',
|
||||
Match = 'match',
|
||||
Edge = 'edge',
|
||||
Ref = 'ref',
|
||||
@ -42,6 +43,7 @@ export class Tag {
|
||||
export const DefaultPriorities: Record<Type, string> = {
|
||||
[Type.Schedule]: '1000',
|
||||
[Type.Semver]: '900',
|
||||
[Type.Pep440]: '900',
|
||||
[Type.Match]: '800',
|
||||
[Type.Edge]: '700',
|
||||
[Type.Ref]: '600',
|
||||
@ -124,7 +126,8 @@ export function Parse(s: string): Tag {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Type.Semver: {
|
||||
case Type.Semver:
|
||||
case Type.Pep440: {
|
||||
if (!tag.attrs.hasOwnProperty('pattern')) {
|
||||
throw new Error(`Missing pattern attribute for ${s}`);
|
||||
}
|
||||
|
Reference in New Issue
Block a user