From cc2ced886a963fe2f276d0a57ae07911a5702f22 Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Kandula Date: Wed, 4 Oct 2023 15:28:26 +0530 Subject: [PATCH] fix: Fix backup command getting version (#27780) This broke when we changed the way RTS stores version information. This was never the right way to get the version in the `backup` command and this PR fixes it, by getting the version from `info.json`. Failure error: ``` Error: ENOENT: no such file or directory, open '/opt/appsmith/rts/version.js' ``` --- .../docker/fs/opt/appsmith/utils/bin/backup.test.js | 12 +++--------- deploy/docker/fs/opt/appsmith/utils/bin/restore.js | 4 ++-- deploy/docker/fs/opt/appsmith/utils/bin/utils.js | 5 +++-- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/deploy/docker/fs/opt/appsmith/utils/bin/backup.test.js b/deploy/docker/fs/opt/appsmith/utils/bin/backup.test.js index de6ebbb553..1b5da25a5a 100644 --- a/deploy/docker/fs/opt/appsmith/utils/bin/backup.test.js +++ b/deploy/docker/fs/opt/appsmith/utils/bin/backup.test.js @@ -6,7 +6,7 @@ const utils = require('./utils'); const shell = require('shelljs'); describe('Backup Tests', () => { - + test('Timestamp string in ISO format', () => { console.log(backup.getTimeStampInISO()) expect(backup.getTimeStampInISO()).toMatch(/(\d{4})-(\d{2})-(\d{2})T(\d{2})\-(\d{2})\-(\d{2})\.(\d{3})Z/) @@ -78,14 +78,8 @@ test('Test ln command generation', async () => { }) it('Checks for the current Appsmith Version.', async () => { - - fsPromises.readFile = jest.fn().mockImplementation(async (a) => - `Object.defineProperty(exports, "__esModule", { value: true }); - exports.VERSION = void 0; - exports.VERSION = "v0.0.0-SNAPSHOT";`); - const res = await utils.getCurrentAppsmithVersion() - expect(res).toBe("v0.0.0-SNAPSHOT") - console.log(res) + fsPromises.readFile = jest.fn().mockImplementation(async () => `{"githubRef":"refs/tags/v1.2.3"}`); + await expect(utils.getCurrentAppsmithVersion()).resolves.toBe("v1.2.3") }) test('If Encryption env values are being removed', () => { diff --git a/deploy/docker/fs/opt/appsmith/utils/bin/restore.js b/deploy/docker/fs/opt/appsmith/utils/bin/restore.js index 9fb080f98e..4b92c8044a 100644 --- a/deploy/docker/fs/opt/appsmith/utils/bin/restore.js +++ b/deploy/docker/fs/opt/appsmith/utils/bin/restore.js @@ -7,6 +7,7 @@ const shell = require('shelljs'); const utils = require('./utils'); const Constants = require('./constants'); +const {getCurrentAppsmithVersion} = require("./utils") async function getBackupFileName() { @@ -101,8 +102,7 @@ async function restoreGitStorageArchive(restoreContentsPath, backupName) { } async function checkRestoreVersionCompatability(restoreContentsPath) { - const content = await fsPromises.readFile('/opt/appsmith/rts/version.js', { encoding: 'utf8' }); - const currentVersion = content.match(/\bexports\.VERSION\s*=\s*["']([^"]+)["']/)[1]; + const currentVersion = await getCurrentAppsmithVersion(); const manifest_data = await fsPromises.readFile(restoreContentsPath + '/manifest.json', { encoding: 'utf8' }); const manifest_json = JSON.parse(manifest_data); const restoreVersion = manifest_json["appsmithVersion"]; diff --git a/deploy/docker/fs/opt/appsmith/utils/bin/utils.js b/deploy/docker/fs/opt/appsmith/utils/bin/utils.js index 376a0b272e..e97f84dc3a 100644 --- a/deploy/docker/fs/opt/appsmith/utils/bin/utils.js +++ b/deploy/docker/fs/opt/appsmith/utils/bin/utils.js @@ -98,8 +98,9 @@ async function getLastBackupErrorMailSentInMilliSec() { } async function getCurrentAppsmithVersion() { - const content = await fsPromises.readFile('/opt/appsmith/rts/version.js', { encoding: 'utf8' }); - return content.match(/\bexports\.VERSION\s*=\s*["']([^"]+)["']/)[1]; + const githubRef = JSON.parse(await fsPromises.readFile("/opt/appsmith/info.json", "utf8")).githubRef; + // This will be of the form "refs/tags/v1.2.3". + return githubRef.split("/").pop() ?? ""; } function preprocessMongoDBURI(uri /* string */) {