Skip to content

Commit

Permalink
Download latest vsix file according to os and date
Browse files Browse the repository at this point in the history
Signed-off-by: Shveta Sachdeva <[email protected]>
  • Loading branch information
sshveta committed Oct 22, 2024
1 parent 1d71c13 commit f5c1813
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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'
7 changes: 3 additions & 4 deletions e2e/pages/vscode.pages.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,8 +16,7 @@ class LaunchVSCodePage {
executablePath: string
): Promise<LaunchVSCodePage> {
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);

Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/vscode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
63 changes: 63 additions & 0 deletions e2e/utilities/download.utils.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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;
}
71 changes: 8 additions & 63 deletions e2e/utilities/utils.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<void> {
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`);
}

0 comments on commit f5c1813

Please sign in to comment.