Skip to content

Commit

Permalink
🧱 Fix CLI updater script
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Apr 15, 2024
1 parent ee19938 commit c7f2b65
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions common/update-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async function getLatestRelease() {
};

const release = await makeRequest(options);
return release.tag_name;
return release.tag_name.substring(1);
} catch (error) {
console.error("An error occurred:", error);
}
Expand All @@ -96,7 +96,7 @@ function updateCliChecksums(latestVersion, checksumsPath, cliJsonPath) {
}
}
});
cliJson.version = latestVersion.slice(1);
cliJson.version = latestVersion;
fs.writeFileSync(cliJsonPath, JSON.stringify(cliJson, null, 2));
fs.unlinkSync(checksumsPath);
}
Expand All @@ -114,8 +114,6 @@ function updateCircleCIChecksums(circleCIConfigPath) {
}

function updateVersions(latestVersion, currentVersion) {
latestVersion = latestVersion.slice(1);

const latestVersions = latestVersion.split(".");
const latestMajor = parseInt(latestVersions[0]);
const latestMinor = parseInt(latestVersions[1]);
Expand All @@ -137,27 +135,32 @@ function updateVersions(latestVersion, currentVersion) {
const currentVersions = currentVersion.split(".");
const currentMajor = parseInt(currentVersions[0]);
const currentMinor = parseInt(currentVersions[1]);
const currentPatch = parseInt(currentVersions[2]);

replaceStringsInProject(`${latestMajor}.${latestMinor}.${latestPatch}`, `${currentMajor}.${currentMinor}.${latestPatch}`);
replaceStringsInProject(`${latestMajor}.${latestMinor}.${latestPatch}`, `${currentMajor}.${currentMinor}.${currentPatch}`);
replaceStringsInProject(`${latestMajor}.${latestMinor}`, `${currentMajor}.${currentMinor}`);
}

function replaceStringsInProject(newString, oldString) {
process.env.LC_ALL = "C";
const isMacOS = process.platform === "darwin";
const command = `cd .. && find . -type f -exec sed -i${isMacOS ? " ''" : ""} 's/${oldString}/${newString}/g' {} +`;
console.log("Running command:", command);
execSync(command, { shell: "/bin/bash" });
}

async function main() {
try {
const currentVersion = JSON.parse(fs.readFileSync(cliJsonPath, "utf-8")).version;
console.log("Current version:", currentVersion);
const latestVersion = await getLatestRelease();
console.log("Latest version:", latestVersion);
console.log("Downloading new checksums...");
await downloadFile(`https://github.com/jetbrains/qodana-cli/releases/latest/download/checksums.txt`, "checksums.txt");
updateVersions(latestVersion, currentVersion);
updateCliChecksums(latestVersion, "checksums.txt", cliJsonPath);
updateCircleCIChecksums("../orb/commands/scan.yml");
console.log("Checksums updated successfully!");
console.log("Versions updated successfully!");
} catch (error) {
console.error("An error occurred:", error);
}
Expand Down

0 comments on commit c7f2b65

Please sign in to comment.