|
1 | | -name: UI validation on prod |
| 1 | +name: Running Playwright test on UI |
2 | 2 | on: |
3 | | - workflow_dispatch: |
4 | | - |
| 3 | + push: |
| 4 | + branches: [main] |
| 5 | + paths: |
| 6 | + - 'static/nginxaas-azure/js/cost-calculator_v2.js' |
| 7 | + - 'content/nginxaas-azure/billing/usage-and-cost-estimator.md' |
| 8 | + pull_request: |
| 9 | + paths: |
| 10 | + - 'static/nginxaas-azure/js/cost-calculator_v2.js' |
| 11 | + - 'content/nginxaas-azure/billing/usage-and-cost-estimator.md' |
| 12 | +permissions: |
| 13 | + contents: read |
5 | 14 | jobs: |
| 15 | + get-playwright-version: |
| 16 | + name: Get Playwright Version |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + version: ${{ steps.get-playwright-version.outputs.version }} |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 |
| 23 | + - name: Get version from package.json |
| 24 | + id: get-playwright-version |
| 25 | + run: | |
| 26 | + version=$(jq -r '.devDependencies["@playwright/test"] // .dependencies["@playwright/test"]' package.json) |
| 27 | + test -n "$version" || { echo "No @playwright/test version found in package.json"; exit 1; } |
| 28 | + echo "version=$version" >> $GITHUB_OUTPUT |
| 29 | + echo "Version: " $version |
6 | 30 | run-playwright-tests: |
| 31 | + name: Run Playwright |
| 32 | + needs: get-playwright-version |
7 | 33 | runs-on: ubuntu-latest |
| 34 | + container: |
| 35 | + image: mcr.microsoft.com/playwright:v${{needs.get-playwright-version.outputs.version}}-jammy |
8 | 36 | steps: |
9 | | - - uses: actions/checkout@v4 |
10 | | - - uses: actions/setup-node@v6 |
| 37 | + - name: Checkout code |
| 38 | + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 |
| 39 | + - name: Setup Hugo |
| 40 | + uses: peaceiris/actions-hugo@75d2e84710de30f6ff7268e08f310b60ef14033f # v3.0.0 |
11 | 41 | with: |
12 | | - node-version: lts/* |
| 42 | + hugo-version: '0.147.8' |
| 43 | + extended: true |
| 44 | + - uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 #v6.0.0 |
| 45 | + with: |
| 46 | + go-version: '1.24.6' |
13 | 47 | - name: Install dependencies |
14 | 48 | run: npm ci |
15 | | - - name: Install Playwright Browsers |
16 | | - run: npx playwright install --with-deps |
17 | 49 | - name: Run Playwright tests |
18 | | - run: npx playwright test --retries=2 |
19 | | - - uses: actions/upload-artifact@v6 |
20 | | - if: ${{ !cancelled() }} |
| 50 | + id: test-ui |
| 51 | + # Check done to set the home variable. Workaround as browser is unable to launch if the $HOME folder isn't owned by the current user. |
| 52 | + if: ${{ runner.os == 'Linux' }} |
| 53 | + env: |
| 54 | + HOME: /root |
| 55 | + run: | |
| 56 | + git config --global --add safe.directory /__w/nginx-hugo-theme/nginx-hugo-theme |
| 57 | + cd tests && npx playwright test | tee output.log |
| 58 | + if grep -q "failed" output.log; then |
| 59 | + echo "Playwright tests failed. Please view the Playwright report to see full error." |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + - uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0 |
| 63 | + id: artifact-upload |
| 64 | + if: ${{ !cancelled() && failure() && steps.test-ui.conclusion == 'failure' }} |
21 | 65 | with: |
22 | 66 | name: playwright-report |
23 | 67 | path: tests/playwright-report/ |
24 | | - retention-days: 30 |
25 | | - - uses: actions/upload-artifact@v6 |
26 | | - if: ${{ !cancelled() }} |
27 | | - with: |
28 | | - name: test-results |
29 | | - path: tests/test-results/ |
30 | | - retention-days: 30 |
| 68 | + retention-days: 3 |
0 commit comments