From 675b34ed0ce641cb1b2e9d2525357c37c72af1fc Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 19 Nov 2021 11:57:15 +0800 Subject: [PATCH 1/4] Prepare and check test env during CI --- .drone.yml | 10 ++++++---- build/test-env-check.sh | 24 ++++++++++++++++++++++++ build/test-env-prepare.sh | 11 +++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100755 build/test-env-check.sh create mode 100755 build/test-env-prepare.sh diff --git a/.drone.yml b/.drone.yml index a24f4c621e718..1f5a37d361519 100644 --- a/.drone.yml +++ b/.drone.yml @@ -207,15 +207,16 @@ steps: 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: unit-test image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env user: gitea commands: + - ./build/test-env-check.sh - make unit-test-coverage test-check environment: GOPROXY: off @@ -353,16 +354,17 @@ 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 diff --git a/build/test-env-check.sh b/build/test-env-check.sh new file mode 100755 index 0000000000000..38e5a28823114 --- /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 0000000000000..0c5bc25f116f1 --- /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 . From c8f467ac1941b7c0a81392c9ff5ede65ef3691fe Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 19 Nov 2021 12:35:17 +0800 Subject: [PATCH 2/4] Add more test env checks --- .drone.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.drone.yml b/.drone.yml index 1f5a37d361519..ed50cfb9e6c50 100644 --- a/.drone.yml +++ b/.drone.yml @@ -230,6 +230,7 @@ steps: image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env user: gitea commands: + - ./build/test-env-check.sh - make unit-test-coverage test-check environment: GOPROXY: off @@ -242,6 +243,7 @@ steps: image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env user: gitea commands: + - ./build/test-env-check.sh - make test-mysql-migration integration-test-coverage environment: GOPROXY: off @@ -257,6 +259,7 @@ steps: image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env user: gitea commands: + - ./build/test-env-check.sh - timeout -s ABRT 40m make test-mysql8-migration test-mysql8 environment: GOPROXY: off @@ -271,6 +274,7 @@ steps: image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env user: gitea commands: + - ./build/test-env-check.sh - make test-mssql-migration test-mssql environment: GOPROXY: off @@ -375,6 +379,7 @@ steps: image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env user: gitea commands: + - ./build/test-env-check.sh - timeout -s ABRT 40m make test-sqlite-migration test-sqlite environment: GOPROXY: off @@ -389,6 +394,7 @@ steps: image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env user: gitea commands: + - ./build/test-env-check.sh - timeout -s ABRT 40m make test-pgsql-migration test-pgsql environment: GOPROXY: off From 53d6e3bfc42433b07c3ca90b403bbcbad5c109e3 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 19 Nov 2021 12:45:48 +0800 Subject: [PATCH 3/4] Clean up --- .drone.yml | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/.drone.yml b/.drone.yml index ed50cfb9e6c50..18abf6a7ada7f 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,16 +193,6 @@ 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 @@ -212,11 +204,24 @@ steps: commands: - ./build/test-env-prepare.sh + - name: build + pull: always + image: golang:1.17 + 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 user: gitea commands: - - ./build/test-env-check.sh - make unit-test-coverage test-check environment: GOPROXY: off @@ -230,7 +235,6 @@ steps: image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env user: gitea commands: - - ./build/test-env-check.sh - make unit-test-coverage test-check environment: GOPROXY: off @@ -243,7 +247,6 @@ steps: image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env user: gitea commands: - - ./build/test-env-check.sh - make test-mysql-migration integration-test-coverage environment: GOPROXY: off @@ -259,7 +262,6 @@ steps: image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env user: gitea commands: - - ./build/test-env-check.sh - timeout -s ABRT 40m make test-mysql8-migration test-mysql8 environment: GOPROXY: off @@ -274,7 +276,6 @@ steps: image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env user: gitea commands: - - ./build/test-env-check.sh - make test-mssql-migration test-mssql environment: GOPROXY: off @@ -374,12 +375,13 @@ steps: 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 user: gitea commands: - - ./build/test-env-check.sh - timeout -s ABRT 40m make test-sqlite-migration test-sqlite environment: GOPROXY: off @@ -394,7 +396,6 @@ steps: image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env user: gitea commands: - - ./build/test-env-check.sh - timeout -s ABRT 40m make test-pgsql-migration test-pgsql environment: GOPROXY: off @@ -469,6 +470,7 @@ steps: --- kind: pipeline +type: docker name: update_gitignore_and_licenses platform: @@ -505,6 +507,7 @@ steps: --- kind: pipeline +type: docker name: release-latest platform: @@ -683,6 +686,7 @@ steps: --- kind: pipeline +type: docker name: docs platform: @@ -724,6 +728,7 @@ steps: --- kind: pipeline +type: docker name: docker-linux-amd64-release-version platform: @@ -788,6 +793,7 @@ steps: --- kind: pipeline +type: docker name: docker-linux-amd64-release platform: @@ -852,6 +858,7 @@ steps: --- kind: pipeline +type: docker name: docker-linux-arm64-dry-run platform: @@ -884,6 +891,7 @@ steps: --- kind: pipeline +type: docker name: docker-linux-arm64-release-version platform: @@ -951,6 +959,7 @@ steps: --- kind: pipeline +type: docker name: docker-linux-arm64-release platform: @@ -1017,6 +1026,7 @@ steps: - pull_request --- kind: pipeline +type: docker name: docker-manifest-version platform: @@ -1060,6 +1070,7 @@ depends_on: --- kind: pipeline +type: docker name: docker-manifest platform: @@ -1103,6 +1114,7 @@ depends_on: --- kind: pipeline +type: docker name: notifications platform: From 10c678d2b8374b154199901e82bd099a4741976f Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 19 Nov 2021 12:57:56 +0800 Subject: [PATCH 4/4] Fix build --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 18abf6a7ada7f..6a69921c4220e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -206,7 +206,7 @@ steps: - name: build pull: always - image: golang:1.17 + image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env user: gitea commands: - ./build/test-env-check.sh