Skip to content

Commit 675b34e

Browse files
committed
Prepare and check test env during CI
1 parent 96ec656 commit 675b34e

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

.drone.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,16 @@ steps:
207207
commands:
208208
- git update-ref refs/heads/tag_test ${DRONE_COMMIT_SHA}
209209

210-
- name: fix-permissions
210+
- name: prepare-test-env
211211
image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env
212212
commands:
213-
- chown -R gitea:gitea .
213+
- ./build/test-env-prepare.sh
214214

215215
- name: unit-test
216216
image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env
217217
user: gitea
218218
commands:
219+
- ./build/test-env-check.sh
219220
- make unit-test-coverage test-check
220221
environment:
221222
GOPROXY: off
@@ -353,16 +354,17 @@ steps:
353354
exclude:
354355
- pull_request
355356

356-
- name: fix-permissions
357+
- name: prepare-test-env
357358
image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env
358359
commands:
359-
- chown -R gitea:gitea .
360+
- ./build/test-env-prepare.sh
360361

361362
- name: build
362363
pull: always
363364
image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env
364365
user: gitea
365366
commands:
367+
- ./build/test-env-check.sh
366368
- make backend
367369
environment:
368370
GOPROXY: https://goproxy.cn # proxy.golang.org is blocked in China, this proxy is not

build/test-env-check.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
if [ ! -f ./build/test-env-check.sh ]; then
6+
echo "${0} can only be executed in gitea source root directory"
7+
exit 1
8+
fi
9+
10+
11+
echo "check uid ..."
12+
13+
# the uid of gitea defined in "https://gitea.com/gitea/test-env" is 1000
14+
gitea_uid=$(id -u gitea)
15+
if [ "$gitea_uid" != "1000" ]; then
16+
echo "The uid of linux user 'gitea' is expected to be 1000, but it is $gitea_uid"
17+
exit 1
18+
fi
19+
20+
cur_uid=$(id -u)
21+
if [ "$cur_uid" != "0" -a "$cur_uid" != "$gitea_uid" ]; then
22+
echo "The uid of current linux user is expected to be 0 or $gitea_uid, but it is $cur_uid"
23+
exit 1
24+
fi

build/test-env-prepare.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
if [ ! -f ./build/test-env-prepare.sh ]; then
6+
echo "${0} can only be executed in gitea source root directory"
7+
exit 1
8+
fi
9+
10+
echo "change the owner of files to gitea ..."
11+
chown -R gitea:gitea .

0 commit comments

Comments
 (0)