-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (116 loc) · 4.66 KB
/
test.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
name: Automatic Test
on: [push, pull_request, workflow_dispatch]
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
# We conduct tests on a combination of so many platforms,
# not only to test compatibility,
# but also to identify bugs that may not be detected without extensive repetition.
matrix:
postgresql-version: [latest, 12]
elasticsearch-version: [8.12.2, 8.0.0]
node-version: [18.x, 20.x]
pnpm-version: [8]
repeat: [1, 2]
env:
TEST_REPEAT: 10 # Tests will be repeated
PORT: 7777
JWT_SECRET: Test JWT Secret
PRISMA_DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres?connection_limit=16
DEFAULT_AVATAR_NAME: default.jpg
FILE_UPLOAD_PATH: /home/runner/work/cheese-backend
ELASTICSEARCH_NODE: http://127.0.0.1:9200/
ELASTICSEARCH_MAX_RETRIES: 10
ELASTICSEARCH_REQUEST_TIMEOUT: 60000
ELASTICSEARCH_PING_TIMEOUT: 60000
ELASTICSEARCH_SNIFF_ON_START: false
ELASTICSEARCH_AUTH_USERNAME: elastic
ELASTICSEARCH_AUTH_PASSWORD: your-elasticsearch-password
services:
# See: https://docs.github.com/en/actions/using-containerized-services/creating-postgresql-service-containers
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres:${{ matrix.postgresql-version }}
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--name my_postgres_container
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
elasticsearch: # See: https://discuss.elastic.co/t/set-password-and-user-with-docker-compose/225075
image: docker.elastic.co/elasticsearch/elasticsearch:${{ matrix.elasticsearch-version }}
env:
discovery.type: single-node
xpack.security.enabled: true
ELASTIC_USERNAME: ${{ env.ELASTICSEARCH_AUTH_USERNAME }}
ELASTIC_PASSWORD: ${{ env.ELASTICSEARCH_AUTH_PASSWORD }}
options: >-
--health-cmd "curl http://localhost:9200/_cluster/health"
--health-interval 10s
--health-timeout 5s
--health-retries 10
ports:
# Maps tcp port 9200 on service container to the host
- 9200:9200
steps:
# See: https://remarkablemark.org/blog/2022/05/12/github-actions-postgresql-increase-max-connections-and-shared-buffers/
# See: https://stackoverflow.com/questions/70673766/how-to-increase-max-connection-in-github-action-postgres
- name: Increase PostgreSQL max_connections
run: |
docker exec -i my_postgres_container bash << EOF
sed -i -e 's/max_connections = 100/max_connections = 1000/' /var/lib/postgresql/data/postgresql.conf
sed -i -e 's/shared_buffers = 128MB/shared_buffers = 2GB/' /var/lib/postgresql/data/postgresql.conf
EOF
docker restart --time 0 my_postgres_container
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ matrix.pnpm-version }}
run_install: false
- name: Install Dependencies
run: pnpm install
- name: Initialize Database Structures with Prisma
run: pnpm prisma db push
- name: Install ffmpeg
# uses: FedericoCarboni/setup-ffmpeg@v3
run: |
sudo apt-get update
sudo apt-get install ffmpeg
- name: Try to Start Application
run: |
pnpm start | tee output &
while true; do
sleep 1
if grep -q "Nest application successfully started" output; then
echo "Detected 'Nest application successfully started'. Stopping pnpm..."
pid=$(netstat -nlp | grep :$PORT | awk '{print $7}' | awk -F'/' '{print $1}')
kill $pid
break
fi
if grep -q "Command failed" output; then
echo "Nest application failed to start."
exit -1
fi
done
- name: Run Tests
run: |
for i in {1..${{ env.TEST_REPEAT }}}; do
echo "Repeating Test [$i]"
pnpm test --verbose
done