|
1 | | - |
2 | 1 | # Copyright 2025 Google LLC |
3 | 2 | # |
4 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
|
13 | 12 | # See the License for the specific language governing permissions and |
14 | 13 | # limitations under the License. |
15 | 14 |
|
16 | | -name: Test |
| 15 | +name: Playwright Tests |
| 16 | + |
17 | 17 | on: |
18 | | - push: |
19 | | - branches: [ main ] |
20 | 18 | pull_request: |
21 | | - branches: [ main ] |
| 19 | + branches: |
| 20 | + - main |
22 | 21 | types: [opened, synchronize, edited] |
23 | 22 | paths: |
24 | 23 | - 'samples/**' |
| 24 | + - 'e2e/samples.spec.ts' |
| 25 | + - 'playwright.config.ts' |
| 26 | + - 'package.json' |
| 27 | + paths-ignore: |
| 28 | + - '.github/dependabot.yml' |
| 29 | + - 'package-lock.json' |
| 30 | + push: |
| 31 | + branches: |
| 32 | + - main |
| 33 | + paths: |
| 34 | + - 'samples/**' |
| 35 | + - 'e2e/samples.spec.ts' |
| 36 | + - 'playwright.config.ts' |
| 37 | + - 'package.json' |
| 38 | + paths-ignore: |
| 39 | + - '.github/dependabot.yml' |
| 40 | + - 'package-lock.json' |
| 41 | + schedule: |
| 42 | + - cron: "0 12 * * *" |
| 43 | + |
25 | 44 | concurrency: |
26 | | - group: test-${{ github.ref }} |
| 45 | + group: ${{ github.workflow }}-${{ github.ref }} |
27 | 46 | cancel-in-progress: true |
| 47 | + |
28 | 48 | jobs: |
29 | | - test: |
30 | | - if: github.event.pull_request.merged == false |
| 49 | + pr_and_push_tests: |
| 50 | + name: Playwright PR/Push Tests |
| 51 | + if: | |
| 52 | + (github.event_name == 'pull_request' && github.event.pull_request.merged == false) || |
| 53 | + (github.event_name == 'push' && !contains(github.event.head_commit.message, 'chore: update dist folder')) |
| 54 | + runs-on: ubuntu-latest |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v4 |
| 57 | + with: |
| 58 | + lfs: true |
| 59 | + |
| 60 | + - name: Get Affected Workspaces |
| 61 | + id: get_workspaces |
| 62 | + run: bash samples/find-changes.sh ${{ github.event_name == 'pull_request' && github.base_ref || 'origin/main' }} |
| 63 | + |
| 64 | + - name: Setup Node.js |
| 65 | + uses: actions/setup-node@v4 |
| 66 | + with: |
| 67 | + node-version: '20' |
| 68 | + |
| 69 | + - name: Cache npm dependencies |
| 70 | + uses: actions/cache@v4 |
| 71 | + with: |
| 72 | + path: ~/.npm |
| 73 | + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
| 74 | + restore-keys: | |
| 75 | + ${{ runner.os }}-node- |
| 76 | +
|
| 77 | + - name: Cache Playwright browsers |
| 78 | + uses: actions/cache@v4 |
| 79 | + with: |
| 80 | + path: ~/.cache/ms-playwright |
| 81 | + key: ${{ runner.os }}-playwright-${{ hashFiles('playwright.config.ts', 'package.json') }} |
| 82 | + restore-keys: | |
| 83 | + ${{ runner.os }}-playwright- |
| 84 | +
|
| 85 | + - name: Install dependencies |
| 86 | + run: npm ci |
| 87 | + |
| 88 | + - name: Build Affected Projects |
| 89 | + if: steps.get_workspaces.outputs.affected_workspaces != '' |
| 90 | + run: | |
| 91 | + IFS=$'\n' |
| 92 | + AFFECTED_WORKSPACES_ARRAY=(${{ steps.get_workspaces.outputs.affected_workspaces }}) |
| 93 | + |
| 94 | + echo "Building affected workspaces:" |
| 95 | + for workspace in "${AFFECTED_WORKSPACES_ARRAY[@]}"; do |
| 96 | + echo " - samples/$workspace" |
| 97 | + npm run build --workspace=samples/$workspace |
| 98 | + done |
| 99 | +
|
| 100 | + - name: Generate Index (Run Once After Builds) |
| 101 | + run: bash samples/generate-index.sh |
| 102 | + # Consider adding an 'if' condition if it only needs to run when 'samples/' changed at all. |
| 103 | + # if: | |
| 104 | + # steps.get_workspaces.outputs.affected_workspaces != '' || # If any workspace built |
| 105 | + # contains(github.event.pull_request.paths.*, 'samples/generate-index.sh') # Or if the script itself changed |
| 106 | + |
| 107 | + - name: Install Playwright browsers and system dependencies |
| 108 | + run: | |
| 109 | + npx playwright install-deps |
| 110 | + npx playwright install |
| 111 | +
|
| 112 | + - name: Run All Playwright Tests |
| 113 | + run: npx playwright test e2e/samples.spec.ts |
| 114 | + env: |
| 115 | + CI: true |
| 116 | + |
| 117 | + - name: Upload Test Report Artifact |
| 118 | + uses: actions/upload-artifact@v4 |
| 119 | + if: failure() |
| 120 | + with: |
| 121 | + name: Test Results |
| 122 | + path: test-results/ |
| 123 | + |
| 124 | + scheduled_full_test: |
| 125 | + name: Scheduled Full E2E Tests |
| 126 | + if: github.event_name == 'schedule' |
31 | 127 | runs-on: ubuntu-latest |
32 | 128 | steps: |
33 | 129 | - uses: actions/checkout@v4 |
34 | | - if: github.actor != 'dependabot[bot]' |
35 | | - - uses: actions/cache@v4 |
| 130 | + with: |
| 131 | + lfs: true |
| 132 | + |
| 133 | + - name: Setup Node.js |
| 134 | + uses: actions/setup-node@v4 |
| 135 | + with: |
| 136 | + node-version: '20' |
| 137 | + |
| 138 | + - name: Cache npm dependencies |
| 139 | + uses: actions/cache@v4 |
36 | 140 | with: |
37 | 141 | path: ~/.npm |
38 | 142 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
39 | 143 | restore-keys: | |
40 | | - ${{ runner.os }}-node |
41 | | - - uses: actions/cache@v4 # Cache Playwright browsers |
| 144 | + ${{ runner.os }}-node- |
| 145 | +
|
| 146 | + - name: Cache Playwright browsers |
| 147 | + uses: actions/cache@v4 |
42 | 148 | with: |
43 | 149 | path: ~/.cache/ms-playwright |
44 | | - key: ${{ runner.os }}-playwright-${{ hashFiles('playwright.config.ts', 'package.json') }} # Cache key based on config files |
| 150 | + key: ${{ runner.os }}-playwright-${{ hashFiles('playwright.config.ts', 'package.json') }} |
45 | 151 | restore-keys: | |
46 | 152 | ${{ runner.os }}-playwright- |
47 | | - - run: npm i |
48 | | - - run: npx playwright install |
49 | | - - run: npx playwright test |
| 153 | +
|
| 154 | + - name: Install dependencies |
| 155 | + run: npm ci |
| 156 | + |
| 157 | + - name: Build All Projects |
| 158 | + run: npm run build-all |
| 159 | + |
| 160 | + - name: Generate Index (Run Once After Full Builds) |
| 161 | + run: bash generate-index.sh |
| 162 | + |
| 163 | + - name: Install Playwright system dependencies |
| 164 | + run: npx playwright install-deps |
| 165 | + |
| 166 | + - name: Install Playwright browsers |
| 167 | + run: npx playwright install |
| 168 | + |
| 169 | + - name: Run Full E2E Tests (Scheduled) |
| 170 | + run: npx playwright test e2e/samples.spec.ts |
| 171 | + env: |
| 172 | + CI: true |
| 173 | + |
| 174 | + - name: Upload Test Report Artifact |
| 175 | + uses: actions/upload-artifact@v4 |
| 176 | + if: failure() |
| 177 | + with: |
| 178 | + name: Test Results |
| 179 | + path: test-results/ |
0 commit comments