-
Notifications
You must be signed in to change notification settings - Fork 130
196 lines (176 loc) · 8.37 KB
/
api-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
194
195
196
name: ShareIt API Tests
on:
pull_request:
workflow_call:
jobs:
check-repo:
runs-on: ubuntu-latest
steps:
- name: Check repo not fork and public
run: |
REPO=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" "/repos/${GITHUB_REPOSITORY}")
FORK=$(jq '.fork' <<< "$REPO")
PRIVATE=$(jq '.private' <<< "$REPO")
echo "FORK='$FORK', PRIVATE='$PRIVATE', GITHUB_REPOSITORY_OWNER=${GITHUB_REPOSITORY_OWNER} "
if [[ "$FORK" == "true" ]]
then
echo "Use the repository automatically created by Yandex Practicum (works in fork repositories are not accepted)"
echo "Используйте только репозиторий созданный Yandex Practicum, работы в форк репозитории не принимаются"
exit -1
fi
if [[ "$GITHUB_REPOSITORY_OWNER" == "yandex-praktikum" ]]
then
echo "Use the repository automatically created by Yandex Practicum (works in fork repositories are not accepted)"
echo "Используйте только репозиторий созданный Yandex Practicum, работы в форк репозитории не принимаются"
exit -2
fi
if [[ "$PRIVATE" == "true" && "$GITHUB_REPOSITORY_OWNER" != "praktikum-java" ]]
then
echo "Share your repository, make it public"
echo "Откройте доступ к вашему репозиторию, сделайте его публичным"
exit -3
fi
env:
GH_TOKEN: ${{ github.token }}
- name: Check branch name
run: |
if [[ "$GITHUB_BASE_REF" != "main" && "$GITHUB_REPOSITORY_OWNER" != "praktikum-java" ]]
then
echo "Set the pull request to merge branch 'main' (instead of '$GITHUB_BASE_REF')"
echo "Задайте в Pull request ветку слияния 'main' (вместо '$GITHUB_BASE_REF')"
exit -2
fi
echo "Github target '$GITHUB_BASE_REF' - OK"
if [[ "$GITHUB_HEAD_REF" == "add-controllers" ]]
then
echo "Sprint 14: add-controllers - OK"
exit
fi
if [[ "$GITHUB_HEAD_REF" == "add-bookings" ]]
then
echo "Sprint 15: add-bookings - OK"
PULL=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${GITHUB_REPOSITORY}/pulls?head=${GITHUB_REPOSITORY_OWNER}:add-controllers || true)
OPEN=$(jq '. | length' <<< "$PULL")
if [[ "$OPEN" != "0" && "$GITHUB_REPOSITORY_OWNER" != "praktikum-java" ]]
then
PULL_URL=$(jq '.[0].html_url' <<< "$PULL")
echo "Merge the add-controllers branch pull request: ${PULL_URL}"
echo "Объедините pull request ветки add-controllers: ${PULL_URL}"
exit -3
fi
echo "Sprint 14: add-controllers - Merged"
exit
fi
if [[ "$GITHUB_HEAD_REF" == "add-item-requests-and-gateway" ]]
then
echo "Sprint 16: add-item-requests-and-gateway - OK"
PULL=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${GITHUB_REPOSITORY}/pulls?head=${GITHUB_REPOSITORY_OWNER}:add-bookings || true)
OPEN=$(jq '. | length' <<< "$PULL")
if [[ "$OPEN" != "0" && "$GITHUB_REPOSITORY_OWNER" != "praktikum-java" ]]
then
PULL_URL=$(jq '.[0].html_url' <<< "$PULL")
echo "Merge the add-bookings branch pull request: ${PULL_URL}"
echo "Объедините pull request ветки add-bookings: ${PULL_URL}"
exit -4
fi
echo "Sprint 15: add-bookings - Merged"
exit
fi
echo "Correct branch name '$GITHUB_HEAD_REF' according to the spec, allowed: add-controllers, add-bookings, add-item-requests-and-gateway"
echo "Исправьте пожалуйста имя ветки '$GITHUB_HEAD_REF' согласно заданию, разрешены: add-controllers, add-bookings, add-item-requests-and-gateway"
exit -1
env:
GH_TOKEN: ${{ github.token }}
- name: Check files
run: |
PULL=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${GITHUB_REPOSITORY}/pulls/${PULL_NUMBER}/files?per_page=100 || true)
FILENAMES=$(jq '.[] | .filename' <<< "$PULL")
if [[ "$FILENAMES" =~ "api-tests.yml" ]]
then
echo "The pull request contains the api-tests.yml file and cannot be modified. Remove it from PR"
echo "Pull request содержит файл api-tests.yml, его изменять нельзя. Удалите его из PR"
exit -1
fi
if [[ "$FILENAMES" =~ "checkstyle.xml" ]]
then
echo "The pull request contains the checkstyle.xml file and cannot be modified. Remove it from PR"
echo "Pull request содержит файл checkstyle.xml, его изменять нельзя. Удалите его из PR"
exit -2
fi
if [[ "$FILENAMES" =~ ".class" ]] || [[ "$FILENAMES" =~ ".jar" ]] || [[ "$FILENAMES" =~ "mvn" ]] || [[ "$FILENAMES" =~ ".DS_Store" ]] \
|| [[ "$FILENAMES" =~ ".idea" ]] || [[ "$FILENAMES" =~ ".iws" ]] || [[ "$FILENAMES" =~ ".iml" ]] || [[ "$FILENAMES" =~ ".ipr" ]] \
|| [[ "$FILENAMES" =~ ".db" ]] || [[ "$FILENAMES" =~ ".log" ]] || [[ "$FILENAMES" =~ "target/" ]]
then
echo "The pull request contains the binary files. Remove them (*.class, *.jar, *.DS_Store ...) from PR"
echo "Pull request содержит двоичные файлы. Удалите их (*.class, *.jar, *.DS_Store ...) из PR"
exit -3
fi
echo "PR files - OK"
exit
env:
PULL_NUMBER: ${{ github.event.number }}
GH_TOKEN: ${{ github.token }}
build-shareit:
needs: check-repo
runs-on: ubuntu-latest
steps:
- name: Checkout target repo
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Checkout tests
uses: actions/checkout@v4
with:
repository: 'yandex-praktikum/java-shareit'
ref: ${{ github.event.pull_request.head.ref }}
path: tests
- name: Check and Build application
run: |
chmod a+x ./tests/.github/workflows/build.sh
./tests/.github/workflows/build.sh
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: '16.x'
- name: Install newman
run: |
npm install -g newman
npm install -g newman-reporter-htmlextra
- name: Run Application
run: |
chmod a+x ./tests/.github/workflows/run.sh
./tests/.github/workflows/run.sh
- name: Run POSTMAN tests
run: >
newman run ./tests/postman/sprint.json
--delay-request 50 -r cli,htmlextra
--verbose --color on --reporter-htmlextra-darkTheme
--reporter-htmlextra-export reports/shareIt.html
--reporter-htmlextra-title "Отчет по тестам"
--reporter-htmlextra-logs true
--reporter-htmlextra-template ./tests/.github/workflows/dashboard-template.hbs
- name: Compose logs
if: ${{ failure() }}
run: |
if test -f "docker-compose.yml"; then
docker compose -f docker-compose.yml ps
docker compose -f docker-compose.yml stop
docker compose -f docker-compose.yml logs -f gateway >> ./gateway.log || true
docker compose -f docker-compose.yml logs -f server >> ./server.log || true
fi
- name: Upload log artifact
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: shareIt_log
path: ./*.log
- name: Archive artifacts
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: postman_tests_report
path: reports