Skip to content

Commit 596991f

Browse files
authored
ci: run e2e on direct main pushes only (#195)
* ci: run e2e on direct main pushes only Keep E2E as a PR check, but skip redundant runs on merge commits by running on main only when the pushed commit is not associated with any PR. * ci: ensure e2e runs on PRs Make the direct-push detection job always complete so PR-triggered E2E isn't skipped due to a missing/conditional dependency. * ci: update e2e workflow to use Playwright container Configure the e2e job to run in a Playwright container, improving consistency and reliability. Removed caching and installation steps for Playwright browsers as they are now handled within the container. * ci: install unzip in e2e container Ensure oven-sh/setup-bun works inside the Playwright container by installing unzip before setting up Bun. * ci: set HOME for Firefox in playwright container Playwright Firefox requires $HOME to be owned by the running user inside the container; set HOME=/root so Firefox can launch reliably in CI. * ci: update e2e workflow to set HOME for Playwright user Change the HOME environment variable to /home/pwuser and add user option to the Playwright container to ensure proper permissions for Firefox execution in CI. * ci: use correct Playwright container user uid Run the e2e container as uid 1000 so actions and Playwright Firefox share a writable, owned home directory and avoid checkout permission failures. * ci: restore root runner context in e2e container Remove the custom container user so GitHub action file commands can write to runner temp paths, while keeping HOME on /root for Firefox launch stability. --------- Co-authored-by: Nico Prananta <311343+nicnocquee@users.noreply.github.com>
1 parent 1902d00 commit 596991f

1 file changed

Lines changed: 49 additions & 12 deletions

File tree

.github/workflows/e2e.yml

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,55 @@ on:
77
- main
88
workflow_dispatch:
99

10+
permissions:
11+
contents: read
12+
pull-requests: read
13+
1014
concurrency:
1115
group: e2e-${{ github.workflow }}-${{ github.ref }}
1216
cancel-in-progress: true
1317

1418
jobs:
19+
direct_push_check:
20+
name: Detect direct push to main
21+
runs-on: ubuntu-latest
22+
outputs:
23+
is_direct: ${{ steps.detect.outputs.is_direct }}
24+
steps:
25+
- name: Determine if commit belongs to a PR
26+
id: detect
27+
uses: actions/github-script@v8
28+
with:
29+
script: |
30+
if (context.eventName !== 'push' || context.ref !== 'refs/heads/main') {
31+
// Only `push` to `main` needs direct-vs-merge detection.
32+
core.setOutput('is_direct', 'false')
33+
return
34+
}
35+
36+
const sha = context.sha
37+
// If this commit is associated with any PR, it's almost certainly coming from a PR merge.
38+
// Direct pushes to main won't have associated PRs.
39+
const { data } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
40+
owner: context.repo.owner,
41+
repo: context.repo.repo,
42+
commit_sha: sha,
43+
})
44+
45+
core.setOutput('is_direct', String(data.length === 0))
46+
1547
e2e:
1648
runs-on: ubuntu-latest
49+
container:
50+
image: mcr.microsoft.com/playwright:v1.57.0-jammy
51+
options: --ipc=host
52+
needs: [direct_push_check]
53+
if: |
54+
github.event_name == 'pull_request' ||
55+
(github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.direct_push_check.outputs.is_direct == 'true')
56+
env:
57+
# Playwright's Firefox won't launch in the container unless $HOME is owned by the current user.
58+
HOME: /root
1759
timeout-minutes: 45
1860
strategy:
1961
fail-fast: false
@@ -46,6 +88,9 @@ jobs:
4688
- name: Checkout
4789
uses: actions/checkout@v6
4890

91+
- name: Install unzip
92+
run: apt-get update && apt-get install -y unzip
93+
4994
- name: Setup Bun
5095
uses: oven-sh/setup-bun@v2
5196
with:
@@ -62,17 +107,6 @@ jobs:
62107
- name: Install dependencies
63108
run: bun install --frozen-lockfile
64109

65-
- name: Cache Playwright browsers
66-
uses: actions/cache@v4
67-
with:
68-
path: ~/.cache/ms-playwright
69-
# Cache per-browser to avoid cross-job races and partial caches
70-
# when matrix runs in parallel.
71-
key: ${{ runner.os }}-playwright-${{ matrix.browser }}-${{ hashFiles('bun.lock') }}
72-
73-
- name: Install Playwright browsers
74-
run: bunx playwright install ${{ matrix.browser }} --with-deps
75-
76110
- name: Build app
77111
run: bun run build
78112

@@ -94,11 +128,14 @@ jobs:
94128
name: Merge Playwright report
95129
runs-on: ubuntu-latest
96130
if: always()
97-
needs: [e2e]
131+
needs: [direct_push_check, e2e]
98132
steps:
99133
- name: Checkout
100134
uses: actions/checkout@v6
101135

136+
- name: Install unzip
137+
run: sudo apt-get update && sudo apt-get install -y unzip
138+
102139
- name: Setup Bun
103140
uses: oven-sh/setup-bun@v2
104141
with:

0 commit comments

Comments
 (0)