From 23163e98a307300a6ba43e3d8c3b0d031398fef4 Mon Sep 17 00:00:00 2001 From: guillep2k <18600385+guillep2k@users.noreply.github.com> Date: Sun, 19 Apr 2020 08:17:02 -0300 Subject: [PATCH] Use /tmp for test repositories (#11126) * Add option to use /tmp for test repositories * Fix exit status * Add feedback about using tmp repos Co-authored-by: Guillermo Prandi Co-authored-by: Lunny Xiao --- .drone.yml | 5 +++ .gitignore | 1 + Makefile | 36 +++++++++++++++++--- integrations/mssql.ini.tmpl | 2 +- integrations/mysql.ini.tmpl | 2 +- integrations/mysql8.ini.tmpl | 2 +- integrations/pgsql.ini.tmpl | 2 +- integrations/{sqlite.ini => sqlite.ini.tmpl} | 2 +- 8 files changed, 43 insertions(+), 9 deletions(-) rename integrations/{sqlite.ini => sqlite.ini.tmpl} (96%) diff --git a/.drone.yml b/.drone.yml index 43ff21cac8..3fe8dd9980 100644 --- a/.drone.yml +++ b/.drone.yml @@ -176,6 +176,7 @@ steps: GOPROXY: off TAGS: bindata TEST_LDAP: 1 + USE_REPO_TEST_DIR: 1 depends_on: - build @@ -190,6 +191,7 @@ steps: GOPROXY: off TAGS: bindata TEST_LDAP: 1 + USE_REPO_TEST_DIR: 1 depends_on: - build @@ -204,6 +206,7 @@ steps: GOPROXY: off TAGS: bindata TEST_LDAP: 1 + USE_REPO_TEST_DIR: 1 depends_on: - build @@ -302,6 +305,7 @@ steps: environment: GOPROXY: off TAGS: bindata + USE_REPO_TEST_DIR: 1 depends_on: - build @@ -316,6 +320,7 @@ steps: GOPROXY: off TAGS: bindata TEST_LDAP: 1 + USE_REPO_TEST_DIR: 1 depends_on: - build diff --git a/.gitignore b/.gitignore index 2f6b021c38..e13b2c0fe6 100644 --- a/.gitignore +++ b/.gitignore @@ -68,6 +68,7 @@ coverage.all /integrations/indexers-pgsql /integrations/indexers-sqlite /integrations/indexers-mssql +/integrations/sqlite.ini /integrations/mysql.ini /integrations/mysql8.ini /integrations/pgsql.ini diff --git a/Makefile b/Makefile index f6d24be085..2a08c76339 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,20 @@ + +ifeq ($(USE_REPO_TEST_DIR),1) + +# This rule replaces the whole Makefile when we're trying to use /tmp repository temporary files +location = $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) +self := $(location) + +%: + @tmpdir=`mktemp --tmpdir -d` ; \ + echo Using temporary directory $$tmpdir for test repositories ; \ + USE_REPO_TEST_DIR= $(MAKE) -f $(self) --no-print-directory REPO_TEST_DIR=$$tmpdir/ $@ ; \ + STATUS=$$? ; rm -r "$$tmpdir" ; exit $$STATUS + +else + +# This is the "normal" part of the Makefile + DIST := dist DIST_DIRS := $(DIST)/binaries $(DIST)/release IMPORT := code.gitea.io/gitea @@ -321,16 +338,20 @@ test-vendor: vendor exit 1; \ fi; +generate-ini-sqlite: + sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \ + integrations/sqlite.ini.tmpl > integrations/sqlite.ini + .PHONY: test-sqlite -test-sqlite: integrations.sqlite.test +test-sqlite: integrations.sqlite.test generate-ini-sqlite GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test .PHONY: test-sqlite\#% -test-sqlite\#%: integrations.sqlite.test +test-sqlite\#%: integrations.sqlite.test generate-ini-sqlite GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.run $(subst .,/,$*) .PHONY: test-sqlite-migration -test-sqlite-migration: migrations.sqlite.test +test-sqlite-migration: migrations.sqlite.test generate-ini-sqlite GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./migrations.sqlite.test generate-ini-mysql: @@ -338,6 +359,7 @@ generate-ini-mysql: -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \ -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \ -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \ + -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \ integrations/mysql.ini.tmpl > integrations/mysql.ini .PHONY: test-mysql @@ -357,6 +379,7 @@ generate-ini-mysql8: -e 's|{{TEST_MYSQL8_DBNAME}}|${TEST_MYSQL8_DBNAME}|g' \ -e 's|{{TEST_MYSQL8_USERNAME}}|${TEST_MYSQL8_USERNAME}|g' \ -e 's|{{TEST_MYSQL8_PASSWORD}}|${TEST_MYSQL8_PASSWORD}|g' \ + -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \ integrations/mysql8.ini.tmpl > integrations/mysql8.ini .PHONY: test-mysql8 @@ -377,6 +400,7 @@ generate-ini-pgsql: -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \ -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \ -e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \ + -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \ integrations/pgsql.ini.tmpl > integrations/pgsql.ini .PHONY: test-pgsql @@ -396,6 +420,7 @@ generate-ini-mssql: -e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \ -e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \ -e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \ + -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \ integrations/mssql.ini.tmpl > integrations/mssql.ini .PHONY: test-mssql @@ -411,7 +436,7 @@ test-mssql-migration: migrations.mssql.test generate-ini-mssql GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./migrations.mssql.test .PHONY: bench-sqlite -bench-sqlite: integrations.sqlite.test +bench-sqlite: integrations.sqlite.test generate-ini-sqlite GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench . .PHONY: bench-mysql @@ -627,3 +652,6 @@ golangci-lint: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.24.0; \ fi golangci-lint run --timeout 5m + +# This endif closes the if at the top of the file +endif \ No newline at end of file diff --git a/integrations/mssql.ini.tmpl b/integrations/mssql.ini.tmpl index 931e923cf4..063c41972b 100644 --- a/integrations/mssql.ini.tmpl +++ b/integrations/mssql.ini.tmpl @@ -15,7 +15,7 @@ REPO_INDEXER_ENABLED = true REPO_INDEXER_PATH = integrations/indexers-mssql/repos.bleve [repository] -ROOT = integrations/gitea-integration-mssql/gitea-repositories +ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-mssql/gitea-repositories [repository.local] LOCAL_COPY_PATH = tmp/local-repo-mssql diff --git a/integrations/mysql.ini.tmpl b/integrations/mysql.ini.tmpl index 304434dbd6..beff736606 100644 --- a/integrations/mysql.ini.tmpl +++ b/integrations/mysql.ini.tmpl @@ -17,7 +17,7 @@ REPO_INDEXER_ENABLED = true REPO_INDEXER_PATH = integrations/indexers-mysql/repos.bleve [repository] -ROOT = integrations/gitea-integration-mysql/gitea-repositories +ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-mysql/gitea-repositories [repository.local] LOCAL_COPY_PATH = tmp/local-repo-mysql diff --git a/integrations/mysql8.ini.tmpl b/integrations/mysql8.ini.tmpl index 1b1d3d2436..a135ecb981 100644 --- a/integrations/mysql8.ini.tmpl +++ b/integrations/mysql8.ini.tmpl @@ -15,7 +15,7 @@ REPO_INDEXER_ENABLED = true REPO_INDEXER_PATH = integrations/indexers-mysql8/repos.bleve [repository] -ROOT = integrations/gitea-integration-mysql8/gitea-repositories +ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-mysql8/gitea-repositories [repository.local] LOCAL_COPY_PATH = tmp/local-repo-mysql8 diff --git a/integrations/pgsql.ini.tmpl b/integrations/pgsql.ini.tmpl index f337d98fb4..80258437e5 100644 --- a/integrations/pgsql.ini.tmpl +++ b/integrations/pgsql.ini.tmpl @@ -16,7 +16,7 @@ REPO_INDEXER_ENABLED = true REPO_INDEXER_PATH = integrations/indexers-pgsql/repos.bleve [repository] -ROOT = integrations/gitea-integration-pgsql/gitea-repositories +ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-pgsql/gitea-repositories [repository.local] LOCAL_COPY_PATH = tmp/local-repo-pgsql diff --git a/integrations/sqlite.ini b/integrations/sqlite.ini.tmpl similarity index 96% rename from integrations/sqlite.ini rename to integrations/sqlite.ini.tmpl index 160af3456a..3873681842 100644 --- a/integrations/sqlite.ini +++ b/integrations/sqlite.ini.tmpl @@ -11,7 +11,7 @@ REPO_INDEXER_ENABLED = true REPO_INDEXER_PATH = integrations/indexers-sqlite/repos.bleve [repository] -ROOT = integrations/gitea-integration-sqlite/gitea-repositories +ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-sqlite/gitea-repositories [repository.local] LOCAL_COPY_PATH = tmp/local-repo-sqlite