loading up the forgejo repo on tangled to test page performance

Clean some legacy files and move some build files (#23699)

* Clean the "tools" directory. The "tools" directory contains only two
files, move them.
* The "external_renderer.go" works like "cat" command to echo Stdin to
Stdout , to help testing.
* The `// gobuild: external_renderer` is incorrect, there should be no
space: `//gobuild: external_renderer`
* The `fmt.Print(os.Args[1])` is not a well-defined behavior, and it's
never used.
* The "watch.sh" is for "make watch", it's somewhat related to "build"
* After this PR, there is no "tools" directory, the project root
directory looks slightly simpler than before.
* Remove the legacy "contrib/autoboot.sh", there is no
"gogs_supervisord.sh"
* Remove the legacy "contrib/mysql.sql", it's never mentioned anywhere.
* Remove the legacy "contrib/pr/checkout.go", it has been broken for
long time, and it introduces unnecessary dependencies of the main code
base.

authored by wxiaoguang and committed by GitHub 5b5f7b75 73b4010f

+2 -7
Makefile
··· 131 131 132 132 TAR_EXCLUDES := .git data indexers queues log node_modules $(EXECUTABLE) $(FOMANTIC_WORK_DIR)/node_modules $(DIST) $(MAKE_EVIDENCE_DIR) $(AIR_TMP_DIR) $(GO_LICENSE_TMP_DIR) 133 133 134 - GO_DIRS := cmd tests models modules routers build services tools 134 + GO_DIRS := build cmd models modules routers services tests 135 135 WEB_DIRS := web_src/js web_src/css 136 136 137 137 GO_SOURCES := $(wildcard *.go) ··· 219 219 @echo " - tidy run go mod tidy" 220 220 @echo " - test[\#TestSpecificName] run unit test" 221 221 @echo " - test-sqlite[\#TestSpecificName] run integration test for sqlite" 222 - @echo " - pr#<index> build and start gitea from a PR with integration test data loaded" 223 222 224 223 .PHONY: go-check 225 224 go-check: ··· 353 352 354 353 .PHONY: watch 355 354 watch: 356 - bash tools/watch.sh 355 + bash build/watch.sh 357 356 358 357 .PHONY: watch-frontend 359 358 watch-frontend: node-check node_modules ··· 938 937 @./gitea docs --man > man/man1/gitea.1 939 938 @gzip -9 man/man1/gitea.1 && echo man/man1/gitea.1.gz created 940 939 @#TODO A small script that formats config-cheat-sheet.en-us.md nicely for use as a config man page 941 - 942 - .PHONY: pr\#% 943 - pr\#%: clean-all 944 - $(GO) run contrib/pr/checkout.go $* 945 940 946 941 .PHONY: golangci-lint 947 942 golangci-lint:
+3
build/backport-locales.go
··· 1 + // Copyright 2023 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 1 4 //go:build ignore 2 5 3 6 package main
-1
build/code-batch-process.go
··· 65 65 "modules", 66 66 "routers", 67 67 "services", 68 - "tools", 69 68 } 70 69 co.includePatterns = append(co.includePatterns, regexp.MustCompile(`.*\.go$`)) 71 70
+20
build/test-echo.go
··· 1 + // Copyright 2023 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + //go:build ignore 5 + 6 + package main 7 + 8 + import ( 9 + "fmt" 10 + "io" 11 + "os" 12 + ) 13 + 14 + func main() { 15 + _, err := io.Copy(os.Stdout, os.Stdin) 16 + if err != nil { 17 + fmt.Fprintf(os.Stderr, "Error: %v", err) 18 + os.Exit(1) 19 + } 20 + }
-2
contrib/autoboot.sh
··· 1 - #!/bin/sh 2 - su git -c "/home/git/gogs/scripts/gogs_supervisord.sh restart"
-2
contrib/mysql.sql
··· 1 - DROP DATABASE IF EXISTS gitea; 2 - CREATE DATABASE IF NOT EXISTS gitea CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
-267
contrib/pr/checkout.go
··· 1 - // Copyright 2020 The Gitea Authors. All rights reserved. 2 - // SPDX-License-Identifier: MIT 3 - 4 - package main 5 - 6 - /* 7 - Checkout a PR and load the tests data into sqlite database 8 - */ 9 - 10 - import ( 11 - "context" 12 - "flag" 13 - "fmt" 14 - "log" 15 - "net/http" 16 - "os" 17 - "os/exec" 18 - "os/user" 19 - "path" 20 - "path/filepath" 21 - "runtime" 22 - "strconv" 23 - "time" 24 - 25 - "code.gitea.io/gitea/models/db" 26 - "code.gitea.io/gitea/models/unittest" 27 - gitea_git "code.gitea.io/gitea/modules/git" 28 - "code.gitea.io/gitea/modules/graceful" 29 - "code.gitea.io/gitea/modules/markup" 30 - "code.gitea.io/gitea/modules/markup/external" 31 - repo_module "code.gitea.io/gitea/modules/repository" 32 - "code.gitea.io/gitea/modules/setting" 33 - "code.gitea.io/gitea/modules/util" 34 - "code.gitea.io/gitea/routers" 35 - markup_service "code.gitea.io/gitea/services/markup" 36 - 37 - "github.com/go-git/go-git/v5" 38 - "github.com/go-git/go-git/v5/config" 39 - "github.com/go-git/go-git/v5/plumbing" 40 - "xorm.io/xorm" 41 - ) 42 - 43 - var codeFilePath = "contrib/pr/checkout.go" 44 - 45 - func runPR() { 46 - log.Printf("[PR] Starting gitea ...\n") 47 - curDir, err := os.Getwd() 48 - if err != nil { 49 - log.Fatal(err) 50 - } 51 - setting.SetCustomPathAndConf("", "", "") 52 - setting.InitProviderAllowEmpty() 53 - setting.LoadCommonSettings() 54 - 55 - setting.RepoRootPath, err = os.MkdirTemp(os.TempDir(), "repos") 56 - if err != nil { 57 - log.Fatalf("TempDir: %v\n", err) 58 - } 59 - setting.AppDataPath, err = os.MkdirTemp(os.TempDir(), "appdata") 60 - if err != nil { 61 - log.Fatalf("TempDir: %v\n", err) 62 - } 63 - setting.AppWorkPath = curDir 64 - setting.StaticRootPath = curDir 65 - setting.GravatarSource = "https://secure.gravatar.com/avatar/" 66 - setting.AppURL = "http://localhost:8080/" 67 - setting.HTTPPort = "8080" 68 - setting.SSH.Domain = "localhost" 69 - setting.SSH.Port = 3000 70 - setting.InstallLock = true 71 - setting.SecretKey = "9pCviYTWSb" 72 - setting.InternalToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTI3OTU5ODN9.OQkH5UmzID2XBdwQ9TAI6Jj2t1X-wElVTjbE7aoN4I8" 73 - curUser, err := user.Current() 74 - if err != nil { 75 - log.Fatal(err) 76 - } 77 - setting.RunUser = curUser.Username 78 - 79 - log.Printf("[PR] Loading fixtures data ...\n") 80 - //models.LoadConfigs() 81 - /* 82 - setting.Database.Type = "sqlite3" 83 - setting.Database.Path = ":memory:" 84 - setting.Database.Timeout = 500 85 - */ 86 - dbCfg := setting.CfgProvider.Section("database") 87 - dbCfg.NewKey("DB_TYPE", "sqlite3") 88 - dbCfg.NewKey("PATH", ":memory:") 89 - 90 - routers.InitGitServices() 91 - setting.Database.LogSQL = true 92 - // x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared") 93 - 94 - db.InitEngineWithMigration(context.Background(), func(_ *xorm.Engine) error { 95 - return nil 96 - }) 97 - db.HasEngine = true 98 - // x.ShowSQL(true) 99 - err = unittest.InitFixtures( 100 - unittest.FixturesOptions{ 101 - Dir: path.Join(curDir, "models/fixtures/"), 102 - }, 103 - ) 104 - if err != nil { 105 - fmt.Printf("Error initializing test database: %v\n", err) 106 - os.Exit(1) 107 - } 108 - unittest.LoadFixtures() 109 - util.RemoveAll(setting.RepoRootPath) 110 - util.RemoveAll(repo_module.LocalCopyPath()) 111 - unittest.CopyDir(path.Join(curDir, "tests/gitea-repositories-meta"), setting.RepoRootPath) 112 - 113 - log.Printf("[PR] Setting up router\n") 114 - // routers.GlobalInit() 115 - external.RegisterRenderers() 116 - markup.Init(markup_service.ProcessorHelper()) 117 - c := routers.NormalRoutes(graceful.GetManager().HammerContext()) 118 - 119 - log.Printf("[PR] Ready for testing !\n") 120 - log.Printf("[PR] Login with user1, user2, user3, ... with pass: password\n") 121 - /* 122 - log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubURL) 123 - 124 - if setting.LFS.StartServer { 125 - log.Info("LFS server enabled") 126 - } 127 - 128 - if setting.EnablePprof { 129 - go func() { 130 - log.Info("Starting pprof server on localhost:6060") 131 - log.Info("%v", http.ListenAndServe("localhost:6060", nil)) 132 - }() 133 - } 134 - */ 135 - 136 - // Start the server 137 - http.ListenAndServe(":8080", c) 138 - 139 - log.Printf("[PR] Cleaning up ...\n") 140 - /* 141 - if err = util.RemoveAll(setting.Indexer.IssuePath); err != nil { 142 - fmt.Printf("util.RemoveAll: %v\n", err) 143 - os.Exit(1) 144 - } 145 - if err = util.RemoveAll(setting.Indexer.RepoPath); err != nil { 146 - fmt.Printf("Unable to remove repo indexer: %v\n", err) 147 - os.Exit(1) 148 - } 149 - */ 150 - if err = util.RemoveAll(setting.RepoRootPath); err != nil { 151 - log.Fatalf("util.RemoveAll: %v\n", err) 152 - } 153 - if err = util.RemoveAll(setting.AppDataPath); err != nil { 154 - log.Fatalf("util.RemoveAll: %v\n", err) 155 - } 156 - } 157 - 158 - func main() { 159 - runPRFlag := flag.Bool("run", false, "Run the PR code") 160 - flag.Parse() 161 - if *runPRFlag { 162 - runPR() 163 - return 164 - } 165 - 166 - // To force checkout (e.g. Windows complains about unclean work tree) set env variable FORCE=true 167 - force, err := strconv.ParseBool(os.Getenv("FORCE")) 168 - if err != nil { 169 - force = false 170 - } 171 - 172 - // Otherwise checkout PR 173 - if len(os.Args) != 2 { 174 - log.Fatal("Need only one arg: the PR number") 175 - } 176 - pr := os.Args[1] 177 - 178 - codeFilePath = filepath.FromSlash(codeFilePath) // Convert to running OS 179 - 180 - // Copy this file if it will not exist in the PR branch 181 - dat, err := os.ReadFile(codeFilePath) 182 - if err != nil { 183 - log.Fatalf("Failed to cache this code file : %v", err) 184 - } 185 - 186 - repo, err := git.PlainOpen(".") 187 - if err != nil { 188 - log.Fatalf("Failed to open the repo : %v", err) 189 - } 190 - 191 - // Find remote upstream 192 - remotes, err := repo.Remotes() 193 - if err != nil { 194 - log.Fatalf("Failed to list remotes of repo : %v", err) 195 - } 196 - remoteUpstream := "origin" // Default 197 - for _, r := range remotes { 198 - if r.Config().URLs[0] == "https://github.com/go-gitea/gitea.git" || 199 - r.Config().URLs[0] == "https://github.com/go-gitea/gitea" || 200 - r.Config().URLs[0] == "git@github.com:go-gitea/gitea.git" { // fetch at index 0 201 - remoteUpstream = r.Config().Name 202 - break 203 - } 204 - } 205 - 206 - branch := fmt.Sprintf("pr-%s-%d", pr, time.Now().Unix()) 207 - branchRef := plumbing.NewBranchReferenceName(branch) 208 - 209 - log.Printf("Fetching PR #%s in %s\n", pr, branch) 210 - if runtime.GOOS == "windows" { 211 - // Use git cli command for windows 212 - runCmd("git", "fetch", remoteUpstream, fmt.Sprintf("pull/%s/head:%s", pr, branch)) 213 - } else { 214 - ref := fmt.Sprintf("%s%s/head:%s", gitea_git.PullPrefix, pr, branchRef) 215 - err = repo.Fetch(&git.FetchOptions{ 216 - RemoteName: remoteUpstream, 217 - RefSpecs: []config.RefSpec{ 218 - config.RefSpec(ref), 219 - }, 220 - }) 221 - if err != nil { 222 - log.Fatalf("Failed to fetch %s from %s : %v", ref, remoteUpstream, err) 223 - } 224 - } 225 - 226 - tree, err := repo.Worktree() 227 - if err != nil { 228 - log.Fatalf("Failed to parse git tree : %v", err) 229 - } 230 - log.Printf("Checkout PR #%s in %s\n", pr, branch) 231 - err = tree.Checkout(&git.CheckoutOptions{ 232 - Branch: branchRef, 233 - Force: force, 234 - }) 235 - if err != nil { 236 - log.Fatalf("Failed to checkout %s : %v", branch, err) 237 - } 238 - 239 - // Copy this file if not exist 240 - if _, err := os.Stat(codeFilePath); os.IsNotExist(err) { 241 - err = os.MkdirAll(filepath.Dir(codeFilePath), 0o755) 242 - if err != nil { 243 - log.Fatalf("Failed to duplicate this code file in PR : %v", err) 244 - } 245 - err = os.WriteFile(codeFilePath, dat, 0o644) 246 - if err != nil { 247 - log.Fatalf("Failed to duplicate this code file in PR : %v", err) 248 - } 249 - } 250 - // Force build of js, css, bin, ... 251 - runCmd("make", "build") 252 - // Start with integration test 253 - runCmd("go", "run", "-mod", "vendor", "-tags", "sqlite sqlite_unlock_notify", codeFilePath, "-run") 254 - } 255 - 256 - func runCmd(cmd ...string) { 257 - log.Printf("Executing : %s ...\n", cmd) 258 - c := exec.Command(cmd[0], cmd[1:]...) 259 - c.Stdout = os.Stdout 260 - c.Stderr = os.Stderr 261 - if err := c.Start(); err != nil { 262 - log.Panicln(err) 263 - } 264 - if err := c.Wait(); err != nil { 265 - log.Panicln(err) 266 - } 267 - }
+1 -1
tests/sqlite.ini.tmpl
··· 111 111 [markup.html] 112 112 ENABLED = true 113 113 FILE_EXTENSIONS = .html 114 - RENDER_COMMAND = `go run tools/external_renderer.go` 114 + RENDER_COMMAND = `go run build/test-echo.go` 115 115 IS_INPUT_FILE = false 116 116 RENDER_CONTENT_MODE=sanitized
-23
tools/external_renderer.go
··· 1 - // Copyright 2017 The Gitea Authors. All rights reserved. 2 - // SPDX-License-Identifier: MIT 3 - 4 - // gobuild: external_renderer 5 - 6 - package main 7 - 8 - import ( 9 - "fmt" 10 - "io" 11 - "os" 12 - ) 13 - 14 - func main() { 15 - if len(os.Args) > 1 { 16 - fmt.Print(os.Args[1]) 17 - } else { 18 - _, err := io.Copy(os.Stdout, os.Stdin) 19 - if err != nil { 20 - fmt.Println(err) 21 - } 22 - } 23 - }
tools/watch.sh build/watch.sh