require previous semver segment to be present for tagging, fix fully qualified semver not being tagged in additional to normalized ones, allow tag/branch tagging if != semver tag

This commit is contained in:
David Hiendl 2023-12-07 12:01:34 +01:00
parent 47fb719517
commit c2c9a6f265
2 changed files with 72 additions and 67 deletions

58
dist/index.js vendored
View File

@ -62189,7 +62189,6 @@ function writeRegistryAuthJson(registryAuthJson, targetFile) {
console.log('debug_log_auth_json:', copy);
}
console.log('LEAK INTENTIONAL config json:', gBase64.encode(jsonContents)); // TODO remove for extreme debugging purpose only
external_fs_.writeFileSync(targetFile, jsonContents);
}
@ -62199,46 +62198,44 @@ function isNonEmptyStr(str) {
function collectTags(information) {
const tags = [];
let foundSemverTag = false;
let mostSpecificSemverTag = false;
let tagPrefix = (core.getInput('tag_prefix') ?? '').trim();
let tagSuffix = (core.getInput('tag_suffix') ?? '').trim();
let tagCommitPrefix = (core.getInput('tag_commit_prefix') ?? '').trim();
// handle semver
console.log({
'tag_semver_enable' : core.getBooleanInput('tag_semver_enable'),
'tag_semver_major' : core.getBooleanInput('tag_semver_major'),
'tag_semver_minor' : core.getBooleanInput('tag_semver_minor'),
'tag_semver_patch' : core.getBooleanInput('tag_semver_patch'),
'information.semver_major': information.semver_major,
'information.semver_minor': information.semver_minor,
'information.semver_patch': information.semver_patch,
'information' : information
});
if (core.getBooleanInput('tag_semver_enable')) {
if (core.getBooleanInput('tag_semver_major') && isNonEmptyStr(information.semver_major)) {
tags.push(tagPrefix + information.semver_major);
foundSemverTag = true;
// tag semver
if (core.getBooleanInput('tag_semver_enable') && information.semver_valid) {
if (core.getBooleanInput('tag_semver_major') && information.semver_major != null) {
mostSpecificSemverTag = tagPrefix + information.semver_major;
tags.push(mostSpecificSemverTag);
if (core.getBooleanInput('tag_semver_minor') && information.semver_minor != null) {
mostSpecificSemverTag += '.' + information.semver_minor;
tags.push(mostSpecificSemverTag);
if (core.getBooleanInput('tag_semver_patch') && information.semver_patch != null) {
mostSpecificSemverTag += '.' + information.semver_patch;
tags.push(mostSpecificSemverTag);
}
if (core.getBooleanInput('tag_semver_minor') && isNonEmptyStr(information.semver_minor)) {
tags.push(tagPrefix + information.semver_minor);
foundSemverTag = true;
}
if (core.getBooleanInput('tag_semver_patch') && isNonEmptyStr(information.semver_patch)) {
tags.push(tagPrefix + information.semver_patch);
foundSemverTag = true;
}
}
// handle git tag/branch
if (core.getBooleanInput('tag_ref_normalized_enable') && foundSemverTag === false) {
if (core.getBooleanInput('tag_ref_normalized_enable')) {
// only apply tag IF it doesn't match the semver
if (isNonEmptyStr(information.git_tag)) {
// TODO normalize tag from git for docker
tags.push(tagPrefix + information.git_tag + tagSuffix);
const normalizedTag = tagPrefix + normalizeGitRefForDockerTag(information.git_tag) + tagSuffix;
if (mostSpecificSemverTag !== normalizedTag) {
tags.push(normalizedTag);
}
}
if (isNonEmptyStr(information.git_current_branch)) {
// TODO normalize branch from git for docker
tags.push(tagPrefix + information.git_current_branch + tagSuffix);
const normalizedBranch = tagPrefix + normalizeGitRefForDockerTag(information.git_current_branch) + tagSuffix;
if (mostSpecificSemverTag !== normalizedBranch) {
tags.push(normalizedBranch);
}
}
}
@ -62259,6 +62256,11 @@ function collectTags(information) {
return tags;
}
function normalizeGitRefForDockerTag(ref) {
return ref
.replaceAll('/', '-');
}
function prepareDestinations(registries, tags) {
const destinations = [];
registries.forEach((registry) => {

View File

@ -94,46 +94,44 @@ function isNonEmptyStr(str) {
export function collectTags(information) {
const tags = [];
let foundSemverTag = false;
let mostSpecificSemverTag = false;
let tagPrefix = (core.getInput('tag_prefix') ?? '').trim();
let tagSuffix = (core.getInput('tag_suffix') ?? '').trim();
let tagCommitPrefix = (core.getInput('tag_commit_prefix') ?? '').trim();
// handle semver
console.log({
'tag_semver_enable' : core.getBooleanInput('tag_semver_enable'),
'tag_semver_major' : core.getBooleanInput('tag_semver_major'),
'tag_semver_minor' : core.getBooleanInput('tag_semver_minor'),
'tag_semver_patch' : core.getBooleanInput('tag_semver_patch'),
'information.semver_major': information.semver_major,
'information.semver_minor': information.semver_minor,
'information.semver_patch': information.semver_patch,
'information' : information
});
if (core.getBooleanInput('tag_semver_enable')) {
if (core.getBooleanInput('tag_semver_major') && isNonEmptyStr(information.semver_major)) {
tags.push(tagPrefix + information.semver_major);
foundSemverTag = true;
// tag semver
if (core.getBooleanInput('tag_semver_enable') && information.semver_valid) {
if (core.getBooleanInput('tag_semver_major') && information.semver_major != null) {
mostSpecificSemverTag = tagPrefix + information.semver_major;
tags.push(mostSpecificSemverTag);
if (core.getBooleanInput('tag_semver_minor') && information.semver_minor != null) {
mostSpecificSemverTag += '.' + information.semver_minor;
tags.push(mostSpecificSemverTag);
if (core.getBooleanInput('tag_semver_patch') && information.semver_patch != null) {
mostSpecificSemverTag += '.' + information.semver_patch;
tags.push(mostSpecificSemverTag);
}
if (core.getBooleanInput('tag_semver_minor') && isNonEmptyStr(information.semver_minor)) {
tags.push(tagPrefix + information.semver_minor);
foundSemverTag = true;
}
if (core.getBooleanInput('tag_semver_patch') && isNonEmptyStr(information.semver_patch)) {
tags.push(tagPrefix + information.semver_patch);
foundSemverTag = true;
}
}
// handle git tag/branch
if (core.getBooleanInput('tag_ref_normalized_enable') && foundSemverTag === false) {
if (core.getBooleanInput('tag_ref_normalized_enable')) {
// only apply tag IF it doesn't match the semver
if (isNonEmptyStr(information.git_tag)) {
// TODO normalize tag from git for docker
tags.push(tagPrefix + information.git_tag + tagSuffix);
const normalizedTag = tagPrefix + normalizeGitRefForDockerTag(information.git_tag) + tagSuffix;
if (mostSpecificSemverTag !== normalizedTag) {
tags.push(normalizedTag);
}
}
if (isNonEmptyStr(information.git_current_branch)) {
// TODO normalize branch from git for docker
tags.push(tagPrefix + information.git_current_branch + tagSuffix);
const normalizedBranch = tagPrefix + normalizeGitRefForDockerTag(information.git_current_branch) + tagSuffix;
if (mostSpecificSemverTag !== normalizedBranch) {
tags.push(normalizedBranch);
}
}
}
@ -154,6 +152,11 @@ export function collectTags(information) {
return tags;
}
export function normalizeGitRefForDockerTag(ref) {
return ref
.replaceAll('/', '-');
}
export function prepareDestinations(registries, tags) {
const destinations = [];
registries.forEach((registry) => {