Skip to content

Commit 1fe4f3d

Browse files
fix: update version detection logic in build-releases.js
- Changed the latest version pattern to YY.MM-patch format. - Introduced MIN_STABLE_VERSION for stable version validation.
1 parent b567f34 commit 1fe4f3d

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

.github/scripts/release-index/build-releases.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const { load } = require("js-yaml");
66

77
const OWNER = "codefresh-io";
88
const REPO = "gitops-runtime-helm";
9-
const LATEST_PATTERN = /^(\d{4})\.(\d{1,2})-(\d+)$/;
9+
const LATEST_PATTERN = /^(\d{2})\.(\d{1,2})-(\d+)$/; // Format: YY.MM-patch (e.g., 25.04-1)
10+
const MIN_STABLE_VERSION = "1.0.0";
1011
const TOKEN = process.env.GITHUB_TOKEN;
1112
const SECURITY_FIXES_STRING =
1213
process.env.SECURITY_FIXES_STRING || "### Security Fixes:";
@@ -22,6 +23,11 @@ if (!TOKEN) {
2223

2324
const octokit = new Octokit({ auth: TOKEN });
2425

26+
/**
27+
* Detect channel based on version format
28+
* - Latest: YY.MM-patch format (e.g., 25.04-1)
29+
* - Stable: Semver format starting from 1.0.0 (e.g., 1.2.3)
30+
*/
2531
function detectChannel(version) {
2632
const match = version.match(LATEST_PATTERN);
2733
if (match) {
@@ -30,12 +36,26 @@ function detectChannel(version) {
3036
return "latest";
3137
}
3238
}
39+
3340
return "stable";
3441
}
3542

43+
function isValidChannelVersion(normalized, channel) {
44+
if (!semver.valid(normalized)) {
45+
return false;
46+
}
47+
48+
if (channel === "stable") {
49+
return semver.gte(normalized, MIN_STABLE_VERSION);
50+
}
51+
52+
return true;
53+
}
54+
3655
/**
3756
* Normalize version for semver validation
38-
* Converts: 2025.01-1 → 2025.1.1
57+
* - Latest channel: 25.01-1 → 25.1.1
58+
* - Stable channel: 1.2.3 → 1.2.3 (no change)
3959
*/
4060
function normalizeVersion(version, channel) {
4161
if (channel === "latest") {
@@ -50,10 +70,6 @@ function normalizeVersion(version, channel) {
5070
return version;
5171
}
5272

53-
function isValidVersion(normalized) {
54-
return !!semver.valid(normalized);
55-
}
56-
5773
function compareVersions(normA, normB) {
5874
try {
5975
return semver.compare(normA, normB);
@@ -145,11 +161,14 @@ function processReleases(rawReleases) {
145161
}
146162

147163
const channel = detectChannel(version);
148-
149164
const normalized = normalizeVersion(version, channel);
150165

151-
if (!isValidVersion(normalized)) {
152-
console.log(` ⚠️ Skipping invalid version: ${version}`);
166+
if (!isValidChannelVersion(normalized, channel)) {
167+
const reason =
168+
channel === "stable"
169+
? `not valid semver >= ${MIN_STABLE_VERSION}`
170+
: "not valid semver";
171+
console.log(` ⚠️ Skipping invalid ${channel} version: ${version} (${reason})`);
153172
skipped++;
154173
continue;
155174
}

0 commit comments

Comments
 (0)