|
| 1 | +name: "Run Playwright tests" |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + - 'releases/*' |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + test-linux: |
| 13 | + name: Playwright tests on ${{ matrix.os }} (headless=${{ matrix.headless }}) |
| 14 | + runs-on: ubuntu-20.04 |
| 15 | + |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + headless: [true] |
| 20 | + |
| 21 | + steps: |
| 22 | + # 1. Checkout the repository |
| 23 | + - uses: actions/checkout@v3 |
| 24 | + |
| 25 | + # 2. Setup Node.js |
| 26 | + - name: Setup Node.js |
| 27 | + uses: actions/setup-node@v3 |
| 28 | + with: |
| 29 | + node-version: '20' |
| 30 | + |
| 31 | + # 3. Setup pnpm |
| 32 | + - name: Setup pnpm |
| 33 | + uses: pnpm/action-setup@v2 |
| 34 | + with: |
| 35 | + version: 7.x |
| 36 | + |
| 37 | + # 4. Cache pnpm dependencies |
| 38 | + - name: Cache pnpm dependencies |
| 39 | + uses: actions/cache@v3 |
| 40 | + with: |
| 41 | + path: | |
| 42 | + ~/.pnpm-store |
| 43 | + node_modules |
| 44 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 45 | + restore-keys: | |
| 46 | + ${{ runner.os }}-pnpm-store- |
| 47 | +
|
| 48 | + # 5. Cache Playwright browsers |
| 49 | + - name: Cache Playwright browsers |
| 50 | + uses: actions/cache@v3 |
| 51 | + with: |
| 52 | + path: ~/.cache/ms-playwright |
| 53 | + key: ${{ runner.os }}-playwright-${{ hashFiles('**/package.json') }} |
| 54 | + restore-keys: | |
| 55 | + ${{ runner.os }}-playwright- |
| 56 | +
|
| 57 | + # 6. Install dependencies |
| 58 | + - name: Install dependencies |
| 59 | + run: pnpm install |
| 60 | + |
| 61 | + # 7. Cache build output for idb-cache package |
| 62 | + - name: Cache idb-cache build output |
| 63 | + uses: actions/cache@v3 |
| 64 | + with: |
| 65 | + path: packages/idb-cache/dist |
| 66 | + key: ${{ runner.os }}-idb-cache-build-${{ hashFiles('packages/idb-cache/**/*.ts') }} |
| 67 | + restore-keys: | |
| 68 | + ${{ runner.os }}-idb-cache-build- |
| 69 | +
|
| 70 | + # 8. Build the @instructure/idb-cache package |
| 71 | + - name: Build idb-cache package |
| 72 | + run: pnpm --filter @instructure/idb-cache build |
| 73 | + |
| 74 | + # 9. Cache build output for idb-cache-app |
| 75 | + - name: Cache idb-cache-app build output |
| 76 | + uses: actions/cache@v3 |
| 77 | + with: |
| 78 | + path: apps/idb-cache-app/dist |
| 79 | + key: ${{ runner.os }}-idb-cache-app-build-${{ hashFiles('apps/idb-cache-app/**/*.ts') }} |
| 80 | + restore-keys: | |
| 81 | + ${{ runner.os }}-idb-cache-app-build- |
| 82 | +
|
| 83 | + # 10. Build the idb-cache-app |
| 84 | + - name: Build idb-cache-app |
| 85 | + run: pnpm --filter idb-cache-app build |
| 86 | + |
| 87 | + # 11. Install Playwright browsers |
| 88 | + - name: Install Playwright browsers |
| 89 | + run: pnpm --filter idb-cache-app exec playwright install |
| 90 | + |
| 91 | + # 12. Serve the idb-cache-app |
| 92 | + - name: Serve idb-cache-app |
| 93 | + run: pnpm --filter idb-cache-app preview -- --port 3000 & |
| 94 | + # The '&' runs the serve command in the background |
| 95 | + |
| 96 | + # 13. Wait for the server to be ready |
| 97 | + - name: Wait for idb-cache-app to be ready |
| 98 | + run: | |
| 99 | + for i in {1..60}; do |
| 100 | + if curl -s http://localhost:3000 > /dev/null; then |
| 101 | + echo "Server is ready!" |
| 102 | + break |
| 103 | + fi |
| 104 | + echo "Waiting for server to be ready... ($i/60)" |
| 105 | + sleep 1 |
| 106 | + done |
| 107 | +
|
| 108 | + # 14. Run Playwright tests in headless mode |
| 109 | + - name: Run Playwright tests (Headless) |
| 110 | + if: ${{ matrix.headless == true }} |
| 111 | + run: pnpm --filter idb-cache-app test |
| 112 | + |
| 113 | + # 15. Run Playwright tests in headful mode on Linux |
| 114 | + - name: Run Playwright tests (Headful) |
| 115 | + if: ${{ matrix.headless == false }} |
| 116 | + run: | |
| 117 | + export HEADFUL=true |
| 118 | + xvfb-run --auto-servernum -- pnpm --filter idb-cache-app test |
0 commit comments