-
Notifications
You must be signed in to change notification settings - Fork 701
162 lines (137 loc) · 5.35 KB
/
test-pr-e2e.yml
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Tests (E2E)
on:
workflow_dispatch:
pull_request:
paths:
- 'keep/**'
- 'keep-ui/**'
- 'tests/**'
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true
env:
PYTHON_VERSION: 3.11
STORAGE_MANAGER_DIRECTORY: /tmp/storage-manager
# MySQL server environment variables
MYSQL_ROOT_PASSWORD: keep
MYSQL_DATABASE: keep
# Postgres environment variables
POSTGRES_USER: keepuser
POSTGRES_PASSWORD: keeppassword
POSTGRES_DB: keepdb
# To test if imports are working properly
EE_ENABLED: true
jobs:
tests-e2e:
runs-on: ubuntu-latest
strategy:
matrix:
db_type: [mysql, postgres]
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
with:
src: "./keep"
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache dependencies
id: cache-deps
uses: actions/cache@v2
with:
path: .venv
key: pydeps-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies using poetry
run: poetry install --no-interaction --no-root --with dev
- name: Install Playwright dependencies
run: npx playwright install --with-deps
- name: Install playwright
run: poetry run playwright install
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up Keep environment
run: |
DOCKER_BUILDKIT=1 docker compose \
--project-directory . \
-f tests/e2e_tests/docker-compose-e2e-${{ matrix.db_type }}.yml up -d
- name: Wait for database to be ready
run: |
# Add commands to wait for the database to be ready
if [ "${{ matrix.db_type }}" == "mysql" ]; then
until docker exec $(docker ps -qf "name=keep-database") mysqladmin ping -h "localhost" --silent; do
echo "Waiting for MySQL to be ready..."
sleep 2
done
elif [ "${{ matrix.db_type }}" == "postgres" ]; then
until docker exec $(docker ps -qf "name=keep-database") pg_isready -h localhost -U keepuser; do
echo "Waiting for Postgres to be ready..."
sleep 2
done
fi
# wait to keep backend on port 8080
echo "Waiting for Keep backend to be ready..."
attempt=0
max_attempts=10
until $(curl --output /dev/null --silent --fail http://localhost:8080/healthcheck); do
if [ "$attempt" -ge "$max_attempts" ]; then
echo "Max attempts reached, exiting... Sometimes Keep can't start because of double-headed migrations, use: 'alembic -c keep/alembic.ini history' to investigate, or check artifacts."
exit 1
fi
echo "Waiting for Keep backend to be ready... (Attempt: $((attempt+1)))"
attempt=$((attempt+1))
sleep 2
done
echo "Keep backend is ready!"
# wait to the backend
echo "Waiting for Keep frontend to be ready..."
attempt=0
max_attempts=10
until $(curl --output /dev/null --silent --fail http://localhost:3000/); do
if [ "$attempt" -ge "$max_attempts" ]; then
echo "Max attempts reached, exiting..."
exit 1
fi
echo "Waiting for Keep frontend to be ready... (Attempt: $((attempt+1)))"
attempt=$((attempt+1))
sleep 2
done
# create the state directory
# mkdir -p ./state && chown -R root:root ./state && chmod -R 777 ./state
- name: Run e2e tests and report coverage
run: |
poetry run coverage run --branch -m pytest -s tests/e2e_tests/
- name: Convert coverage results to JSON (for CodeCov support)
run: poetry run coverage json --omit="keep/providers/*"
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false # don't fail if we didn't manage to upload the coverage report
files: coverage.json
verbose: true
- name: Dump backend logs
if: always()
run: |
docker compose --project-directory . -f tests/e2e_tests/docker-compose-e2e-${{ matrix.db_type }}.yml logs keep-backend > backend_logs-${{ matrix.db_type }}.txt
docker compose --project-directory . -f tests/e2e_tests/docker-compose-e2e-${{ matrix.db_type }}.yml logs keep-frontend > frontend_logs-${{ matrix.db_type }}.txt
continue-on-error: true
- name: Upload test artifacts on failure
if: always()
uses: actions/upload-artifact@v3
with:
name: test-artifacts
path: |
playwright_dump_*.html
playwright_dump_*.png
backend_logs-${{ matrix.db_type }}.txt
frontend_logs-${{ matrix.db_type }}.txt
continue-on-error: true
- name: Tear down environment
run: |
docker compose --project-directory . -f tests/e2e_tests/docker-compose-e2e-${{ matrix.db_type }}.yml down