Skip to content

Commit e4b95de

Browse files
authored
Prepare and check test env during CI (#17725)
This PR should resolve the permission problems during CI, if the uid doesn't match, a more clear message is shown. * CI fails with unknown permission problems #17710 The new drone step dependencies: (root)prepare-test-env -> (gitea)build -> (gitea)test
1 parent 9361b65 commit e4b95de

File tree

3 files changed

+69
-14
lines changed

3 files changed

+69
-14
lines changed

.drone.yml

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
kind: pipeline
3+
type: docker
34
name: compliance
45

56
platform:
@@ -130,6 +131,7 @@ steps:
130131

131132
---
132133
kind: pipeline
134+
type: docker
133135
name: testing-amd64
134136

135137
platform:
@@ -191,26 +193,30 @@ steps:
191193
exclude:
192194
- pull_request
193195

194-
- name: build
195-
pull: always
196-
image: golang:1.17
197-
commands:
198-
- make backend
199-
environment:
200-
GOPROXY: https://goproxy.cn # proxy.golang.org is blocked in China, this proxy is not
201-
GOSUMDB: sum.golang.org
202-
TAGS: bindata sqlite sqlite_unlock_notify
203-
204196
- name: tag-pre-condition
205197
pull: always
206198
image: drone/git
207199
commands:
208200
- git update-ref refs/heads/tag_test ${DRONE_COMMIT_SHA}
209201

210-
- name: fix-permissions
202+
- name: prepare-test-env
211203
image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env
212204
commands:
213-
- chown -R gitea:gitea .
205+
- ./build/test-env-prepare.sh
206+
207+
- name: build
208+
pull: always
209+
image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env
210+
user: gitea
211+
commands:
212+
- ./build/test-env-check.sh
213+
- make backend
214+
environment:
215+
GOPROXY: https://goproxy.cn # proxy.golang.org is blocked in China, this proxy is not
216+
GOSUMDB: sum.golang.org
217+
TAGS: bindata sqlite sqlite_unlock_notify
218+
depends_on:
219+
- prepare-test-env
214220

215221
- name: unit-test
216222
image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env
@@ -353,21 +359,24 @@ steps:
353359
exclude:
354360
- pull_request
355361

356-
- name: fix-permissions
362+
- name: prepare-test-env
357363
image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env
358364
commands:
359-
- chown -R gitea:gitea .
365+
- ./build/test-env-prepare.sh
360366

361367
- name: build
362368
pull: always
363369
image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env
364370
user: gitea
365371
commands:
372+
- ./build/test-env-check.sh
366373
- make backend
367374
environment:
368375
GOPROXY: https://goproxy.cn # proxy.golang.org is blocked in China, this proxy is not
369376
GOSUMDB: sum.golang.org
370377
TAGS: bindata gogit sqlite sqlite_unlock_notify
378+
depends_on:
379+
- prepare-test-env
371380

372381
- name: test-sqlite
373382
image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env
@@ -461,6 +470,7 @@ steps:
461470

462471
---
463472
kind: pipeline
473+
type: docker
464474
name: update_gitignore_and_licenses
465475

466476
platform:
@@ -497,6 +507,7 @@ steps:
497507

498508
---
499509
kind: pipeline
510+
type: docker
500511
name: release-latest
501512

502513
platform:
@@ -675,6 +686,7 @@ steps:
675686

676687
---
677688
kind: pipeline
689+
type: docker
678690
name: docs
679691

680692
platform:
@@ -716,6 +728,7 @@ steps:
716728

717729
---
718730
kind: pipeline
731+
type: docker
719732
name: docker-linux-amd64-release-version
720733

721734
platform:
@@ -780,6 +793,7 @@ steps:
780793

781794
---
782795
kind: pipeline
796+
type: docker
783797
name: docker-linux-amd64-release
784798

785799
platform:
@@ -844,6 +858,7 @@ steps:
844858

845859
---
846860
kind: pipeline
861+
type: docker
847862
name: docker-linux-arm64-dry-run
848863

849864
platform:
@@ -876,6 +891,7 @@ steps:
876891

877892
---
878893
kind: pipeline
894+
type: docker
879895
name: docker-linux-arm64-release-version
880896

881897
platform:
@@ -943,6 +959,7 @@ steps:
943959

944960
---
945961
kind: pipeline
962+
type: docker
946963
name: docker-linux-arm64-release
947964

948965
platform:
@@ -1009,6 +1026,7 @@ steps:
10091026
- pull_request
10101027
---
10111028
kind: pipeline
1029+
type: docker
10121030
name: docker-manifest-version
10131031

10141032
platform:
@@ -1052,6 +1070,7 @@ depends_on:
10521070

10531071
---
10541072
kind: pipeline
1073+
type: docker
10551074
name: docker-manifest
10561075

10571076
platform:
@@ -1095,6 +1114,7 @@ depends_on:
10951114

10961115
---
10971116
kind: pipeline
1117+
type: docker
10981118
name: notifications
10991119

11001120
platform:

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)