Skip to content

Commit b216ac3

Browse files
committed
fix: improve pattern normalization and template filling in metadata action
1 parent 2512bcc commit b216ac3

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

actions/metadata-action/dist/index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42730,8 +42730,14 @@ function extractSemverParts(versionString) {
4273042730
}
4273142731

4273242732

42733+
// function matchesPattern(refName, pattern) {
42734+
// const regex = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$');
42735+
// return regex.test(refName);
42736+
// }
42737+
4273342738
function matchesPattern(refName, pattern) {
42734-
const regex = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$');
42739+
const normalizedPattern = pattern.replace(/\//g, '-').replace(/\*/g, '.*');
42740+
const regex = new RegExp('^' + normalizedPattern + '$');
4273542741
return regex.test(refName);
4273642742
}
4273742743

@@ -42772,7 +42778,7 @@ function findDistTag(ref, distTags) {
4277242778
}
4277342779

4277442780
function fillTemplate(template, values) {
42775-
return template.replace(/{{\s*(\w+)\s*}}/g, (match, key) => {
42781+
return template.replace(/{{\s*([\w-]+)\s*}}/g, (match, key) => {
4277642782
return key in values ? values[key] : match;
4277742783
});
4277842784
}
@@ -42789,13 +42795,17 @@ async function run() {
4278942795
core.info(`🔹 Ref: ${JSON.stringify(ref)}`);
4279042796

4279142797
const template = findTemplate(!ref.isTag ? ref.name : "tag", loader["branches-template"]);
42798+
if (!template) {
42799+
core.setFailed(`❗️ No template found for ref: ${ref.name}`);
42800+
return;
42801+
}
4279242802

4279342803
// let fill = fillTemplate(template, { ...ref, ...generateSnapshotVersionParts(), ...extractSemverParts(ref.name) });
4279442804

4279542805
const parts = generateSnapshotVersionParts();
4279642806
const semverParts = extractSemverParts(ref.name);
4279742807
const distTag = findDistTag(ref, loader["dist-tags"]) || "default";
42798-
const values = { ...ref, ...semverParts, ...parts, ...github.context, distTag };
42808+
const values = { ...ref, "ref-name": ref.name, ...semverParts, ...parts, ...github.context, distTag };
4279942809

4280042810
core.info(`🔹 time: ${JSON.stringify(parts)}`);
4280142811
core.info(`🔹 semver: ${JSON.stringify(semverParts)}`);
@@ -42804,6 +42814,9 @@ async function run() {
4280442814
let result = fillTemplate(template, values)
4280542815

4280642816
core.info(`🔹 Template: ${template}`);
42817+
42818+
let t = ref.name;
42819+
core.info(`🔹 Name: ${{ t}}`)
4280742820
core.info(`💡 Rendered template: ${result}`);
4280842821

4280942822
core.setOutput("result", result);

0 commit comments

Comments
 (0)