Skip to content

Commit

Permalink
Merge pull request #22 from sshveta/nightly_ci_for_vscode_tests
Browse files Browse the repository at this point in the history
[RFR] Nightly CI for Vscode tests
  • Loading branch information
sshveta authored Nov 1, 2024
2 parents 90bebe9 + a31d104 commit 5b49c65
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 24 deletions.
12 changes: 9 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
# For git password please use your generated git token, not a clear text password

VSCODE_EXECUTABLE_PATH='/usr/share/code/code'
VSIX_FILE_PATH='/home/sshveta/Work/kai-ci/'
VSIX_FILE_NAME='konveyor-linux-0.0.1.vsix'
VSIX_DOWNLOAD_URL= 'https://github.com/konveyor/editor-extensions/releases/download/v0.0.1-dev%2B20241022/konveyor-linux-0.0.1.vsix'
DEFAULT_VSIX_DOWNLOAD_URL= 'https://github.com/konveyor/editor-extensions/releases/download/v0.0.1-dev%2B20241022/konveyor-linux-0.0.1.vsix'
PLUGIN_URL= 'https://github.com/konveyor/editor-extensions/releases/download/'
PLUGIN_VERSION= 'v0.0.1-dev%2B'

# For Windows Path needs to be given in below format
# VSCODE_EXECUTABLE_PATH='C:/Users/nonadmin/AppData/Local/Programs/Microsoft VS Code/Code.exe'
# VSIX_FILE_PATH='C:/Users/nonadmin/kai-ci/'

# For Linux
# VSCODE_EXECUTABLE_PATH='/usr/share/code/code'

# If Daily builds are not available this default URL will be used.
# Provide link to latest VSIX download URL
# DEFAULT_VSIX_DOWNLOAD_URL= 'https://github.com/konveyor/editor-extensions/releases/download/v0.0.1-dev%2B20241022/konveyor-linux-0.0.1.vsix'

87 changes: 87 additions & 0 deletions .github/workflows/nightly-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Run Playwright tests nightly on main branch

on:
schedule:
- cron: "5 3 * * *"
workflow_dispatch:

jobs:
main-nightly:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: lts/*
- name: Install vscode dependencies
run: sudo apt-get update && sudo apt-get install -y wget

- name: Download and Install VSCode
run: |
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" |sudo tee /etc/apt/sources.list.d/vscode.list > /dev/null
rm -f packages.microsoft.gpg
sudo apt install apt-transport-https
sudo apt update
sudo apt install code
- name: Set up virtual X11
run: |
sudo apt-get update
sudo apt-get install -y \
xvfb \
x11-xserver-utils \
dbus-x11 \
xfonts-100dpi \
xfonts-75dpi \
libxrender1 \
libxext6 \
libx11-6 \
xfonts-base \
nickle cairo-5c \
xorg-docs-core
- name: Set DISPLAY environment variable
run: |
Xvfb :99 -screen 0 1920x1080x24 &
echo "DISPLAY=:99" >> $GITHUB_ENV
- name: Start D-Bus
run: |
dbus-launch --exit-with-session &
- name: Start Dbus
run: |
sudo service dbus start
export XDG_RUNTIME_DIR=/run/user/$(id -u)
sudo chmod 700 $XDG_RUNTIME_DIR
sudo chown $(id -un):$(id -gn) $XDG_RUNTIME_DIR
export DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus
dbus-daemon --session --address=$DBUS_SESSION_BUS_ADDRESS --nofork --nopidfile --syslog-only &
mkdir ~/.vscode && echo '{ "disable-hardware-acceleration": true }' > ~/.vscode/argv.json
- name: Verify Installation
run: code --version
- name: Ensure no VSCode instances are running
run: |
pkill -f code || true # Kills all VSCode processes if they are running
- name: Install playwright dependencies
run: npm install
- name: More dependencies
run: npm ci
- name: Copy .env.example to .env
run: cp .env.example .env
- name: Run Playwright tests
run: npx playwright test || true # Ensures the workflow continues even if tests fail
- name: Upload screenshots
uses: actions/upload-artifact@v3
with:
name: vscode-screenshots
path: |
vscode-initialized-screenshot.png
kai-installed-screenshot.png
if: always() # This ensures the upload runs regardless of previous step results
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30

5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ Install the required packages using npm:

VSCODE_EXECUTABLE_PATH='/usr/share/code/code'

# Path to Save the vsix file
VSIX_FILE_PATH="/home/sshveta/Work/kai-ci/"

# URL to download the vsix file, update this if the URL is different.
VSIX_DOWNLOAD_URL= 'https://github.com/konveyor/editor-extensions/releases/download/v0.0.1-dev%2B20241022/konveyor-linux-0.0.1.vsix'
DEFAULT_VSIX_DOWNLOAD_URL= 'https://github.com/konveyor/editor-extensions/releases/download/v0.0.1-dev%2B20241022/konveyor-linux-0.0.1.vsix'


## Running Tests
Expand Down
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 { downloadLatestKAIPlugin } from '../utilities/download.utils';
import { getKAIPluginPath } from '../utilities/utils';
import { getKAIPluginName } from '../utilities/utils';

class VSCode {
private readonly vscodeApp?: ElectronApplication;
Expand All @@ -13,13 +13,12 @@ class VSCode {
}

/**
* Installs kai extensions from the VSIX path configured in the .env file and
* launches VSCode
* launches VSCode with KAI plugin installed.
* @param executablePath path to the vscode binary
*/
public static async init(executablePath: string): Promise<VSCode> {
try {
const vsixFilePath = getKAIPluginPath();
const vsixFilePath = getKAIPluginName();
if (vsixFilePath) {
console.log(`Installing extension from VSIX file: ${vsixFilePath}`);
await VSCode.installExtensionFromVSIX(vsixFilePath);
Expand Down
9 changes: 5 additions & 4 deletions e2e/tests/vscode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@ test.describe('VSCode Tests', () => {
let vscodeApp: VSCode;

test.beforeAll(async () => {
test.setTimeout(60000);
const executablePath =
process.env.VSCODE_EXECUTABLE_PATH || '/usr/share/code/code';
vscodeApp = await VSCode.init(executablePath);
});

test('Should launch VSCode and check window title', async () => {
const window = vscodeApp.getWindow();
const title = await window.title();
expect(title).toContain('Visual Studio Code');
await window.screenshot({ path: 'vscode-initialized-screenshot.png' });
});

test('Should open Extensions tab and verify installed extension', async () => {
const window = vscodeApp.getWindow();
const kaiTab = await window.getByRole('tab', { name: 'Konveyor' });
await kaiTab.click();
// Assert if KAI explorer is opened.
await window.waitForTimeout(10000);
const title = window.getByRole('heading', {
name: 'KAI',
name: 'Konveyor Analysis',
exact: true,
});
expect(title).toBeTruthy();
await window.screenshot({ path: 'kai-installed-screenshot.png' });
});
});
6 changes: 3 additions & 3 deletions e2e/utilities/download.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import * as fs from 'fs';
import { getKAIPluginPath, getOSInfo, getKAIPluginName } from './utils';
import { getKAIPluginName } from './utils';

/**
* Downloads a file from the given URL and saves it to the specified destination.
Expand All @@ -9,9 +9,9 @@ import { getKAIPluginPath, getOSInfo, getKAIPluginName } from './utils';
* @returns Promise that resolves when the download is complete.
*/
export async function downloadFile(): Promise<void> {
const outputLocationPath = getKAIPluginPath();
const outputLocationPath = getKAIPluginName();
const fileUrl = buildDownloadUrl();
const defaultUrl = process.env.VSIX_DOWNLOAD_URL;
const defaultUrl = process.env.DEFAULT_VSIX_DOWNLOAD_URL;

const writer = fs.createWriteStream(outputLocationPath);
const response = await fetchUrl(fileUrl, defaultUrl);
Expand Down
6 changes: 0 additions & 6 deletions e2e/utilities/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ export function getOSInfo(): string {
}
}

export function getKAIPluginPath(): string {
const vsixFilePath = process.env.VSIX_FILE_PATH;
const pluginFilePath = vsixFilePath + getKAIPluginName();
return pluginFilePath;
}

export function getKAIPluginName(): string {
const vsixFileName =
process.env.VSIX_FILE_NAME || 'konveyor-linux-0.0.1.vsix';
Expand Down

0 comments on commit 5b49c65

Please sign in to comment.