Skip to content

Commit 0e3024d

Browse files
guillep2klunny
authored and
Yohann Delafollye
committed
Use /tmp for test repositories (go-gitea#11126)
* Add option to use /tmp for test repositories * Fix exit status * Add feedback about using tmp repos Co-authored-by: Guillermo Prandi <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent f05f417 commit 0e3024d

File tree

8 files changed

+43
-9
lines changed

8 files changed

+43
-9
lines changed

.drone.yml

+5
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ steps:
176176
GOPROXY: off
177177
TAGS: bindata
178178
TEST_LDAP: 1
179+
USE_REPO_TEST_DIR: 1
179180
depends_on:
180181
- build
181182

@@ -190,6 +191,7 @@ steps:
190191
GOPROXY: off
191192
TAGS: bindata
192193
TEST_LDAP: 1
194+
USE_REPO_TEST_DIR: 1
193195
depends_on:
194196
- build
195197

@@ -204,6 +206,7 @@ steps:
204206
GOPROXY: off
205207
TAGS: bindata
206208
TEST_LDAP: 1
209+
USE_REPO_TEST_DIR: 1
207210
depends_on:
208211
- build
209212

@@ -302,6 +305,7 @@ steps:
302305
environment:
303306
GOPROXY: off
304307
TAGS: bindata
308+
USE_REPO_TEST_DIR: 1
305309
depends_on:
306310
- build
307311

@@ -316,6 +320,7 @@ steps:
316320
GOPROXY: off
317321
TAGS: bindata
318322
TEST_LDAP: 1
323+
USE_REPO_TEST_DIR: 1
319324
depends_on:
320325
- build
321326

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ coverage.all
6868
/integrations/indexers-pgsql
6969
/integrations/indexers-sqlite
7070
/integrations/indexers-mssql
71+
/integrations/sqlite.ini
7172
/integrations/mysql.ini
7273
/integrations/mysql8.ini
7374
/integrations/pgsql.ini

Makefile

+32-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
2+
ifeq ($(USE_REPO_TEST_DIR),1)
3+
4+
# This rule replaces the whole Makefile when we're trying to use /tmp repository temporary files
5+
location = $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
6+
self := $(location)
7+
8+
%:
9+
@tmpdir=`mktemp --tmpdir -d` ; \
10+
echo Using temporary directory $$tmpdir for test repositories ; \
11+
USE_REPO_TEST_DIR= $(MAKE) -f $(self) --no-print-directory REPO_TEST_DIR=$$tmpdir/ $@ ; \
12+
STATUS=$$? ; rm -r "$$tmpdir" ; exit $$STATUS
13+
14+
else
15+
16+
# This is the "normal" part of the Makefile
17+
118
DIST := dist
219
DIST_DIRS := $(DIST)/binaries $(DIST)/release
320
IMPORT := code.gitea.io/gitea
@@ -321,23 +338,28 @@ test-vendor: vendor
321338
exit 1; \
322339
fi;
323340

341+
generate-ini-sqlite:
342+
sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
343+
integrations/sqlite.ini.tmpl > integrations/sqlite.ini
344+
324345
.PHONY: test-sqlite
325-
test-sqlite: integrations.sqlite.test
346+
test-sqlite: integrations.sqlite.test generate-ini-sqlite
326347
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test
327348

328349
.PHONY: test-sqlite\#%
329-
test-sqlite\#%: integrations.sqlite.test
350+
test-sqlite\#%: integrations.sqlite.test generate-ini-sqlite
330351
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.run $(subst .,/,$*)
331352

332353
.PHONY: test-sqlite-migration
333-
test-sqlite-migration: migrations.sqlite.test
354+
test-sqlite-migration: migrations.sqlite.test generate-ini-sqlite
334355
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./migrations.sqlite.test
335356

336357
generate-ini-mysql:
337358
sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
338359
-e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
339360
-e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
340361
-e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
362+
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
341363
integrations/mysql.ini.tmpl > integrations/mysql.ini
342364

343365
.PHONY: test-mysql
@@ -357,6 +379,7 @@ generate-ini-mysql8:
357379
-e 's|{{TEST_MYSQL8_DBNAME}}|${TEST_MYSQL8_DBNAME}|g' \
358380
-e 's|{{TEST_MYSQL8_USERNAME}}|${TEST_MYSQL8_USERNAME}|g' \
359381
-e 's|{{TEST_MYSQL8_PASSWORD}}|${TEST_MYSQL8_PASSWORD}|g' \
382+
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
360383
integrations/mysql8.ini.tmpl > integrations/mysql8.ini
361384

362385
.PHONY: test-mysql8
@@ -377,6 +400,7 @@ generate-ini-pgsql:
377400
-e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
378401
-e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
379402
-e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
403+
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
380404
integrations/pgsql.ini.tmpl > integrations/pgsql.ini
381405

382406
.PHONY: test-pgsql
@@ -396,6 +420,7 @@ generate-ini-mssql:
396420
-e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
397421
-e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
398422
-e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
423+
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
399424
integrations/mssql.ini.tmpl > integrations/mssql.ini
400425

401426
.PHONY: test-mssql
@@ -411,7 +436,7 @@ test-mssql-migration: migrations.mssql.test generate-ini-mssql
411436
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./migrations.mssql.test
412437

413438
.PHONY: bench-sqlite
414-
bench-sqlite: integrations.sqlite.test
439+
bench-sqlite: integrations.sqlite.test generate-ini-sqlite
415440
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
416441

417442
.PHONY: bench-mysql
@@ -627,3 +652,6 @@ golangci-lint:
627652
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.24.0; \
628653
fi
629654
golangci-lint run --timeout 5m
655+
656+
# This endif closes the if at the top of the file
657+
endif

integrations/mssql.ini.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ REPO_INDEXER_ENABLED = true
1515
REPO_INDEXER_PATH = integrations/indexers-mssql/repos.bleve
1616

1717
[repository]
18-
ROOT = integrations/gitea-integration-mssql/gitea-repositories
18+
ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-mssql/gitea-repositories
1919

2020
[repository.local]
2121
LOCAL_COPY_PATH = tmp/local-repo-mssql

integrations/mysql.ini.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ REPO_INDEXER_ENABLED = true
1717
REPO_INDEXER_PATH = integrations/indexers-mysql/repos.bleve
1818

1919
[repository]
20-
ROOT = integrations/gitea-integration-mysql/gitea-repositories
20+
ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-mysql/gitea-repositories
2121

2222
[repository.local]
2323
LOCAL_COPY_PATH = tmp/local-repo-mysql

integrations/mysql8.ini.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ REPO_INDEXER_ENABLED = true
1515
REPO_INDEXER_PATH = integrations/indexers-mysql8/repos.bleve
1616

1717
[repository]
18-
ROOT = integrations/gitea-integration-mysql8/gitea-repositories
18+
ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-mysql8/gitea-repositories
1919

2020
[repository.local]
2121
LOCAL_COPY_PATH = tmp/local-repo-mysql8

integrations/pgsql.ini.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ REPO_INDEXER_ENABLED = true
1616
REPO_INDEXER_PATH = integrations/indexers-pgsql/repos.bleve
1717

1818
[repository]
19-
ROOT = integrations/gitea-integration-pgsql/gitea-repositories
19+
ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-pgsql/gitea-repositories
2020

2121
[repository.local]
2222
LOCAL_COPY_PATH = tmp/local-repo-pgsql

integrations/sqlite.ini renamed to integrations/sqlite.ini.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ REPO_INDEXER_ENABLED = true
1111
REPO_INDEXER_PATH = integrations/indexers-sqlite/repos.bleve
1212

1313
[repository]
14-
ROOT = integrations/gitea-integration-sqlite/gitea-repositories
14+
ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-sqlite/gitea-repositories
1515

1616
[repository.local]
1717
LOCAL_COPY_PATH = tmp/local-repo-sqlite

0 commit comments

Comments
 (0)