Skip to content

Commit 626d4f7

Browse files
authored
ci: use cached vscode at E2E tests (#38)
## Proposed changes To reduce time of CI, cache the vscode binalies. ## Types of changes [//]: # 'What types of changes does your code introduce to WebdriverIO?' [//]: # '_Put an `x` in the boxes that apply_' - [ ] Polish (an improvement for an existing feature) - [ ] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update (improvements to the project's docs) - [X] Internal updates (everything related to internal scripts, governance documentation and CI files) ## Checklist [//]: # "_Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._" - [X] I have read the [CONTRIBUTING](https://github.com/webdriverio/vscode-webdriverio/blob/main/CONTRIBUTION.md) doc - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have added the necessary documentation (if appropriate) - [ ] I have added proper type definitions for new commands (if appropriate) ## Further comments [//]: # 'If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...' ### Reviewers: @webdriverio/project-committers
1 parent 4a4063d commit 626d4f7

8 files changed

Lines changed: 133 additions & 71 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: 'vscode-webdriverio Cache vscode'
2+
description: 'cache the vscode for CI (Use after `pnpm install`)'
3+
inputs:
4+
path:
5+
description: 'location to cache'
6+
runs:
7+
using: 'composite'
8+
steps:
9+
- name: 🪄 Generate cache key
10+
id: generate-key
11+
run: pnpm --filter @vscode-wdio/release run cache-key
12+
shell: bash
13+
14+
- name: 🗃️ Use cached vscode
15+
if: ${{ steps.generate-key.outputs.vscode-cache-key != '' }}
16+
uses: actions/cache@v4
17+
with:
18+
path: ${{ inputs.path }}
19+
key: ${{ steps.generate-key.outputs.vscode-cache-key }}

.github/workflows/ci-e2e.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212

1313
env:
1414
TURBO_TELEMETRY_DISABLED: 1
15+
VSCODE_WDIO_E2E_COMPATIBILITY_MODE: ${{ inputs.compatibility-mode }}
1516

1617
jobs:
1718
unit:
@@ -40,9 +41,12 @@ jobs:
4041
path: .
4142
filename: vscode-webdriverio-build.zip
4243

44+
- name: 🗃️ Use cached vscode
45+
uses: ./.github/workflows/actions/cache-vscode
46+
with:
47+
path: e2e/.wdio-vscode-service
48+
4349
- name: 🧪 Run the e2e test
44-
env:
45-
VSCODE_WDIO_E2E_COMPATIBILITY_MODE: ${{ inputs.compatibility-mode }}
4650
run: pnpm run test:e2e
4751
shell: bash
4852

.github/workflows/ci-smoke.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,23 @@ jobs:
3535
path: .
3636
filename: vscode-webdriverio-build.zip
3737

38+
- name: 🗃️ Use cached vscode
39+
uses: ./.github/workflows/actions/cache-vscode
40+
with:
41+
path: e2e/.wdio-vscode-service
42+
3843
- name: 🚂 Run the smoke test
3944
run: pnpm run test:smoke
4045
shell: bash
4146

47+
- name: 📦 Upload Test Logs on Failure
48+
uses: ./.github/workflows/actions/upload-archive
49+
if: failure()
50+
with:
51+
name: smoke-logs-${{ matrix.os }}
52+
output: smoke-logs-${{ matrix.os }}.zip
53+
paths: e2e/logs
54+
4255
- name: 🐛 Debug Build
4356
uses: stateful/[email protected]
4457
if: failure()

e2e/wdio.conf.ts

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,47 @@ process.env.VSCODE_WDIO_TRACE_LOG_PATH = outputDir
1818

1919
const specs = target === 'cucumber' ? ['./tests/basicCucumber.spec.ts'] : ['./tests/basic.spec.ts']
2020

21-
export const config: WebdriverIO.Config = {
22-
runner: 'local',
23-
tsConfigPath: './tsconfig.json',
24-
specs,
25-
maxInstances: 10,
26-
capabilities: [
27-
{
28-
browserName: 'vscode',
29-
browserVersion: version,
30-
'wdio:vscodeOptions': {
31-
// points to directory where extension package.json is located
32-
extensionPath: path.resolve('../packages/vscode-webdriverio'),
33-
// optional VS Code settings
34-
userSettings: {
35-
'webdriverio.logLevel': 'trace',
21+
export function createBaseConfig(workspacePath: string): WebdriverIO.Config {
22+
return {
23+
runner: 'local',
24+
tsConfigPath: './tsconfig.json',
25+
specs,
26+
maxInstances: 10,
27+
capabilities: [
28+
{
29+
browserName: 'vscode',
30+
browserVersion: version,
31+
'wdio:vscodeOptions': {
32+
// points to directory where extension package.json is located
33+
extensionPath: path.resolve('../packages/vscode-webdriverio'),
34+
// optional VS Code settings
35+
userSettings: {
36+
'webdriverio.logLevel': 'trace',
37+
},
38+
workspacePath: path.resolve(workspacePath),
3639
},
37-
workspacePath: path.resolve(`../samples/e2e/${target}`),
40+
'wdio:enforceWebDriverClassic': true,
3841
},
39-
'wdio:enforceWebDriverClassic': true,
42+
],
43+
44+
logLevel: 'debug',
45+
outputDir,
46+
bail: 0,
47+
waitforTimeout: 120000,
48+
connectionRetryTimeout: 120000,
49+
connectionRetryCount: 3,
50+
services: [['vscode', { cachePath: path.join(__dirname, '.wdio-vscode-service') }]],
51+
framework: 'mocha',
52+
reporters: ['spec'],
53+
mochaOpts: {
54+
ui: 'bdd',
55+
timeout: 6000000,
56+
require: ['assertions/index.ts'],
4057
},
41-
],
42-
43-
logLevel: 'debug',
44-
outputDir,
45-
bail: 0,
46-
waitforTimeout: 120000,
47-
connectionRetryTimeout: 120000,
48-
connectionRetryCount: 3,
49-
services: ['vscode'],
50-
framework: 'mocha',
51-
reporters: ['spec'],
52-
mochaOpts: {
53-
ui: 'bdd',
54-
timeout: 6000000,
55-
require: ['assertions/index.ts'],
56-
},
58+
}
59+
}
60+
61+
export const config: WebdriverIO.Config = {
62+
...createBaseConfig(`../samples/e2e/${target}`),
63+
specs,
5764
}

e2e/wdioSmoke.conf.ts

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,8 @@
1-
import * as path from 'node:path'
1+
import { createBaseConfig } from './wdio.conf.ts'
22

33
const specs = ['./tests/updateConfig.spec.ts']
44

55
export const config: WebdriverIO.Config = {
6-
runner: 'local',
7-
tsConfigPath: './tsconfig.json',
6+
...createBaseConfig('../samples/smoke/update-config'),
87
specs,
9-
maxInstances: 10,
10-
capabilities: [
11-
{
12-
browserName: 'vscode',
13-
browserVersion: 'stable', // also possible: "insiders" or a specific version e.g. "1.80.0"
14-
'wdio:vscodeOptions': {
15-
// points to directory where extension package.json is located
16-
extensionPath: path.resolve('../packages/vscode-webdriverio'),
17-
// optional VS Code settings
18-
userSettings: {
19-
'webdriverio.logLevel': 'trace',
20-
},
21-
workspacePath: path.resolve('../samples/smoke/update-config'),
22-
},
23-
'wdio:enforceWebDriverClassic': true,
24-
},
25-
],
26-
27-
logLevel: 'debug',
28-
outputDir: 'logs',
29-
bail: 0,
30-
waitforTimeout: 120000,
31-
connectionRetryTimeout: 120000,
32-
connectionRetryCount: 3,
33-
services: ['vscode'],
34-
framework: 'mocha',
35-
reporters: ['spec'],
36-
mochaOpts: {
37-
ui: 'bdd',
38-
timeout: 6000000,
39-
require: ['assertions/index.ts'],
40-
},
418
}

infra/release/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6+
"cache-key": "tsx ./src/cacheKey.ts",
67
"copy": "tsx ./src/copy.ts",
78
"push": "tsx ./src/push.ts",
89
"update-version": "tsx ./src/updatePrereleaseVersion.ts",
@@ -12,7 +13,9 @@
1213
"devDependencies": {
1314
"@actions/core": "^1.11.1",
1415
"@octokit/rest": "^22.0.0",
16+
"@types/semver": "^7.7.0",
1517
"dotenv": "^16.5.0",
16-
"lerna-changelog": "^2.2.0"
18+
"lerna-changelog": "^2.2.0",
19+
"semver": "^7.7.2"
1720
}
1821
}

infra/release/src/cacheKey.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env node
2+
import crypto from 'node:crypto'
3+
4+
import * as core from '@actions/core'
5+
import { minVersion } from 'semver'
6+
7+
import pkg from '../../../packages/vscode-webdriverio/package.json' with { type: 'json' }
8+
9+
const VSCODE_RELEASES = 'https://update.code.visualstudio.com/api/releases/stable'
10+
11+
async function resolveStable() {
12+
try {
13+
console.log(`Fetch releases from ${VSCODE_RELEASES}`)
14+
const res = await fetch(VSCODE_RELEASES)
15+
const availableVersions: string[] = (await res.json()) as string[]
16+
return availableVersions[0]
17+
} catch {
18+
console.log('Failed to fetch.')
19+
return ''
20+
}
21+
}
22+
23+
async function generate() {
24+
console.log('Resolve version of the vscode')
25+
const isCompatibilityMode = process.env.VSCODE_WDIO_E2E_COMPATIBILITY_MODE === 'yes'
26+
27+
const version = isCompatibilityMode ? minVersion(pkg.engines.vscode)?.version : await resolveStable()
28+
if (!version) {
29+
console.log('Failed to resolve.')
30+
return ''
31+
}
32+
console.log(`Resolved version: ${version}`)
33+
const os = process.env.RUNNER_OS || process.platform
34+
const arch = process.arch
35+
const hash = crypto.createHash('sha256').update(version).digest('hex')
36+
return `vscode-cache-${os}-${arch}-${hash}`
37+
}
38+
39+
console.log('Generate the cache key for the vscode')
40+
const key = await generate()
41+
console.log(`Generated key: ${key}`)
42+
43+
core.setOutput('vscode-cache-key', key)

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)