Files
admin-frontend-domain/.github/workflows/e2e.yml
T
naibaandcloudcode 52f67d22ba ci: run Playwright e2e against a real Go backend in GitHub Actions
Boot a fresh dashboard from nezhahq/nezha master inside the runner:

- Checkout admin-frontend and the backend repo into two paths.
- Generate the two embed stubs and swag docs so cmd/dashboard builds.
- Inject NZ_JWTSECRETKEY (env-first config story) and start the
  backend on 127.0.0.1:8008 with a tmp SQLite db.
- Wait on /api/v1/setting before letting Playwright launch.
- Playwright config brings up Vite dev which proxies /api to 8008.
- Upload playwright-report and dashboard.log on failure for triage.

Co-authored-by: cloudcode <cloudcode@users.noreply.github.com>
2026-05-26 04:34:43 +00:00

130 lines
3.4 KiB
YAML

name: E2E
on:
push:
branches:
- main
paths:
- "src/**"
- "tests/e2e/**"
- "playwright.config.ts"
- "package.json"
- "package-lock.json"
- ".github/workflows/e2e.yml"
pull_request:
branches:
- main
jobs:
playwright:
runs-on: ubuntu-latest
timeout-minutes: 25
env:
NEZHA_REPO: nezhahq/nezha
NEZHA_REF: master
NZ_LISTENHOST: 127.0.0.1
NZ_LISTENPORT: "8008"
NZ_AGENTSECRETKEY: e2e-agent-secret-32-bytes-long-ok
NZ_JWTSECRETKEY: e2e-jwt-secret-key-min-32-chars-long-ok
NZ_SITENAME: nezha-e2e
NZ_DEBUG: "true"
E2E_ADMIN_USER: admin
E2E_ADMIN_PASS: admin
E2E_BASE_URL: http://127.0.0.1:5173
steps:
- name: Checkout admin-frontend
uses: actions/checkout@v4
with:
path: admin-frontend
- name: Checkout nezha backend
uses: actions/checkout@v4
with:
repository: ${{ env.NEZHA_REPO }}
ref: ${{ env.NEZHA_REF }}
path: nezha
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: admin-frontend/package-lock.json
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.26.x"
cache-dependency-path: nezha/go.sum
- name: Install frontend dependencies
working-directory: admin-frontend
run: npm ci
- name: Install Playwright browsers
working-directory: admin-frontend
run: npx playwright install --with-deps chromium
- name: Prepare backend stubs (dist + swagger docs)
working-directory: nezha
run: |
mkdir -p cmd/dashboard/admin-dist cmd/dashboard/user-dist
touch cmd/dashboard/admin-dist/.gitkeep cmd/dashboard/user-dist/.gitkeep
go install github.com/swaggo/swag/cmd/swag@latest
"$(go env GOPATH)/bin/swag" init --pd -d cmd/dashboard -g main.go -o cmd/dashboard/docs
- name: Start backend
working-directory: nezha
env:
GIN_MODE: release
run: |
mkdir -p data
nohup go run ./cmd/dashboard -c data/config.yaml -db data/sqlite.db \
> /tmp/dashboard.log 2>&1 &
echo $! > /tmp/dashboard.pid
- name: Wait for backend health
run: |
for i in {1..60}; do
if curl -fsS http://127.0.0.1:8008/api/v1/setting > /dev/null; then
echo "backend is up"
exit 0
fi
sleep 1
done
echo "backend failed to start within 60s"
echo "---- dashboard.log ----"
cat /tmp/dashboard.log || true
exit 1
- name: Run Playwright tests
working-directory: admin-frontend
env:
CI: "true"
run: npm run e2e
- name: Upload Playwright report
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: admin-frontend/playwright-report
retention-days: 14
- name: Upload dashboard log
if: always()
uses: actions/upload-artifact@v4
with:
name: dashboard-log
path: /tmp/dashboard.log
retention-days: 7
- name: Stop backend
if: always()
run: |
if [ -f /tmp/dashboard.pid ]; then
kill "$(cat /tmp/dashboard.pid)" || true
fi