forked from activist-org/activist
-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (123 loc) · 4.65 KB
/
pr_ci_playwright_e2e.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: pr_ci_playwright_e2e
on:
workflow_dispatch:
jobs:
frontend:
name: Run PR Frontend Check
runs-on: ubuntu-latest
environment: dev
steps:
- name: Cleanup old checkout
run: chmod +w -R ${GITHUB_WORKSPACE}; rm -rf ${GITHUB_WORKSPACE}/*
- name: Checkout
uses: actions/checkout@v4
- name: Check if .env.dev file exists
run: |
if [ ! -f .env.dev ]; then
echo ".env.dev file does not exist. Exiting workflow."
exit 1
fi
- name: Clean up any existing containers
run: |
docker stop $(docker ps -aq) || true
docker rm $(docker ps -aq) || true
- name: Check Port Availability
run: |
! nc -z localhost 3000 && \
! nc -z localhost 8000 && \
! nc -z localhost 5432
- name: Run Docker Compose
run: docker compose --env-file .env.dev up --build -d
- name: Check Docker Container Logs
run: docker compose --env-file .env.dev logs
- name: Setup Node environment
uses: actions/setup-node@v4
with:
node-version: 20
- name: Clean Yarn cache
working-directory: ./frontend
run: sudo yarn cache clean
- name: Install dependencies via Yarn
working-directory: ./frontend
run: sudo yarn install
- name: Verify wait-on installation
working-directory: ./frontend
run: |
yarn --version
yarn list wait-on
- name: Cache Playwright browsers
uses: actions/cache@v3
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: playwright-browsers-${{ runner.os }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}
restore-keys: |
playwright-browsers-${{ runner.os }}-
- name: Install Playwright Browsers
if: steps.playwright-cache.outputs.cache-hit != 'true'
working-directory: ./frontend
run: sudo yarn playwright install --with-deps
- name: Ensure gh-pages branch exists
if: always()
run: |
git fetch origin gh-pages
if git rev-parse --verify origin/gh-pages; then
git checkout gh-pages
git reset --hard origin/gh-pages
else
git checkout --orphan gh-pages
git rm -rf .
echo "# GitHub Pages" > index.html
git add index.html
git -c user.name='github-actions[bot]' -c user.email='github-actions[bot]@users.noreply.github.com' commit -m "Initial commit"
git push origin gh-pages
- name: Wait for web server to be ready with retry
run: |
MAX_ATTEMPTS=3
WAIT_TIME=1200
ATTEMPT=1
while [[ $ATTEMPT -le $MAX_ATTEMPTS ]]
do
echo "Attempt $ATTEMPT of $MAX_ATTEMPTS"
echo "Waiting for server for $WAIT_TIME seconds"
if yarn wait-on http://localhost:3000 --timeout ${WAIT_TIME}000 --verbose; then
echo "Server is ready!"
break
else
echo "Server not ready, restarting Docker Compose..."
docker compose --env-file .env.dev down
docker compose --env-file .env.dev up --build -d
ATTEMPT=$((ATTEMPT + 1))
if [[ $ATTEMPT -gt $MAX_ATTEMPTS ]]; then
echo "Server failed to start after $MAX_ATTEMPTS attempts."
exit 1
fi
sleep 10
fi
done
- name: Run Playwright tests
working-directory: ./frontend
run: sudo yarn playwright test --reporter=html
- name: Upload Playwright report
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: frontend/playwright-report/
retention-days: 30
- name: Deploy Playwright Report to GitHub Pages
if: always()
run: |
# Configuring git
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# Cloning the repository to the gh-pages branch
git clone --branch=gh-pages https://github.com/${{ github.repository }} gh-pages
cd gh-pages
# Copying the Playwright report to the gh-pages branch
rm -rf ./*
cp -r ../frontend/playwright-report/* .
# Committing and pushing the changes
git add .
git -c user.name='github-actions[bot]' -c user.email='github-actions[bot]@users.noreply.github.com' commit -m "Update Playwright report"
git push origin gh-pages