From a14c67f189abe6b64ecf9f66c15ae3a37e8b0e56 Mon Sep 17 00:00:00 2001 From: Lectom C Han Date: Fri, 20 Feb 2026 10:14:53 +0900 Subject: [PATCH] ci: simplify adminfront runner flow and stabilize e2e auth state --- .gitea/workflows/code_check.yml | 105 ++--------------------- adminfront/tests/user-management.spec.ts | 21 ++++- scripts/run_adminfront_ci_tests.sh | 93 ++++++++++++++++++++ 3 files changed, 119 insertions(+), 100 deletions(-) create mode 100755 scripts/run_adminfront_ci_tests.sh diff --git a/.gitea/workflows/code_check.yml b/.gitea/workflows/code_check.yml index 06a2bd93..5c1e2546 100644 --- a/.gitea/workflows/code_check.yml +++ b/.gitea/workflows/code_check.yml @@ -146,7 +146,7 @@ jobs: - name: Upload backend failure report artifact if: ${{ failure() }} - uses: actions/upload-artifact@v6 + uses: actions/upload-artifact@v3 continue-on-error: true with: name: backend-test-failure-report @@ -158,7 +158,7 @@ jobs: userfront-tests: needs: lint if: ${{ always() && (github.event_name != 'workflow_dispatch' || inputs.run_userfront_tests == true) }} - runs-on: ubuntu-latest + runs-on: ubuntu-latest-slim steps: - name: Checkout code uses: actions/checkout@v4 @@ -235,7 +235,7 @@ jobs: - name: Upload userfront failure report artifact if: ${{ failure() }} - uses: actions/upload-artifact@v6 + uses: actions/upload-artifact@v3 continue-on-error: true with: name: userfront-test-failure-report @@ -247,7 +247,8 @@ jobs: adminfront-tests: needs: lint if: ${{ always() && (github.event_name != 'workflow_dispatch' || inputs.run_adminfront_tests == true) }} - runs-on: ubuntu-latest + runs-on: playwright + timeout-minutes: 30 steps: - name: Checkout code uses: actions/checkout@v4 @@ -259,97 +260,9 @@ jobs: cache: "npm" cache-dependency-path: adminfront/package-lock.json - - name: Install adminfront dependencies - run: | - mkdir -p reports - set +e - cd adminfront - npm ci 2>&1 | tee ../reports/adminfront-install.log - install_exit_code=${PIPESTATUS[0]} - cd .. - set -e - - if [ "$install_exit_code" -ne 0 ]; then - { - echo "# Adminfront Test Failure Report" - echo - echo "- Workflow: \`${GITHUB_WORKFLOW:-Code Check}\`" - echo "- Job: \`adminfront-tests\`" - echo "- Reason: \`Dependency install failed\`" - echo "- Exit Code: \`$install_exit_code\`" - echo - echo "## Command" - echo "\`cd adminfront && npm ci\`" - echo - echo "## Install Log Tail (last 200 lines)" - echo '```text' - tail -n 200 reports/adminfront-install.log - echo '```' - } > reports/adminfront-test-failure-report.md - exit 1 - fi - - - name: Provision browsers for adminfront tests - run: | - set +e - cd adminfront - npx playwright install --with-deps 2>&1 | tee ../reports/adminfront-provision.log - provision_exit_code=${PIPESTATUS[0]} - cd .. - set -e - - if [ "$provision_exit_code" -ne 0 ]; then - { - echo "# Adminfront Test Failure Report" - echo - echo "- Workflow: \`${GITHUB_WORKFLOW:-Code Check}\`" - echo "- Job: \`adminfront-tests\`" - echo "- Reason: \`Browser provisioning failed\`" - echo "- Exit Code: \`$provision_exit_code\`" - echo - echo "## Command" - echo "\`cd adminfront && npx playwright install --with-deps\`" - echo - echo "## Provision Log Tail (last 200 lines)" - echo '```text' - tail -n 200 reports/adminfront-provision.log - echo '```' - } > reports/adminfront-test-failure-report.md - exit 1 - fi - - name: Run adminfront tests run: | - mkdir -p reports - set +e - cd adminfront - npm test 2>&1 | tee ../reports/adminfront-test.log - test_exit_code=${PIPESTATUS[0]} - cd .. - set -e - - if [ "$test_exit_code" -ne 0 ]; then - { - echo "# Adminfront Test Failure Report" - echo - echo "- Workflow: \`${GITHUB_WORKFLOW:-Code Check}\`" - echo "- Job: \`adminfront-tests\`" - echo "- Exit Code: \`$test_exit_code\`" - echo - echo "## Commands" - echo "1. \`cd adminfront\`" - echo "2. \`npm ci\`" - echo "3. \`npx playwright install --with-deps\`" - echo "4. \`npm test\`" - echo - echo "## Log Tail (last 200 lines)" - echo '```text' - tail -n 200 reports/adminfront-test.log - echo '```' - } > reports/adminfront-test-failure-report.md - fi - - exit "$test_exit_code" + scripts/run_adminfront_ci_tests.sh adminfront-tests - name: Ensure adminfront failure report exists if: ${{ failure() }} @@ -397,7 +310,7 @@ jobs: - name: Upload adminfront failure report artifact if: ${{ failure() }} - uses: actions/upload-artifact@v6 + uses: actions/upload-artifact@v3 continue-on-error: true with: name: adminfront-test-failure-report @@ -413,7 +326,7 @@ jobs: devfront-tests: needs: lint if: ${{ always() && (github.event_name != 'workflow_dispatch' || inputs.run_devfront_tests == true) }} - runs-on: ubuntu-latest + runs-on: playwright steps: - name: Checkout code uses: actions/checkout@v4 @@ -563,7 +476,7 @@ jobs: - name: Upload devfront failure report artifact if: ${{ failure() }} - uses: actions/upload-artifact@v6 + uses: actions/upload-artifact@v3 continue-on-error: true with: name: devfront-test-failure-report diff --git a/adminfront/tests/user-management.spec.ts b/adminfront/tests/user-management.spec.ts index 1614c547..4f2aaef0 100644 --- a/adminfront/tests/user-management.spec.ts +++ b/adminfront/tests/user-management.spec.ts @@ -23,14 +23,27 @@ type UserCreatePayload = { department?: string; }; +test.use({ + storageState: { + cookies: [], + origins: [ + { + origin: "http://localhost:5173", + localStorage: [ + { + name: "admin_session", + value: "playwright-admin-session", + }, + ], + }, + ], + }, +}); + test("user create and delete flow", async ({ page }) => { const users: UserSummary[] = []; let idSeq = 1; - await page.addInitScript(() => { - window.localStorage.setItem("admin_session", "playwright-admin-session"); - }); - await page.route("**/api/v1/admin/users**", async (route) => { const request = route.request(); const url = new URL(request.url()); diff --git a/scripts/run_adminfront_ci_tests.sh b/scripts/run_adminfront_ci_tests.sh new file mode 100755 index 00000000..4551582c --- /dev/null +++ b/scripts/run_adminfront_ci_tests.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +set -euo pipefail + +job_name="${1:-adminfront-tests}" + +mkdir -p reports + +set +e +( + cd adminfront + npm ci +) 2>&1 | tee reports/adminfront-install.log +install_exit_code=${PIPESTATUS[0]} +set -e + +if [ "$install_exit_code" -ne 0 ]; then + { + echo "# Adminfront Test Failure Report" + echo + echo "- Workflow: \`${GITHUB_WORKFLOW:-Code Check}\`" + echo "- Job: \`${job_name}\`" + echo "- Reason: \`Dependency install failed\`" + echo "- Exit Code: \`$install_exit_code\`" + echo + echo "## Command" + echo "\`cd adminfront && npm ci\`" + echo + echo "## Install Log Tail (last 200 lines)" + echo '```text' + tail -n 200 reports/adminfront-install.log + echo '```' + } > reports/adminfront-test-failure-report.md + exit 1 +fi + +set +e +( + cd adminfront + npx playwright install --with-deps +) 2>&1 | tee reports/adminfront-provision.log +provision_exit_code=${PIPESTATUS[0]} +set -e + +if [ "$provision_exit_code" -ne 0 ]; then + { + echo "# Adminfront Test Failure Report" + echo + echo "- Workflow: \`${GITHUB_WORKFLOW:-Code Check}\`" + echo "- Job: \`${job_name}\`" + echo "- Reason: \`Browser provisioning failed\`" + echo "- Exit Code: \`$provision_exit_code\`" + echo + echo "## Command" + echo "\`cd adminfront && npx playwright install --with-deps\`" + echo + echo "## Provision Log Tail (last 200 lines)" + echo '```text' + tail -n 200 reports/adminfront-provision.log + echo '```' + } > reports/adminfront-test-failure-report.md + exit 1 +fi + +set +e +( + cd adminfront + npm test +) 2>&1 | tee reports/adminfront-test.log +test_exit_code=${PIPESTATUS[0]} +set -e + +if [ "$test_exit_code" -ne 0 ]; then + { + echo "# Adminfront Test Failure Report" + echo + echo "- Workflow: \`${GITHUB_WORKFLOW:-Code Check}\`" + echo "- Job: \`${job_name}\`" + echo "- Exit Code: \`$test_exit_code\`" + echo + echo "## Commands" + echo "1. \`cd adminfront\`" + echo "2. \`npm ci\`" + echo "3. \`npx playwright install --with-deps\`" + echo "4. \`npm test\`" + echo + echo "## Log Tail (last 200 lines)" + echo '```text' + tail -n 200 reports/adminfront-test.log + echo '```' + } > reports/adminfront-test-failure-report.md +fi + +exit "$test_exit_code"