Skip to content

Commit 5467918

Browse files
authored
Merge branch 'main' into lunny/rework_create_release
2 parents f3102d4 + 5e9b9b3 commit 5467918

File tree

34 files changed

+301
-310
lines changed

34 files changed

+301
-310
lines changed

.github/workflows/pull-db-tests.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ jobs:
6363
RACE_ENABLED: true
6464
TEST_TAGS: gogit
6565
TEST_LDAP: 1
66-
USE_REPO_TEST_DIR: 1
6766

6867
test-sqlite:
6968
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true'
@@ -90,7 +89,6 @@ jobs:
9089
TAGS: bindata gogit sqlite sqlite_unlock_notify
9190
RACE_ENABLED: true
9291
TEST_TAGS: gogit sqlite sqlite_unlock_notify
93-
USE_REPO_TEST_DIR: 1
9492

9593
test-unit:
9694
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true'
@@ -206,7 +204,6 @@ jobs:
206204
env:
207205
TAGS: bindata
208206
RACE_ENABLED: true
209-
USE_REPO_TEST_DIR: 1
210207
TEST_INDEXER_CODE_ES_URL: "http://elastic:changeme@elasticsearch:9200"
211208

212209
test-mssql:
@@ -246,4 +243,3 @@ jobs:
246243
timeout-minutes: 50
247244
env:
248245
TAGS: bindata
249-
USE_REPO_TEST_DIR: 1

Makefile

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
1-
ifeq ($(USE_REPO_TEST_DIR),1)
2-
3-
# This rule replaces the whole Makefile when we're trying to use /tmp repository temporary files
4-
location = $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
5-
self := $(location)
6-
7-
%:
8-
@tmpdir=`mktemp --tmpdir -d` ; \
9-
echo Using temporary directory $$tmpdir for test repositories ; \
10-
USE_REPO_TEST_DIR= $(MAKE) -f $(self) --no-print-directory REPO_TEST_DIR=$$tmpdir/ $@ ; \
11-
STATUS=$$? ; rm -r "$$tmpdir" ; exit $$STATUS
12-
13-
else
14-
15-
# This is the "normal" part of the Makefile
16-
171
DIST := dist
182
DIST_DIRS := $(DIST)/binaries $(DIST)/release
19-
IMPORT := code.gitea.io/gitea
203

214
# By default use go's 1.25 experimental json v2 library when building
225
# TODO: remove when no longer experimental
@@ -83,7 +66,6 @@ endif
8366

8467
EXTRA_GOFLAGS ?=
8568

86-
MAKE_VERSION := $(shell "$(MAKE)" -v | cat | head -n 1)
8769
MAKE_EVIDENCE_DIR := .make_evidence
8870

8971
GOTESTFLAGS ?=
@@ -129,7 +111,7 @@ ifeq ($(VERSION),main)
129111
VERSION := main-nightly
130112
endif
131113

132-
LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
114+
LDFLAGS := $(LDFLAGS) -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
133115

134116
LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64,linux/riscv64
135117

@@ -227,7 +209,7 @@ clean: ## delete backend and integration files
227209
e2e*.test \
228210
tests/integration/gitea-integration-* \
229211
tests/integration/indexers-* \
230-
tests/mysql.ini tests/pgsql.ini tests/mssql.ini man/ \
212+
tests/sqlite.ini tests/mysql.ini tests/pgsql.ini tests/mssql.ini man/ \
231213
tests/e2e/gitea-e2e-*/ \
232214
tests/e2e/indexers-*/ \
233215
tests/e2e/reports/ tests/e2e/test-artifacts/ tests/e2e/test-snapshots/
@@ -474,9 +456,8 @@ $(GO_LICENSE_FILE): go.mod go.sum
474456
GO=$(GO) $(GO) run build/generate-go-licenses.go $(GO_LICENSE_FILE)
475457

476458
generate-ini-sqlite:
477-
sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
459+
sed -e 's|{{WORK_PATH}}|$(CURDIR)/tests/$(or $(TEST_TYPE),integration)/gitea-$(or $(TEST_TYPE),integration)-sqlite|g' \
478460
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
479-
-e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
480461
tests/sqlite.ini.tmpl > tests/sqlite.ini
481462

482463
.PHONY: test-sqlite
@@ -495,9 +476,8 @@ generate-ini-mysql:
495476
-e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
496477
-e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
497478
-e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
498-
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
479+
-e 's|{{WORK_PATH}}|$(CURDIR)/tests/$(or $(TEST_TYPE),integration)/gitea-$(or $(TEST_TYPE),integration)-mysql|g' \
499480
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
500-
-e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
501481
tests/mysql.ini.tmpl > tests/mysql.ini
502482

503483
.PHONY: test-mysql
@@ -518,9 +498,8 @@ generate-ini-pgsql:
518498
-e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
519499
-e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
520500
-e 's|{{TEST_MINIO_ENDPOINT}}|${TEST_MINIO_ENDPOINT}|g' \
521-
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
501+
-e 's|{{WORK_PATH}}|$(CURDIR)/tests/$(or $(TEST_TYPE),integration)/gitea-$(or $(TEST_TYPE),integration)-pgsql|g' \
522502
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
523-
-e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
524503
tests/pgsql.ini.tmpl > tests/pgsql.ini
525504

526505
.PHONY: test-pgsql
@@ -539,9 +518,8 @@ generate-ini-mssql:
539518
-e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
540519
-e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
541520
-e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
542-
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
521+
-e 's|{{WORK_PATH}}|$(CURDIR)/tests/$(or $(TEST_TYPE),integration)/gitea-$(or $(TEST_TYPE),integration)-mssql|g' \
543522
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
544-
-e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
545523
tests/mssql.ini.tmpl > tests/mssql.ini
546524

547525
.PHONY: test-mssql
@@ -662,15 +640,15 @@ migrations.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
662640
GITEA_TEST_CONF=tests/sqlite.ini ./migrations.sqlite.test
663641

664642
.PHONY: migrations.individual.mysql.test
665-
migrations.individual.mysql.test: $(GO_SOURCES)
643+
migrations.individual.mysql.test: $(GO_SOURCES) generate-ini-mysql
666644
GITEA_TEST_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
667645

668646
.PHONY: migrations.individual.sqlite.test\#%
669647
migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
670648
GITEA_TEST_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
671649

672650
.PHONY: migrations.individual.pgsql.test
673-
migrations.individual.pgsql.test: $(GO_SOURCES)
651+
migrations.individual.pgsql.test: $(GO_SOURCES) generate-ini-pgsql
674652
GITEA_TEST_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
675653

676654
.PHONY: migrations.individual.pgsql.test\#%
@@ -901,9 +879,6 @@ docker:
901879
docker build --disable-content-trust=false -t $(DOCKER_REF) .
902880
# support also build args docker build --build-arg GITEA_VERSION=v1.2.3 --build-arg TAGS="bindata sqlite sqlite_unlock_notify" .
903881

904-
# This endif closes the if at the top of the file
905-
endif
906-
907882
# Disable parallel execution because it would break some targets that don't
908883
# specify exact dependencies like 'backend' which does currently not depend
909884
# on 'frontend' to enable Node.js-less builds from source tarballs.

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,6 +2858,9 @@ LEVEL = Info
28582858
;ABANDONED_JOB_TIMEOUT = 24h
28592859
;; Strings committers can place inside a commit message or PR title to skip executing the corresponding actions workflow
28602860
;SKIP_WORKFLOW_STRINGS = [skip ci],[ci skip],[no ci],[skip actions],[actions skip]
2861+
;; Comma-separated list of workflow directories, the first one to exist
2862+
;; in a repo is used to find Actions workflow files
2863+
;WORKFLOW_DIRS = .gitea/workflows,.github/workflows
28612864

28622865
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28632866
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

main.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ import (
2626

2727
// these flags will be set by the build flags
2828
var (
29-
Version = "development" // program version for this build
30-
Tags = "" // the Golang build tags
31-
MakeVersion = "" // "make" program version if built with make
29+
Version = "development" // program version for this build
30+
Tags = "" // the Golang build tags
3231
)
3332

3433
func init() {
@@ -50,9 +49,6 @@ func main() {
5049

5150
func formatBuiltWith() string {
5251
version := runtime.Version()
53-
if len(MakeVersion) > 0 {
54-
version = MakeVersion + ", " + runtime.Version()
55-
}
5652
if len(Tags) == 0 {
5753
return " built with " + version
5854
}

models/migrations/base/tests.go

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"path"
1111
"path/filepath"
1212
"testing"
13-
"time"
1413

1514
"code.gitea.io/gitea/models/db"
1615
"code.gitea.io/gitea/models/unittest"
@@ -27,18 +26,6 @@ import (
2726

2827
// FIXME: this file shouldn't be in a normal package, it should only be compiled for tests
2928

30-
func removeAllWithRetry(dir string) error {
31-
var err error
32-
for range 20 {
33-
err = os.RemoveAll(dir)
34-
if err == nil {
35-
break
36-
}
37-
time.Sleep(100 * time.Millisecond)
38-
}
39-
return err
40-
}
41-
4229
func newXORMEngine(t *testing.T) (*xorm.Engine, error) {
4330
if err := db.InitEngine(t.Context()); err != nil {
4431
return nil, err
@@ -213,29 +200,26 @@ func LoadTableSchemasMap(t *testing.T, x *xorm.Engine) map[string]*schemas.Table
213200
return tableMap
214201
}
215202

216-
func MainTest(m *testing.M) {
203+
func mainTest(m *testing.M) int {
217204
testlogger.Init()
218-
setting.SetupGiteaTestEnv()
219205

220206
tmpDataPath, cleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("data")
221207
if err != nil {
222-
testlogger.Fatalf("Unable to create temporary data path %v\n", err)
208+
testlogger.Panicf("Unable to create temporary data path %v\n", err)
223209
}
224210
defer cleanup()
225211

226212
setting.AppDataPath = tmpDataPath
227213

228214
unittest.InitSettingsForTesting()
229215
if err = git.InitFull(); err != nil {
230-
testlogger.Fatalf("Unable to InitFull: %v\n", err)
216+
testlogger.Panicf("Unable to InitFull: %v\n", err)
231217
}
232218
setting.LoadDBSetting()
233219
setting.InitLoggersForTest()
220+
return m.Run()
221+
}
234222

235-
exitStatus := m.Run()
236-
237-
if err := removeAllWithRetry(setting.RepoRootPath); err != nil {
238-
_, _ = fmt.Fprintf(os.Stderr, "os.RemoveAll: %v\n", err)
239-
}
240-
os.Exit(exitStatus)
223+
func MainTest(m *testing.M) {
224+
os.Exit(mainTest(m))
241225
}

models/unittest/fixtures_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package unittest_test
55

66
import (
7+
"os"
78
"path/filepath"
89
"testing"
910

@@ -58,9 +59,14 @@ func NewFixturesLoaderVendorGoTestfixtures(e *xorm.Engine, opts unittest.Fixture
5859
}
5960
*/
6061

62+
func TestMain(m *testing.M) {
63+
setting.SetupGiteaTestEnv()
64+
os.Exit(m.Run())
65+
}
66+
6167
func prepareTestFixturesLoaders(t testing.TB) unittest.FixturesOptions {
6268
_ = user_model.User{}
63-
giteaRoot := setting.SetupGiteaTestEnv()
69+
giteaRoot := setting.GetGiteaTestSourceRoot()
6470
opts := unittest.FixturesOptions{Dir: filepath.Join(giteaRoot, "models", "fixtures"), Files: []string{
6571
"user.yml",
6672
}}

models/unittest/fscopy.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
package unittest
55

66
import (
7+
"errors"
78
"os"
89
"path/filepath"
910
"strings"
1011

12+
"code.gitea.io/gitea/modules/setting"
1113
"code.gitea.io/gitea/modules/util"
1214
)
1315

@@ -39,7 +41,20 @@ func SyncFile(srcPath, destPath string) error {
3941
// SyncDirs synchronizes files recursively from source to target directory.
4042
// It returns error when error occurs in underlying functions.
4143
func SyncDirs(srcPath, destPath string) error {
42-
err := os.MkdirAll(destPath, os.ModePerm)
44+
destPath = filepath.Clean(destPath)
45+
destPathAbs, err := filepath.Abs(destPath)
46+
if err != nil {
47+
return err
48+
}
49+
devDataPathAbs, err := filepath.Abs(filepath.Join(setting.GetGiteaTestSourceRoot(), "data"))
50+
if err != nil {
51+
return err
52+
}
53+
if strings.HasPrefix(destPathAbs+string(filepath.Separator), devDataPathAbs+string(filepath.Separator)) {
54+
return errors.New("destination path should not be inside Gitea data directory, otherwise your data for dev mode will be removed")
55+
}
56+
57+
err = os.MkdirAll(destPath, os.ModePerm)
4358
if err != nil {
4459
return err
4560
}

0 commit comments

Comments
 (0)