mirror of
https://code.forgejo.org/docker/metadata-action.git
synced 2025-08-11 00:20:53 +00:00
PEP 440 support
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
8a0bc9fddd
commit
a1770d2eba
14 changed files with 10946 additions and 6 deletions
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue