Skip to content

Commit ed3bab1

Browse files
authored
chore: fix ci workflows (conwnet#753)
1 parent 651de6f commit ed3bab1

9 files changed

Lines changed: 39 additions & 10 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010

1111
jobs:
1212
build:
13+
permissions:
14+
contents: read
15+
1316
strategy:
1417
matrix:
1518
os: [macos-14]
@@ -19,6 +22,8 @@ jobs:
1922

2023
steps:
2124
- uses: actions/checkout@v4
25+
with:
26+
persist-credentials: false
2227
- name: Use Node.js ${{ matrix.node-version }}
2328
uses: actions/setup-node@v4
2429
with:
@@ -28,5 +33,12 @@ jobs:
2833
- run: npm install
2934
- run: npm run eslint
3035
- run: npm run build
31-
- uses: microsoft/playwright-github-action@v1
32-
- run: npm run test:ci
36+
env:
37+
GITHUB_API_PREFIX: http://localhost:8080/api/github
38+
- name: Install snapshot test dependencies
39+
working-directory: tests
40+
run: npm ci && npx playwright install --with-deps
41+
- name: Run snapshot tests
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
run: npx start-server-and-test watch:dev-server http://localhost:8080 "env -u GITHUB_TOKEN npm --prefix tests test"

‎.github/workflows/test-wtih-vscode-build.yml‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,12 @@ jobs:
3737
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3838
run: npm run build
3939
- run: npm run link && npm run build
40-
- uses: microsoft/playwright-github-action@v1
41-
- run: npm run test:ci
40+
env:
41+
GITHUB_API_PREFIX: http://localhost:8080/api/github
42+
- name: Install snapshot test dependencies
43+
working-directory: tests
44+
run: npm ci && npx playwright install --with-deps
45+
- name: Run snapshot tests
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
run: npx start-server-and-test watch:dev-server http://localhost:8080 "env -u GITHUB_TOKEN npm --prefix tests test"

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ dist
44
out
55
node_modules
66
.worktrees/
7+
tests/__tests__/__image_snapshots__/__diff_output__/

‎docs/deployment.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ npm run build
9393
npx wrangler pages dev dist
9494
```
9595

96-
Omit the OAuth configuration and export for a preview without GitHub OAuth. Open `http://localhost:8788/conwnet/github1s`. This differs from `npm run watch`, whose webpack server runs on port `8080` and only proxies GitHub code search. See [Pages local development](https://developers.cloudflare.com/pages/functions/local-development/) and [local secrets](https://developers.cloudflare.com/pages/functions/bindings/#local-development-with-secrets).
96+
Omit the OAuth configuration and export for a preview without GitHub OAuth. Open `http://localhost:8788/conwnet/github1s`. See [Pages local development](https://developers.cloudflare.com/pages/functions/local-development/) and [local secrets](https://developers.cloudflare.com/pages/functions/bindings/#local-development-with-secrets).
9797

9898
## Other static hosts
9999

‎docs/development.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The install step also installs dependencies for the local extensions. Watch mode
2525

2626
Wait for the application and both extensions to finish compiling, then open [localhost:8080/conwnet/github1s](http://localhost:8080/conwnet/github1s). The development server uses port `8080` and writes generated assets to `dist/`.
2727

28-
GitHub code search is proxied by the development server. OAuth callback Functions are not run by `npm run watch`; use a manually supplied token for repository authentication or follow the [Pages development instructions](deployment.md#preview-pages-functions-locally).
28+
OAuth callback Functions are not run by `npm run watch`; use a manually supplied token for repository authentication or follow the [Pages development instructions](deployment.md#preview-pages-functions-locally).
2929

3030
## Build the application
3131

-44.9 KB
Loading
-18.3 KB
Loading

‎tests/__tests__/index.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ it('should load successfully', async () => {
6262

6363
it('should open file correctly', async () => {
6464
await page.goto(`${BASE_URL}/conwnet/github1s`);
65-
await page.waitForTimeout(3000);
65+
await page.waitForSelector('iframe.webview.ready');
6666
await page.click('[aria-label="~/tsconfig.json"]');
6767
await page.click('[data-resource-name="tsconfig.json"]');
68-
await page.waitForTimeout(3000);
68+
await page.waitForSelector('[role="tab"][aria-selected="true"][data-resource-name="tsconfig.json"]');
69+
await page.waitForSelector('.monaco-editor[data-uri="github1s:/tsconfig.json"] .view-lines');
6970

7071
const image = await page.screenshot();
7172
expect(image).toMatchImageSnapshot(matchImageSnapshotOptions);

‎webpack.config.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const devVscodeStatic = [
4646
export default (env, argv) => {
4747
const devMode = argv.mode === 'development';
4848
const devVscode = !!process.env.DEV_VSCODE;
49+
const ciGithubProxy = devMode && process.env.CI === 'true' && !!process.env.GITHUB_TOKEN;
4950
const minifyCSS = (code) => (devMode ? code : new CleanCSS().minify(code).styles);
5051
const minifyJS = (code) => (devMode ? code : UglifyJS.minify(code).code);
5152
const availableLanguages = devVscode ? [] : fs.readdirSync(path.join(vscodeWebPath, 'nls'));
@@ -94,24 +95,31 @@ export default (env, argv) => {
9495
],
9596
performance: false,
9697
devServer: {
98+
host: ciGithubProxy ? 'localhost' : undefined,
9799
port: 8080,
98100
proxy: [
99101
{
100-
context: ['/api/github/search/code'],
102+
// Used by code search and by CI builds that point GITHUB_API_PREFIX here.
103+
context: (pathname, req) => pathname.startsWith('/api/github/'),
101104
target: 'https://api.github.com',
102105
changeOrigin: true,
106+
followRedirects: false,
103107
pathRewrite: { '^/api/github': '' },
104108
headers: { 'user-agent': 'GitHub1s' },
105109
on: {
106110
proxyReq: (proxyReq) => {
107111
proxyReq.removeHeader('cookie');
108112
proxyReq.removeHeader('origin');
113+
if (ciGithubProxy) {
114+
// Set up credentials for the CI environment to avoid GitHub API rate limits.
115+
proxyReq.setHeader('authorization', `Bearer ${process.env.GITHUB_TOKEN}`);
116+
}
109117
},
110118
},
111119
},
112120
],
113121
liveReload: false,
114-
allowedHosts: 'all',
122+
allowedHosts: ciGithubProxy ? 'auto' : 'all',
115123
client: { overlay: false },
116124
devMiddleware: { writeToDisk: true },
117125
static: devVscode ? devVscodeStatic : [],

0 commit comments

Comments
 (0)