Skip to content

Commit 45b6799

Browse files
committed
fix: lowe updates releases should not trigger update notification
1 parent ceb9808 commit 45b6799

1 file changed

Lines changed: 43 additions & 2 deletions

File tree

.github/workflows/updateNotification.js

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,41 @@ function _extractSmallReleaseNotes(releaseNotes, releaseTitle) {
8080
return releaseTitle;
8181
}
8282

83+
function getCurrentVersion(latestJsonPath) {
84+
try{
85+
return JSON.parse(fs.readFileSync(latestJsonPath, 'utf8')).version || '0.0.0';
86+
} catch (e) {
87+
console.error("Error getting current version from path: ", latestJsonPath, e);
88+
return '0.0.0';
89+
}
90+
}
91+
92+
/**
93+
* Checks if new version is higher or equal than the current version
94+
* @param currentVersion
95+
* @param newVersion
96+
* @return {boolean}
97+
*/
98+
function isHigherOrEqualVersion(currentVersion, newVersion) {
99+
if(currentVersion === newVersion){
100+
return true;
101+
}
102+
const currentParts = currentVersion.split('.').map(Number);
103+
const newParts = newVersion.split('.').map(Number);
104+
105+
for (let i = 0; i < currentParts.length; i++) {
106+
if (newParts[i] > currentParts[i]) {
107+
return true; // New version is higher
108+
} else if (newParts[i] < currentParts[i]) {
109+
return false; // New version is not higher
110+
}
111+
// If they are equal, move to the next part
112+
}
113+
114+
// If all parts are equal, the versions are the same, so return false
115+
return false;
116+
}
117+
83118
export default async function printStuff({github, context, githubWorkspaceRoot}) {
84119
console.log(github, context, "yo");
85120
const fullRepoName = context.payload.repository.full_name;
@@ -110,6 +145,12 @@ export default async function printStuff({github, context, githubWorkspaceRoot})
110145
const latestJSON = JSON.parse(await _getLatestJson(releaseAssets));
111146
latestJSON.notes = _extractSmallReleaseNotes(releaseNotes, releaseTitle);
112147
const latestJsonPath = `${githubWorkspaceRoot}/docs/${_identifyUpdateJSONPath(releaseAssets)}`;
113-
console.log("writing latest json to path: ", latestJsonPath, " contents: ", latestJSON)
114-
fs.writeFileSync(latestJsonPath, JSON.stringify(latestJSON, null, 4));
148+
const currentVersion = getCurrentVersion(latestJsonPath);
149+
const latestVersion = latestJSON.version;
150+
if(isHigherOrEqualVersion(currentVersion, latestVersion)){
151+
console.log("writing latest json to path: ", latestJsonPath, " contents: ", latestJSON)
152+
fs.writeFileSync(latestJsonPath, JSON.stringify(latestJSON, null, 4));
153+
} else {
154+
console.warn("Current version: ", currentVersion, " is higher than the new release version ", latestVersion, " . Ignoring this release update!");
155+
}
115156
}

0 commit comments

Comments
 (0)