-
Notifications
You must be signed in to change notification settings - Fork 3
193 lines (176 loc) · 6.39 KB
/
ci-postman-tests.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
190
191
192
193
name: Build and Postman Tests
on:
workflow_dispatch:
inputs:
Server:
description: 'Local build or public server:'
required: false
default: 'Node'
type: choice
options:
- 'Node'
- 'Dockerfile'
- 'DockerHub'
- 'https://torapi.vercel.app'
- 'https://toruapi.vercel.app'
- 'https://rutorapi.vercel.app'
Iterations:
description: 'Iteration count for tests:'
required: false
default: 1
type: number
Query:
description: 'Search parameter for all API request:'
required: true
default: 'The Rookie'
type: string
QueryAllPage:
description: 'Parameter for search on all pages:'
required: true
default: 'test'
type: string
CategoryRuTracker:
description: 'Parameter to filter by category for RuTracker (1605 - Switch):'
required: true
default: 1605
type: number
CategoryKinozal:
description: 'Parameter to filter by category for Kinozal (20 - Anime):'
required: true
default: 20
type: number
CategoryRuTor:
description: 'Parameter to filter by category for RuTor (10 - Anime):'
required: true
default: 10
type: number
CategoryNoNameClub:
description: 'Parameter to filter by category for NoNameClub (1318 - Switch):'
required: true
default: 1318
type: number
DeployDocker:
description: 'Deploy to Docker Hub'
required: false
default: false
type: boolean
DeployVercel:
description: 'Deploy to Vercel'
required: false
default: false
type: boolean
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Cache npm dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install newman
run: |
npm install -g newman
npm install -g newman-reporter-html
- name: Packet check
run: |
echo "node version: $(node --version)"
echo "npm version: $(npm --version)"
echo "newman version: $(newman --version)"
- name: Install dependencies and start local server
if: ${{ github.event.inputs.Server == 'Node' }}
run: |
npm install
npm start > torapi.log &
- name: Build docker image and run container
if: ${{ github.event.inputs.Server == 'Dockerfile' || github.event.inputs.Server == 'DockerHub' }}
run: |
if [ "${{ github.event.inputs.Server }}" == "Dockerfile" ]; then
echo "- Build docker image from GitHub"
docker build -t lifailon/torapi:latest .
docker run -d --name TorAPI -p 8443:8443 lifailon/torapi:latest
elif [ "${{ github.event.inputs.Server }}" == "DockerHub" ]; then
echo "- Build docker image from Docker Hub"
docker run -d --name TorAPI -p 8443:8443 --restart=unless-stopped lifailon/torapi:latest
fi
for i in {1..30}; do
response_code=$(curl -o /dev/null -s -w '%{http_code}' http://localhost:8443/api/provider/list 2> /dev/null || echo "404")
if [ "$response_code" -eq 200 ]; then
echo "Server is up: status code 200"
break
else
echo "Waiting for the server to start: $(($i*2)) seconds..."
sleep 2
fi
done
if [ "$response_code" -ne 200 ]; then
exit 1
fi
- name: Run postman tests
run: |
if [[ ${{ github.event.inputs.Server }} =~ ^https ]]; then
server=${{ github.event.inputs.Server }}
else
server="http://localhost:8443"
fi
newman run postman-tests.json \
--iteration-count ${{ github.event.inputs.Iterations }} \
--env-var "baseUrl=$server" \
--env-var "query=${{ github.event.inputs.Query }}" \
--env-var "queryAllPage=${{ github.event.inputs.queryAllPage }}" \
--env-var "categoryRuTracker=${{ github.event.inputs.CategoryRuTracker }}" \
--env-var "categoryKinozal=${{ github.event.inputs.CategoryKinozal }}" \
--env-var "categoryRuTor=${{ github.event.inputs.CategoryRuTor }}" \
--env-var "categoryNoNameClub=${{ github.event.inputs.CategoryNoNameClub }}" \
--reporters cli,junit,html \
--reporter-html-export postman-report.html \
--reporter-junit-export postman-results.xml
- name: View local server logs
if: ${{ github.event.inputs.Server == 'Node' || github.event.inputs.Server == 'Dockerfile' || github.event.inputs.Server == 'DockerHub' && (success() || failure()) }}
run: |
if [ "${{ github.event.inputs.Server }}" == "Node" ]; then
cat torapi.log
else
docker logs TorAPI
fi
- name: Upload Newman HTML Report
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: Postman HTML Report
path: postman-report.html
- name: Publish JUnit Test Results
uses: mikepenz/action-junit-report@v4
if: success() || failure()
with:
report_paths: '**/postman-results.xml'
- name: Login to Docker Hub
if: ${{ github.event.inputs.DeployDocker == 'true' && success() }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Deploy to Docker Hub
if: ${{ github.event.inputs.DeployDocker == 'true' && success() }}
run: |
docker build -t lifailon/torapi:latest .
docker push lifailon/torapi:latest
- name: Install dependencies for deploy to Vercel
if: ${{ github.event.inputs.DeployVercel == 'true' && success() }}
run: npm install
- name: Deploy to Vercel
if: ${{ github.event.inputs.DeployVercel == 'true' && success() }}
uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
vercel-args: '--prod'