-
Notifications
You must be signed in to change notification settings - Fork 4
189 lines (168 loc) · 6.33 KB
/
pull-request-check.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Pull Request Checks
on:
pull_request:
types:
- opened
- synchronize
- reopened
jobs:
black-format-check: # Check that the backend codebase is formatted with black
name: Black format check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies and check black format
run: |
cd backend
python -m pip install --upgrade pip
pip install black
black --check --diff .
flake8-check: # Check that the backend codebase does not contain linting errors
name: Flake8 check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies and check flake8 format
run: |
cd backend
python -m pip install --upgrade pip
pip install flake8
flake8 .
prettier-check: # Check that the frontend codebase is formatted with prettier
name: Prettier format check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 18
- name: Install dependencies and check prettier format
run: |
cd frontend
npm install prettier
npm run prettier:check
cspell-check: # Check that the project does not contain spelling errors
name: CSpell check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 18
- name: Install dependencies and check prettier format
run: npm install -g cspell && cspell --no-summary --no-progress --no-color .
version-upgrade-check: # Check that the version is greater than the previous commit version
name: Version upgrade check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check that the version in backend and frontend are the same
id: version-check
run: |
cd frontend
FRONTEND_VERSION=$(cat package.json | grep -m1 version | cut -d '"' -f 4)
cd ../backend
BACKEND_VERSION=$(cat swagger.yaml | grep -m1 version | cut -d ':' -f 2 | sed 's/ //g')
if [ "$FRONTEND_VERSION" != "$BACKEND_VERSION" ]; then
echo "Version mismatch: frontend/package.json version '$FRONTEND_VERSION' != backend/swagger.yaml version '$BACKEND_VERSION'."
exit 1
fi
echo "Version match: frontend/package.json version '$FRONTEND_VERSION' == backend/swagger.yaml version '$BACKEND_VERSION'."
echo "BRANCH_VERSION=$FRONTEND_VERSION" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3
with:
ref: main
- name: Check that the version is greater than the previous commit version
run: |
BRANCH_VERSION=${{ steps.version-check.outputs.BRANCH_VERSION }}
cd frontend
PREVIOUS_VERSION=$(cat package.json | grep -m1 version | cut -d '"' -f 4)
echo "PREVIOUS_VERSION=$PREVIOUS_VERSION"
echo "BRANCH_VERSION=$BRANCH_VERSION"
# If pervious version is beta, ignore test
if [[ $PREVIOUS_VERSION == *"beta"* ]]; then
echo "Beta version detected, skipping version upgrade check."
exit 0
fi
if [ "$BRANCH_VERSION" == "" ]; then
echo "No version found in current branch."
exit 1
fi
if [ "$PREVIOUS_VERSION" == "" ]; then
echo "No version found in main branch."
exit 1
fi
if [[ $PREVIOUS_VERSION == $BRANCH_VERSION ]]; then
echo "Version not upgraded: frontend/package.json version '$PREVIOUS_VERSION' == branch version '$BRANCH_VERSION'."
exit 1
fi
if [[ $PREVIOUS_VERSION > $BRANCH_VERSION ]]; then
echo "Version not upgraded: frontend/package.json version '$PREVIOUS_VERSION' > branch version '$BRANCH_VERSION'."
exit 1
fi
echo "Version upgraded: frontend/package.json version '$PREVIOUS_VERSION' < branch version '$BRANCH_VERSION'."
python-tests: # Install dependencies and run tests with pytest
name: Python tests
needs:
[black-format-check, prettier-check, cspell-check, version-upgrade-check]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
cd backend
python -m pip install --upgrade pip
pip install pytest
pip install -r requirements.txt
- name: Test with pytest
run: |
cd backend
python websrv.py & sleep 5 && pytest tests/
docker-build-check: # Build the docker image and check that it can run
name: Docker build check
needs:
[black-format-check, prettier-check, cspell-check, version-upgrade-check]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build the Docker image
run: docker build -t debiai .
- name: Run the Docker image
run: docker run -d -p 3000:3000 debiai
- name: Wait for the Docker container to start
run: |
echo "Waiting for container status..."
for i in {1..10}; do
sleep 3
container_id=$(docker ps -q -f "ancestor=debiai")
status=$(docker inspect --format='{{.State.Status}}' $container_id | tr -d '[:space:]')
echo "Docker status: '$status'";
if [ "$status" = "running" ]; then
echo "Container is running"
exit 0
elif [ "$status" = "exited" ]; then
echo "Container exited"
exit 1
fi
done
echo "Container did not start in time"
exit 1