Skip to content
80 changes: 40 additions & 40 deletions actions/run-lighthouse-tests/dist/index.js

Large diffs are not rendered by default.

68 changes: 34 additions & 34 deletions actions/setup-elementor-env/dist/index.js

Large diffs are not rendered by default.

82 changes: 41 additions & 41 deletions actions/setup-wp-env/dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/editor-github-actions-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"dependencies": {
"@actions/core": "^1.11.1",
"ansi-styles": "^6.2.1"
"ansi-styles": "^6.2.1",
"semver": "^7.7.2"
},
Comment on lines 15 to 19
"devDependencies": {
"tsup": "^8.5.0",
Expand Down
38 changes: 15 additions & 23 deletions packages/editor-github-actions-utils/src/version-files.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as semver from 'semver';
Comment thread
Ntnelbaba marked this conversation as resolved.
// ─── elementor.php ────────────────────────────────────────────────────────────

/**
Expand All @@ -7,7 +8,7 @@
*/
export function patchPhpVersion(content: string, version: string): string {
return content
.replace(/( \* Version: ).*/g, `$1${version}`)
.replace(/( \* Version: ).*/, `$1${version}`)
.replace(/(define\( 'ELEMENTOR_VERSION', ')[^']*'/, `$1${version}'`);
}

Expand Down Expand Up @@ -38,7 +39,9 @@ export function patchReadmeTxt(
.replace(/^Beta tag: .*/m, `Beta tag: ${tags.beta}`);
}

// ─── git ls-remote output parsing ─────────────────────────────────────────────
function normalizeVersion(version: string): string {
return version.replace(/-beta(\d+)$/, '-beta.$1');
}

/**
* Parses raw `git ls-remote --tags` output and returns the latest tag name
Expand All @@ -54,31 +57,20 @@ export function parseLatestTagFromLsRemote(
lsRemoteOutput: string,
pattern: RegExp,
): string | null {
const safePattern = new RegExp(
pattern.source,
pattern.flags.replace(/[gy]/g, ''),
);

const tags = lsRemoteOutput
.split('\n')
.map((line) => line.split('\t')[1] ?? '')
.map((ref) => ref.replace(/^refs\/tags\/v?/, ''))
.filter((tag) => pattern.test(tag))
.sort((a, b) => {
// Semantic version sort — splits numeric and alphabetic parts so that
// beta10 > beta2 (numeric comparison, not lexicographic).
const toparts = (v: string) =>
v.split(/[.-]/).flatMap((p) => {
const m = p.match(/^([a-z]+)(\d+)$/);
return m
? [m[1], Number(m[2])]
: [isNaN(Number(p)) ? p : Number(p)];
});
const ap = toparts(a);
const bp = toparts(b);
for (let i = 0; i < Math.max(ap.length, bp.length); i++) {
const ai = ap[i] ?? 0;
const bi = bp[i] ?? 0;
if (ai < bi) return -1;
if (ai > bi) return 1;
}
return 0;
});
.filter((tag) => safePattern.test(tag))
.filter((tag) => semver.valid(normalizeVersion(tag)) !== null)
.sort((a, b) =>
semver.compare(normalizeVersion(a), normalizeVersion(b)),
);

return tags[tags.length - 1] ?? null;
}
Loading