diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2021-11-19 13:58:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-19 13:58:34 +0800 |
commit | e4b95de38856fac845c21348971e3c5343ceac15 (patch) | |
tree | 5702fc5ab5659f7fc48a66dd5e5f8e013df00c41 | |
parent | 9361b65f542671457ed09c35ddde9d09ee06d136 (diff) | |
download | gitea-e4b95de38856fac845c21348971e3c5343ceac15.tar.gz gitea-e4b95de38856fac845c21348971e3c5343ceac15.zip |
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
-rw-r--r-- | .drone.yml | 48 | ||||
-rwxr-xr-x | build/test-env-check.sh | 24 | ||||
-rwxr-xr-x | build/test-env-prepare.sh | 11 |
3 files changed, 69 insertions, 14 deletions
diff --git a/.drone.yml b/.drone.yml index a24f4c621e..6a69921c42 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,5 +1,6 @@ --- kind: pipeline +type: docker name: compliance platform: @@ -130,6 +131,7 @@ steps: --- kind: pipeline +type: docker name: testing-amd64 platform: @@ -191,26 +193,30 @@ steps: exclude: - pull_request - - name: build - pull: always - image: golang:1.17 - commands: - - make backend - environment: - GOPROXY: https://goproxy.cn # proxy.golang.org is blocked in China, this proxy is not - GOSUMDB: sum.golang.org - TAGS: bindata sqlite sqlite_unlock_notify - - name: tag-pre-condition pull: always image: drone/git commands: - git update-ref refs/heads/tag_test ${DRONE_COMMIT_SHA} - - name: fix-permissions + - name: prepare-test-env image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env commands: - - chown -R gitea:gitea . + - ./build/test-env-prepare.sh + + - name: build + pull: always + image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env + user: gitea + commands: + - ./build/test-env-check.sh + - make backend + environment: + GOPROXY: https://goproxy.cn # proxy.golang.org is blocked in China, this proxy is not + GOSUMDB: sum.golang.org + TAGS: bindata sqlite sqlite_unlock_notify + depends_on: + - prepare-test-env - name: unit-test image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env @@ -353,21 +359,24 @@ steps: exclude: - pull_request - - name: fix-permissions + - name: prepare-test-env image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env commands: - - chown -R gitea:gitea . + - ./build/test-env-prepare.sh - name: build pull: always image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env user: gitea commands: + - ./build/test-env-check.sh - make backend environment: GOPROXY: https://goproxy.cn # proxy.golang.org is blocked in China, this proxy is not GOSUMDB: sum.golang.org TAGS: bindata gogit sqlite sqlite_unlock_notify + depends_on: + - prepare-test-env - name: test-sqlite image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env @@ -461,6 +470,7 @@ steps: --- kind: pipeline +type: docker name: update_gitignore_and_licenses platform: @@ -497,6 +507,7 @@ steps: --- kind: pipeline +type: docker name: release-latest platform: @@ -675,6 +686,7 @@ steps: --- kind: pipeline +type: docker name: docs platform: @@ -716,6 +728,7 @@ steps: --- kind: pipeline +type: docker name: docker-linux-amd64-release-version platform: @@ -780,6 +793,7 @@ steps: --- kind: pipeline +type: docker name: docker-linux-amd64-release platform: @@ -844,6 +858,7 @@ steps: --- kind: pipeline +type: docker name: docker-linux-arm64-dry-run platform: @@ -876,6 +891,7 @@ steps: --- kind: pipeline +type: docker name: docker-linux-arm64-release-version platform: @@ -943,6 +959,7 @@ steps: --- kind: pipeline +type: docker name: docker-linux-arm64-release platform: @@ -1009,6 +1026,7 @@ steps: - pull_request --- kind: pipeline +type: docker name: docker-manifest-version platform: @@ -1052,6 +1070,7 @@ depends_on: --- kind: pipeline +type: docker name: docker-manifest platform: @@ -1095,6 +1114,7 @@ depends_on: --- kind: pipeline +type: docker name: notifications platform: diff --git a/build/test-env-check.sh b/build/test-env-check.sh new file mode 100755 index 0000000000..38e5a28823 --- /dev/null +++ b/build/test-env-check.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +set -e + +if [ ! -f ./build/test-env-check.sh ]; then + echo "${0} can only be executed in gitea source root directory" + exit 1 +fi + + +echo "check uid ..." + +# the uid of gitea defined in "https://gitea.com/gitea/test-env" is 1000 +gitea_uid=$(id -u gitea) +if [ "$gitea_uid" != "1000" ]; then + echo "The uid of linux user 'gitea' is expected to be 1000, but it is $gitea_uid" + exit 1 +fi + +cur_uid=$(id -u) +if [ "$cur_uid" != "0" -a "$cur_uid" != "$gitea_uid" ]; then + echo "The uid of current linux user is expected to be 0 or $gitea_uid, but it is $cur_uid" + exit 1 +fi diff --git a/build/test-env-prepare.sh b/build/test-env-prepare.sh new file mode 100755 index 0000000000..0c5bc25f11 --- /dev/null +++ b/build/test-env-prepare.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e + +if [ ! -f ./build/test-env-prepare.sh ]; then + echo "${0} can only be executed in gitea source root directory" + exit 1 +fi + +echo "change the owner of files to gitea ..." +chown -R gitea:gitea . |