Files
Zakk 0ed10b68c7 ci(check): fix two flaky e2e tests and trim the nightly run (#705)
## Problem / 问题

A CI audit of the last ~200 Check runs (owner's report) found two more
intermittent e2e failures and a wasteful schedule:

- `e2e/dashboard.spec.ts:160` failed on WebKit on 11-08, 11-24 and
11-25. It measured the dashboard while the dnsAnswers and policyGroups
cards could still be titles only, and the level-column check passed on
the half-loaded page.
- `e2e/qiangguo.spec.ts:12` failed twice on main. It could scroll while
the startup frame was showing. `heldScroll.ts` then restored that offset
and undid the scripted scroll to the top, as designed.
- 25 of 26 nightly runs re-ran `check` and all nine e2e shards on a main
head its push had already checked, about 510 job minutes a week.

## How I fixed it / 解决方法

- The dashboard test waits for every card's content and for no loading
state before measuring.
- The Qiangguo test waits for the page's loading states to clear before
scrolling.
- On the schedule, `changes` and `ci-ok` are skipped, so only `nightly`
(Firefox) runs. `notify-nightly` treats a skipped `ci-ok` as not failed.
Push, PR and manual dispatch behave as before.

Assertions are unchanged. `failOnFlakyTests` stays on.

## Verified / 验证

- `pnpm format:check`, `lint`, `typecheck` and `test` exit 0.
- e2e in the CI image (`playwright:v1.63.0-noble`) with `CI=1
--retries=0`:
- dashboard: before, 1/200 at 2 workers and 6/80 at 4; after, 300/300 at
2 and at 4 workers.
- Qiangguo: before, failed 6/6 with the CI error when the page chunk is
held back past the first scroll; after, 600/600 at 2 and at 4 workers,
and 20/20 with the chunk delayed 1.5 s.
- actionlint 1.7.7 reports nothing. The scheduled path has not run on
GitHub yet.
2026-11-25 21:47:50 +11:00

315 lines
13 KiB
YAML

name: Check
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
schedule:
- cron: '23 16 * * *'
workflow_dispatch:
# A newer push to a pull request or to main supersedes the run still going on the older commit.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || (github.event_name == 'push' && github.ref) || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }}
permissions:
contents: read
jobs:
# The schedule runs on main's head, which its push already checked, so it runs only the nightly job; without this job
# every lane below it is skipped. A manual dispatch still runs the full lane with the nightly one.
changes:
if: github.event_name != 'schedule'
runs-on: ubuntu-24.04-arm
timeout-minutes: 3
outputs:
lane: ${{ steps.route.outputs.lane }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- id: route
name: Select checks and require changelog fragments
run: node tools/ci-changes.mjs
check-lite:
needs: [changes]
if: needs.changes.outputs.lane == 'docs'
runs-on: ubuntu-24.04-arm
timeout-minutes: 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm format:check
- run: pnpm check:i18n
# Static checks, unit tests and the bundle budget: a few minutes, independent of the browsers.
check:
needs: [changes]
if: needs.changes.outputs.lane == 'full'
runs-on: ubuntu-24.04-arm
timeout-minutes: 10
# actions: read finds main's size measurement for the run summary.
permissions:
actions: read
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm typecheck
- run: pnpm lint
- run: pnpm check:i18n
- run: pnpm format:check
- run: pnpm test:coverage
- run: pnpm -C apps/lite install --frozen-lockfile
- run: pnpm -C apps/lite check
- run: pnpm check:gen
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: coverage
path: coverage/lcov.info
if-no-files-found: error
- run: pnpm build
# The measurement is kept on every run, main's included, as the baseline later pull requests compare against.
- name: Check the size budgets
run: pnpm check:size --json size-report.json --commit "$COMMIT" --base "$BASE"
env:
COMMIT: ${{ github.event.pull_request.head.sha || github.sha }}
BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: ${{ !cancelled() && hashFiles('size-report.json') != '' }}
with:
name: size-report
path: size-report.json
if-no-files-found: error
# The pull request comment (report.yml) only runs from main, so the run summary shows the same table before that.
- name: Show the size report
if: ${{ !cancelled() && hashFiles('size-report.json') != '' }}
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
run: |
tools/size-baseline.sh "$REPO" "$BASE" "$RUNNER_TEMP/size-baseline"
node tools/size-report.mjs size-report.json "$RUNNER_TEMP/size-baseline/size-report.json" >> "$GITHUB_STEP_SUMMARY"
# The browser suite is most of the run's time, so it is split over parallel runners; each builds its own dist.
e2e:
needs: [changes]
if: needs.changes.outputs.lane == 'full'
runs-on: ubuntu-24.04-arm
timeout-minutes: 15
# Update the tag and digest together with @playwright/test.
container:
image: mcr.microsoft.com/playwright:v1.63.0-noble@sha256:eff16c30e6f3f4af0a03fa4b706120d5e9b0891c344a27d64559aff5900a4a27
options: --ipc=host
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4, 5, 6, 7, 8, 9]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Match the container to @playwright/test
run: test "$(node -p "require('./package.json').devDependencies['@playwright/test']")" = "${PLAYWRIGHT_VERSION}"
env:
PLAYWRIGHT_VERSION: 1.63.0
- name: Run the browser shard
# The shard sizes come from the recorded test times (tools/e2e-shards.mjs), so every shard takes about as long as the others.
# If they cannot be computed the shard runs with Playwright's default split instead of failing.
run: |
if weights=$(node tools/e2e-shards.mjs weights "${{ strategy.job-total }}"); then
export PWTEST_SHARD_WEIGHTS="$weights"
else
echo "::warning::Could not balance the e2e shards by test time; running Playwright's default split."
fi
pnpm e2e --shard=${{ matrix.shard }}/${{ strategy.job-total }} --reporter=list,github,blob,json
env:
DOONA_E2E_WEBKIT: '1'
# Uploaded with test-results; `node tools/e2e-shards.mjs record` turns these reports into the recorded times.
PLAYWRIGHT_JSON_OUTPUT_FILE: test-results/e2e-${{ matrix.shard }}.json
- name: Summarize the shard
if: always()
env:
REPORT: test-results/e2e-${{ matrix.shard }}.json
SHARD: ${{ matrix.shard }}
run: |
node <<'JS'
const fs = require('node:fs');
const heading = `### Browser shard ${process.env.SHARD}\n\n`;
let summary = 'Report unavailable; see the failed or cancelled steps.\n';
if (fs.existsSync(process.env.REPORT)) {
const {stats} = JSON.parse(fs.readFileSync(process.env.REPORT, 'utf8'));
summary = `Duration: ${(stats.duration / 1000).toFixed(1)} s\n\n` +
`| Passed | Failed | Flaky | Skipped |\n| --- | --- | --- | --- |\n` +
`| ${stats.expected} | ${stats.unexpected} | ${stats.flaky} | ${stats.skipped} |\n`;
}
fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, heading + summary);
JS
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: always()
with:
name: test-results-${{ matrix.shard }}
path: test-results/
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: ${{ !cancelled() }}
with:
name: blob-report-${{ matrix.shard }}
path: blob-report/
if-no-files-found: ignore
retention-days: 1
merge-reports:
if: ${{ !cancelled() && needs.e2e.result != 'skipped' }}
needs: [e2e]
runs-on: ubuntu-24.04-arm
timeout-minutes: 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
path: all-blob-reports
pattern: blob-report-*
merge-multiple: true
- name: Require blob reports from the browser shards
run: |
shopt -s nullglob
blobs=(all-blob-reports/*.zip)
if [ "${#blobs[@]}" -eq 0 ]; then
echo '::error::The browser jobs ran but produced no blob reports; inspect the failed e2e steps.'
exit 1
fi
- run: pnpm exec playwright merge-reports --reporter html ./all-blob-reports
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: playwright-report
path: playwright-report/
if-no-files-found: error
retention-days: 14
ci-ok:
needs: [changes, check-lite, check, e2e, merge-reports]
if: always() && github.event_name != 'schedule'
runs-on: ubuntu-24.04-arm
timeout-minutes: 3
steps:
- name: Require the selected lane
env:
NEEDS: ${{ toJSON(needs) }}
run: |
node <<'JS'
const needs = JSON.parse(process.env.NEEDS);
const lane = needs.changes.outputs.lane;
const selected = lane === 'docs' ? ['check-lite'] : lane === 'full' ? ['check', 'e2e', 'merge-reports'] : [];
const lanes = ['check-lite', 'check', 'e2e', 'merge-reports'];
const ok = needs.changes.result === 'success' && selected.length > 0 &&
lanes.every(job => needs[job].result === (selected.includes(job) ? 'success' : 'skipped'));
if (!ok) {
console.error('CI lane did not complete successfully', needs);
process.exit(1);
}
JS
nightly:
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-24.04-arm
timeout-minutes: 25
container:
image: mcr.microsoft.com/playwright:v1.63.0-noble@sha256:eff16c30e6f3f4af0a03fa4b706120d5e9b0891c344a27d64559aff5900a4a27
options: --ipc=host --user 1001
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Match the container to @playwright/test
run: test "$(node -p "require('./package.json').devDependencies['@playwright/test']")" = "${PLAYWRIGHT_VERSION}"
env:
PLAYWRIGHT_VERSION: 1.63.0
- name: Run Firefox connections and router
env:
DOONA_E2E_FIREFOX: '1'
run: |
cat > playwright.firefox.config.ts <<'TS'
import config from './playwright.config';
export default {
...config,
projects: config.projects.filter(project => project.name === 'firefox').map(project => ({
...project, testMatch: ['connections.spec.ts', 'router.spec.ts']
}))
};
TS
pnpm build
pnpm exec playwright test --config=playwright.firefox.config.ts
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: ${{ !cancelled() }}
with:
name: firefox-test-results
path: test-results/
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: ${{ !cancelled() }}
with:
name: firefox-blob-report
path: blob-report/
if-no-files-found: ignore
retention-days: 1
notify-nightly:
needs: [ci-ok, nightly]
# ci-ok is skipped on the schedule, which is not a failure.
if: ${{ always() && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && (!contains(fromJSON('["success", "skipped"]'), needs.ci-ok.result) || needs.nightly.result != 'success') }}
runs-on: ubuntu-24.04-arm
timeout-minutes: 3
permissions:
contents: read
issues: write
concurrency:
group: nightly-failure-issue
cancel-in-progress: false
steps:
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
RESULTS: ${{ toJSON(needs) }}
with:
script: |
const marker = '<!-- doona-nightly-failure -->';
const title = 'CI nightly failures';
const results = JSON.parse(process.env.RESULTS);
const url = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const body = `${marker}\nLatest failing nightly: ${url}\n\n` +
Object.entries(results).map(([job, value]) => `- ${job}: ${value.result}`).join('\n');
const issues = await github.paginate(github.rest.search.issuesAndPullRequests, {
q: `repo:${context.repo.owner}/${context.repo.repo} is:issue in:title "${title}"`,
sort: 'created', order: 'asc', per_page: 100
});
const issue = issues.find(issue => issue.title === title);
if (issue) {
await github.rest.issues.update({...context.repo, issue_number: issue.number, body, state: 'open'});
} else {
await github.rest.issues.create({...context.repo, title, body});
}