Skip to content

Commit cd8845f

Browse files
committed
Test playwright caching
1 parent e61e287 commit cd8845f

File tree

7 files changed

+494
-244
lines changed

7 files changed

+494
-244
lines changed

.github/actions/build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const buildCommand = getBuildCommand({
66
entryPoints: [
77
{ in: './src/info/index.ts', out: 'info' },
88
{ in: './src/load-artifacts/index.ts', out: 'load' },
9+
{ in: './src/playwright-cache/index.ts', out: 'playwright' },
910
],
1011
format: 'esm',
1112
outdir: 'dist',

.github/actions/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
},
1212
"dependencies": {
1313
"@actions/artifact": "^2.3.2",
14+
"@actions/cache": "^4.0.5",
1415
"@actions/core": "^1.11.1",
1516
"@actions/exec": "^1.1.1",
17+
"@actions/tool-cache": "^2.0.2",
1618
"lodash": "^4.17.21"
1719
},
1820
"scripts": {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Playwright Cache
2+
description: Manages the installation of playwright and its dependencies
3+
4+
inputs:
5+
package-name:
6+
required: true
7+
description: Name of the package
8+
9+
runs:
10+
using: node20
11+
main: ../../dist/playwright.js
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import * as core from '@actions/core';
2+
import { getExecOutput } from '@actions/exec';
3+
import * as tc from '@actions/tool-cache';
4+
5+
interface YarnWhyEntry {
6+
value: string;
7+
children: {
8+
[name: string]: {
9+
locator: string;
10+
description: string;
11+
};
12+
};
13+
}
14+
15+
/**
16+
* Given the output from `yarn why`, figure out what the installed version is
17+
*/
18+
function findInstalledVersion(entry: YarnWhyEntry) {
19+
const RE = /^playwright@npm:(.+)$/;
20+
21+
for (const each of Object.keys(entry.children)) {
22+
const match = RE.exec(each);
23+
if (match) return match[1];
24+
}
25+
26+
throw new Error('Failed to find version');
27+
}
28+
29+
const RE = /^(@sourceacademy\/.+)@.+/;
30+
31+
async function main() {
32+
const { exitCode, stderr, stdout } = await getExecOutput('yarn', ['why', 'playwright', '--json'], { silent: true });
33+
34+
if (exitCode !== 0) {
35+
core.setFailed(stderr);
36+
return;
37+
}
38+
39+
const entries = stdout.trim().split('\n').map(each => JSON.parse(each) as YarnWhyEntry);
40+
const packageName = core.getInput('package-name', { required: true });
41+
// const packageName = '@sourceacademy/tab-Curve';
42+
43+
const entry = entries.find(each => {
44+
const match = RE.exec(each.value);
45+
if (!match) return false;
46+
const [, entryName] = match;
47+
return entryName === packageName;
48+
});
49+
50+
if (!entry) throw new Error(`${packageName} does not have playwright listed as a dependency.`);
51+
52+
const version = findInstalledVersion(entry);
53+
const playwrightDir = tc.find('playwright', version);
54+
55+
console.log(playwrightDir);
56+
}
57+
58+
await main();

.github/actions/src/playwright-cache/sample.json

Whitespace-only changes.

0 commit comments

Comments
 (0)