From 7ea2cf27fe62bc45472b1798e0b07cceb9118b6d Mon Sep 17 00:00:00 2001 From: Shveta Sachdeva Date: Thu, 17 Oct 2024 17:45:04 -0700 Subject: [PATCH 1/3] Download latest vsix file according to os and date Signed-off-by: Shveta Sachdeva --- e2e/pages/vscode.pages.ts | 20 ++++----- e2e/utilities/utils.ts | 92 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 10 deletions(-) create mode 100644 e2e/utilities/utils.ts diff --git a/e2e/pages/vscode.pages.ts b/e2e/pages/vscode.pages.ts index 7153f32..68fc724 100644 --- a/e2e/pages/vscode.pages.ts +++ b/e2e/pages/vscode.pages.ts @@ -1,6 +1,7 @@ import { _electron as electron, ElectronApplication, Page } from 'playwright'; import { execSync } from 'child_process'; import * as fs from 'fs'; +import { downloadLatestKAIPlugin, getOSInfo } from '../utilities/utils'; class LaunchVSCodePage { private vscodeApp?: ElectronApplication; @@ -15,15 +16,10 @@ class LaunchVSCodePage { executablePath: string ): Promise { try { - const vsixFilePath = process.env.VSIX_FILE_PATH; - if (vsixFilePath) { - console.log(`Installing extension from VSIX file: ${vsixFilePath}`); - await LaunchVSCodePage.installExtensionFromVSIX(vsixFilePath); - } else { - console.warn( - 'VSIX_FILE_PATH environment variable is not set. Skipping extension installation.' - ); - } + const vsixFilePath = + process.env.VSIX_FILE_PATH + `konveyor-${getOSInfo()}-0.0.1.vsix`; + console.log(`Installing extension from VSIX file: ${vsixFilePath}`); + await LaunchVSCodePage.installExtensionFromVSIX(vsixFilePath); // Launch VSCode as an Electron app const vscodeApp = await electron.launch({ @@ -48,10 +44,14 @@ class LaunchVSCodePage { private static async installExtensionFromVSIX( vsixFilePath: string ): Promise { + // if (!fs.existsSync(vsixFile)) { + // throw new Error(`VSIX file not found at path: ${vsixFile}`); + // } + + downloadLatestKAIPlugin(); if (!fs.existsSync(vsixFilePath)) { throw new Error(`VSIX file not found at path: ${vsixFilePath}`); } - try { // Execute command to install VSIX file using VSCode CLI console.log(`Installing extension from ${vsixFilePath}...`); diff --git a/e2e/utilities/utils.ts b/e2e/utilities/utils.ts new file mode 100644 index 0000000..58eb573 --- /dev/null +++ b/e2e/utilities/utils.ts @@ -0,0 +1,92 @@ +import * as os from 'os'; +import axios from 'axios'; +import * as fs from 'fs'; +import * as path from 'path'; + +// Function to get OS information +export function getOSInfo(): string { + const platform: NodeJS.Platform = os.platform(); + + switch (platform) { + case 'win32': + return 'windows'; + case 'darwin': + return 'macOS'; + case 'linux': + return 'linux'; + default: + return `Unknown OS: ${platform}`; + } +} + +/** + * Downloads a file from the given URL and saves it to the specified destination. + * @param fileUrl The URL of the file to download. + * @param outputLocationPath The local file path where the file will be saved. + * @returns Promise that resolves when the download is complete. + */ +export async function downloadFile( + fileUrl: string, + outputLocationPath: string +): Promise { + outputLocationPath = '/home/sshveta/Work/kai-ci/konveyor-linux-0.0.1.vsix'; + const writer = fs.createWriteStream(outputLocationPath); + console.log('==================output path======'); + console.log(outputLocationPath); + + const response = await axios({ + url: fileUrl, + method: 'GET', + responseType: 'stream', + }); + + response.data.pipe(writer); + + return new Promise((resolve, reject) => { + writer.on('finish', resolve); + writer.on('error', reject); + }); +} + +export async function downloadLatestKAIPlugin() { + const url = buildDownloadUrl(); + const outputPath = process.env.VSIX_FILE_PATH || ''; + console.log('========path====='); + console.log(outputPath); + + try { + await downloadFile(url, outputPath); + console.log('File downloaded successfully!'); + } catch (err) { + console.error('Error downloading the file:', err); + } +} + +/** + * Builds the download URL for the KAI plugin with today's date + * and depending on operating system. + * @returns The generated URL string with the current date and os. + */ +export function buildDownloadUrl(): string { + const pluginUrl = + process.env.PLUGIN_URL || + 'https://github.com/konveyor/editor-extensions/releases/download/'; + const version = process.env.PLUGIN_VERSION || 'v0.0.1-dev+'; + + const platform = getOSInfo(); + const fileName = `konveyor-${platform}-0.0.1.vsix`; + + // Get today's date + const today = new Date(); + + // Format date as YYYYMMDD + const year = today.getFullYear(); + const month = String(today.getMonth() + 1).padStart(2, '0'); // Month is zero-based, so add 1 + const day = String(today.getDate()).padStart(2, '0'); + // Resulting format YYYYMMDD + const formattedDate = `${year}${month}${day}`; + + // Build the full URL + const url = `${pluginUrl}${version}${formattedDate}/${fileName}`; + return url; +} From 1d71c133db03f08c2d3be9486a36cb9b511ad7e9 Mon Sep 17 00:00:00 2001 From: Shveta Sachdeva Date: Fri, 18 Oct 2024 14:01:13 -0700 Subject: [PATCH 2/3] Download latest vsix file according to os and date Signed-off-by: Shveta Sachdeva --- .env.example | 7 +++++-- e2e/pages/vscode.pages.ts | 8 +------- e2e/utilities/utils.ts | 22 +++++++--------------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/.env.example b/.env.example index 65189ab..a18cf2a 100644 --- a/.env.example +++ b/.env.example @@ -6,6 +6,9 @@ # Instead, copy it, remove the .example extension and provide your custom values # For git password please use your generated git token, not a clear text password - VSCODE_EXECUTABLE_PATH='/usr/share/code/code' -VSIX_FILE_PATH='kai-vscode-plugin-0.0.3.vsix' +VSIX_FILE_PATH="/home/sshveta/Work/kai-ci/" +VSIX_FILE='konveyor-linux-0.0.1.vsix ' +VSIX_DOWNLOAD_URL= 'https://github.com/konveyor/editor-extensions/releases/download/v0.0.1-dev%2B20241017/konveyor-linux-0.0.1.vsix' +PLUGIN_URL= 'https://github.com/konveyor/editor-extensions/releases/download/' +PLUGIN_VERSION= 'v0.0.1-dev%2B' diff --git a/e2e/pages/vscode.pages.ts b/e2e/pages/vscode.pages.ts index 68fc724..5aa7d67 100644 --- a/e2e/pages/vscode.pages.ts +++ b/e2e/pages/vscode.pages.ts @@ -44,14 +44,8 @@ class LaunchVSCodePage { private static async installExtensionFromVSIX( vsixFilePath: string ): Promise { - // if (!fs.existsSync(vsixFile)) { - // throw new Error(`VSIX file not found at path: ${vsixFile}`); - // } + await downloadLatestKAIPlugin(); - downloadLatestKAIPlugin(); - if (!fs.existsSync(vsixFilePath)) { - throw new Error(`VSIX file not found at path: ${vsixFilePath}`); - } try { // Execute command to install VSIX file using VSCode CLI console.log(`Installing extension from ${vsixFilePath}...`); diff --git a/e2e/utilities/utils.ts b/e2e/utilities/utils.ts index 58eb573..63adcc9 100644 --- a/e2e/utilities/utils.ts +++ b/e2e/utilities/utils.ts @@ -1,7 +1,6 @@ import * as os from 'os'; import axios from 'axios'; import * as fs from 'fs'; -import * as path from 'path'; // Function to get OS information export function getOSInfo(): string { @@ -25,14 +24,12 @@ export function getOSInfo(): string { * @param outputLocationPath The local file path where the file will be saved. * @returns Promise that resolves when the download is complete. */ -export async function downloadFile( - fileUrl: string, - outputLocationPath: string -): Promise { - outputLocationPath = '/home/sshveta/Work/kai-ci/konveyor-linux-0.0.1.vsix'; +export async function downloadFile(): Promise { + const outputLocationPath = + process.env.VSIX_FILE_PATH + `konveyor-${getOSInfo()}-0.0.1.vsix`; + const fileUrl = buildDownloadUrl(); + const writer = fs.createWriteStream(outputLocationPath); - console.log('==================output path======'); - console.log(outputLocationPath); const response = await axios({ url: fileUrl, @@ -49,13 +46,8 @@ export async function downloadFile( } export async function downloadLatestKAIPlugin() { - const url = buildDownloadUrl(); - const outputPath = process.env.VSIX_FILE_PATH || ''; - console.log('========path====='); - console.log(outputPath); - try { - await downloadFile(url, outputPath); + await downloadFile(); console.log('File downloaded successfully!'); } catch (err) { console.error('Error downloading the file:', err); @@ -71,7 +63,7 @@ export function buildDownloadUrl(): string { const pluginUrl = process.env.PLUGIN_URL || 'https://github.com/konveyor/editor-extensions/releases/download/'; - const version = process.env.PLUGIN_VERSION || 'v0.0.1-dev+'; + const version = process.env.PLUGIN_VERSION || 'v0.0.1-dev%2B'; const platform = getOSInfo(); const fileName = `konveyor-${platform}-0.0.1.vsix`; From f5c18138dd33d3ed113ad19ff4cf4fa2ca75cd81 Mon Sep 17 00:00:00 2001 From: Shveta Sachdeva Date: Tue, 22 Oct 2024 10:31:48 -0700 Subject: [PATCH 3/3] Download latest vsix file according to os and date Signed-off-by: Shveta Sachdeva --- .env.example | 2 +- e2e/pages/vscode.pages.ts | 7 ++-- e2e/tests/vscode.test.ts | 2 +- e2e/utilities/download.utils.ts | 63 +++++++++++++++++++++++++++++ e2e/utilities/utils.ts | 71 ++++----------------------------- 5 files changed, 76 insertions(+), 69 deletions(-) create mode 100644 e2e/utilities/download.utils.ts diff --git a/.env.example b/.env.example index a18cf2a..7b19334 100644 --- a/.env.example +++ b/.env.example @@ -8,7 +8,7 @@ VSCODE_EXECUTABLE_PATH='/usr/share/code/code' VSIX_FILE_PATH="/home/sshveta/Work/kai-ci/" -VSIX_FILE='konveyor-linux-0.0.1.vsix ' +VSIX_FILE_NAME='konveyor-linux-0.0.1.vsix' VSIX_DOWNLOAD_URL= 'https://github.com/konveyor/editor-extensions/releases/download/v0.0.1-dev%2B20241017/konveyor-linux-0.0.1.vsix' PLUGIN_URL= 'https://github.com/konveyor/editor-extensions/releases/download/' PLUGIN_VERSION= 'v0.0.1-dev%2B' diff --git a/e2e/pages/vscode.pages.ts b/e2e/pages/vscode.pages.ts index 5aa7d67..8ce0bc7 100644 --- a/e2e/pages/vscode.pages.ts +++ b/e2e/pages/vscode.pages.ts @@ -1,7 +1,7 @@ import { _electron as electron, ElectronApplication, Page } from 'playwright'; import { execSync } from 'child_process'; -import * as fs from 'fs'; -import { downloadLatestKAIPlugin, getOSInfo } from '../utilities/utils'; +import { downloadLatestKAIPlugin } from '../utilities/download.utils'; +import { getKAIPluginPath } from '../utilities/utils'; class LaunchVSCodePage { private vscodeApp?: ElectronApplication; @@ -16,8 +16,7 @@ class LaunchVSCodePage { executablePath: string ): Promise { try { - const vsixFilePath = - process.env.VSIX_FILE_PATH + `konveyor-${getOSInfo()}-0.0.1.vsix`; + const vsixFilePath = getKAIPluginPath(); console.log(`Installing extension from VSIX file: ${vsixFilePath}`); await LaunchVSCodePage.installExtensionFromVSIX(vsixFilePath); diff --git a/e2e/tests/vscode.test.ts b/e2e/tests/vscode.test.ts index 777d753..adc159c 100644 --- a/e2e/tests/vscode.test.ts +++ b/e2e/tests/vscode.test.ts @@ -22,7 +22,7 @@ test.describe('VSCode Tests', () => { test('should open Extensions tab and verify installed extension', async () => { const window = vscodeApp.getWindow(); - const kaiTab = await window.getByRole('tab', { name: 'KAI', exact: true }); + const kaiTab = await window.getByRole('tab', { name: 'Konveyor' }); await kaiTab.click(); // Assert if KAI explorer is opened. const title = await window.getByRole('heading', { diff --git a/e2e/utilities/download.utils.ts b/e2e/utilities/download.utils.ts new file mode 100644 index 0000000..141faaa --- /dev/null +++ b/e2e/utilities/download.utils.ts @@ -0,0 +1,63 @@ +import axios from 'axios'; +import * as fs from 'fs'; +import { getKAIPluginPath, getOSInfo, getKAIPluginName } from './utils'; + +/** + * Downloads a file from the given URL and saves it to the specified destination. + * @param fileUrl The URL of the file to download. + * @param outputLocationPath The local file path where the file will be saved. + * @returns Promise that resolves when the download is complete. + */ +export async function downloadFile(): Promise { + const outputLocationPath = getKAIPluginPath(); + const fileUrl = buildDownloadUrl(); + + const writer = fs.createWriteStream(outputLocationPath); + + const response = await axios({ + url: fileUrl, + method: 'GET', + responseType: 'stream', + }); + + response.data.pipe(writer); + + return new Promise((resolve, reject) => { + writer.on('finish', resolve); + writer.on('error', reject); + }); +} + +export async function downloadLatestKAIPlugin() { + try { + await downloadFile(); + console.log('File downloaded successfully!'); + } catch (err) { + console.error('Error downloading the file:', err); + } +} + +/** + * Builds the download URL for the KAI plugin with today's date + * and depending on operating system. + * @returns The generated URL string with the current date and os. + */ +export function buildDownloadUrl(): string { + const pluginUrl = + process.env.PLUGIN_URL || + 'https://github.com/konveyor/editor-extensions/releases/download/'; + const version = process.env.PLUGIN_VERSION || 'v0.0.1-dev%2B'; + const fileName = getKAIPluginName(); + + const today = new Date(); + + // Format date as YYYYMMDD + const year = today.getFullYear(); + const month = String(today.getMonth() + 1).padStart(2, '0'); // Month is zero-based, so add 1 + const day = String(today.getDate()).padStart(2, '0'); + const formattedDate = `${year}${month}${day}`; + + // Build the full URL + const url = `${pluginUrl}${version}${formattedDate}/${fileName}`; + return url; +} diff --git a/e2e/utilities/utils.ts b/e2e/utilities/utils.ts index 63adcc9..c71c303 100644 --- a/e2e/utilities/utils.ts +++ b/e2e/utilities/utils.ts @@ -1,6 +1,4 @@ import * as os from 'os'; -import axios from 'axios'; -import * as fs from 'fs'; // Function to get OS information export function getOSInfo(): string { @@ -18,67 +16,14 @@ export function getOSInfo(): string { } } -/** - * Downloads a file from the given URL and saves it to the specified destination. - * @param fileUrl The URL of the file to download. - * @param outputLocationPath The local file path where the file will be saved. - * @returns Promise that resolves when the download is complete. - */ -export async function downloadFile(): Promise { - const outputLocationPath = - process.env.VSIX_FILE_PATH + `konveyor-${getOSInfo()}-0.0.1.vsix`; - const fileUrl = buildDownloadUrl(); - - const writer = fs.createWriteStream(outputLocationPath); - - const response = await axios({ - url: fileUrl, - method: 'GET', - responseType: 'stream', - }); - - response.data.pipe(writer); - - return new Promise((resolve, reject) => { - writer.on('finish', resolve); - writer.on('error', reject); - }); +export function getKAIPluginPath(): string { + const vsixFilePath = process.env.VSIX_FILE_PATH; + const pluginFilePath = vsixFilePath + getKAIPluginName(); + return pluginFilePath; } -export async function downloadLatestKAIPlugin() { - try { - await downloadFile(); - console.log('File downloaded successfully!'); - } catch (err) { - console.error('Error downloading the file:', err); - } -} - -/** - * Builds the download URL for the KAI plugin with today's date - * and depending on operating system. - * @returns The generated URL string with the current date and os. - */ -export function buildDownloadUrl(): string { - const pluginUrl = - process.env.PLUGIN_URL || - 'https://github.com/konveyor/editor-extensions/releases/download/'; - const version = process.env.PLUGIN_VERSION || 'v0.0.1-dev%2B'; - - const platform = getOSInfo(); - const fileName = `konveyor-${platform}-0.0.1.vsix`; - - // Get today's date - const today = new Date(); - - // Format date as YYYYMMDD - const year = today.getFullYear(); - const month = String(today.getMonth() + 1).padStart(2, '0'); // Month is zero-based, so add 1 - const day = String(today.getDate()).padStart(2, '0'); - // Resulting format YYYYMMDD - const formattedDate = `${year}${month}${day}`; - - // Build the full URL - const url = `${pluginUrl}${version}${formattedDate}/${fileName}`; - return url; +export function getKAIPluginName(): string { + const vsixFileName = + process.env.VSIX_FILE_NAME || 'konveyor-linux-0.0.1.vsix'; + return vsixFileName.replace(/(konveyor-)(\w+)(-.*)/, `$1${getOSInfo()}$3`); }