Skip to content

Commit

Permalink
CICD
Browse files Browse the repository at this point in the history
  • Loading branch information
namnguyen20999 committed Oct 1, 2024
1 parent 1de24a9 commit 977e0dc
Showing 1 changed file with 25 additions and 92 deletions.
117 changes: 25 additions & 92 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -1,105 +1,38 @@
name: Test execution on Github server
name: Playwright CI

on:
pull_request:
branches: [ main, master ]
push:
branches: [ main, master ]

workflow_dispatch:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
permissions:
contents: write
pull-requests: write
timeout-minutes: 60
runs-on: ubuntu-latest
continue-on-error: true

steps:
- name: checkout repo
uses: actions/checkout@v4

- name: setup node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Checkout code
uses: actions/checkout@v2

- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: |
node_modules
key: modules-${{ hashFiles('package-lock.json') }}

- name: Cache Playwright Binaries
id: cache-playwright
uses: actions/cache@v4
with:
path: |
~/.cache/ms-playwright
key: playwright-${{ hashFiles('package-lock.json') }}
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16' # Specify the Node.js version

- name: Install dependencies
id: install-dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci
- name: Install dependencies
run: npm install

- name: Install Playwright Browsers
id: install-playwright-browsers
if: steps.cache-playwright.outputs.cache-hit != 'true'
run: npx playwright install --with-deps
- name: Install Playwright Browsers
run: npx playwright install

- name: Run Playwright tests
continue-on-error: true
run: |
npx playwright test
- name: Get the failure count
id: tests
run: |
export count=$(cat ./playwright-report/result.txt | grep Failed | cut -d ':' -f 2 | tr -d ' ')
echo "fail_count=$count" >> "$GITHUB_OUTPUT"
echo $count
- uses: mshick/add-pr-comment@v2
if: always()
with:
message-path: |
./playwright-report/result.txt
message-failure: |
Workflow failed
- name: Run Playwright tests
run: npx playwright test

- name: Setup Pages
if: steps.tests.outputs.fail_count != '0'
uses: actions/configure-pages@v3

- name: Upload Artifact
if: steps.tests.outputs.fail_count != '0'
uses: actions/upload-pages-artifact@v1
with:
path: "./playwright-report"

- name: Fail the job if there any failed case
if: steps.tests.outputs.fail_count != '0'
run : |
exit 1
outputs:
fail_count: ${{ steps.tests.outputs.fail_count }}

deploy:
if: needs.test.outputs.fail_count != '0'
needs: test
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Upload test results
if: always() # Upload results even if tests fail
uses: actions/upload-artifact@v2
with:
name: playwright-results
path: test-results/ # Adjust the path as needed

0 comments on commit 977e0dc

Please sign in to comment.