Skip to content

Commit ce5d711

Browse files
committed
Merge branch 'main' into blender-merged-develop
2 parents 33cf63a + 738f2af commit ce5d711

File tree

199 files changed

+2620
-2436
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+2620
-2436
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
* text=auto eol=lf
22
*.tmpl linguist-language=Handlebars
33
/assets/*.json linguist-generated
4+
/public/img/svg/*.svg linguist-generated
45
/public/vendor/** -text -eol linguist-vendored
56
/vendor/** -text -eol linguist-vendored
67
/web_src/fomantic/build/** linguist-generated

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ IMPORT := code.gitea.io/gitea
2020

2121
GO ?= go
2222
SHASUM ?= shasum -a 256
23-
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
23+
HAS_GO := $(shell hash $(GO) > /dev/null 2>&1 && echo yes)
2424
COMMA := ,
2525

2626
XGO_VERSION := go-1.20.x
@@ -41,7 +41,7 @@ DOCKER_IMAGE ?= gitea/gitea
4141
DOCKER_TAG ?= latest
4242
DOCKER_REF := $(DOCKER_IMAGE):$(DOCKER_TAG)
4343

44-
ifeq ($(HAS_GO), GO)
44+
ifeq ($(HAS_GO), yes)
4545
GOPATH ?= $(shell $(GO) env GOPATH)
4646
export PATH := $(GOPATH)/bin:$(PATH)
4747

cmd/actions.go

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
9+
"code.gitea.io/gitea/modules/private"
10+
"code.gitea.io/gitea/modules/setting"
11+
12+
"github.com/urfave/cli"
13+
)
14+
15+
var (
16+
// CmdActions represents the available actions sub-commands.
17+
CmdActions = cli.Command{
18+
Name: "actions",
19+
Usage: "",
20+
Description: "Commands for managing Gitea Actions",
21+
Subcommands: []cli.Command{
22+
subcmdActionsGenRunnerToken,
23+
},
24+
}
25+
26+
subcmdActionsGenRunnerToken = cli.Command{
27+
Name: "generate-runner-token",
28+
Usage: "Generate a new token for a runner to use to register with the server",
29+
Action: runGenerateActionsRunnerToken,
30+
Aliases: []string{"grt"},
31+
Flags: []cli.Flag{
32+
cli.StringFlag{
33+
Name: "scope, s",
34+
Value: "",
35+
Usage: "{owner}[/{repo}] - leave empty for a global runner",
36+
},
37+
},
38+
}
39+
)
40+
41+
func runGenerateActionsRunnerToken(c *cli.Context) error {
42+
ctx, cancel := installSignals()
43+
defer cancel()
44+
45+
setting.InitProviderFromExistingFile()
46+
setting.LoadCommonSettings()
47+
48+
scope := c.String("scope")
49+
50+
respText, extra := private.GenerateActionsRunnerToken(ctx, scope)
51+
if extra.HasError() {
52+
return handleCliResponseExtra(extra)
53+
}
54+
_, _ = fmt.Printf("%s\n", respText)
55+
return nil
56+
}

cmd/convert.go

+16-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
var CmdConvert = cli.Command{
1818
Name: "convert",
1919
Usage: "Convert the database",
20-
Description: "A command to convert an existing MySQL database from utf8 to utf8mb4",
20+
Description: "A command to convert an existing MySQL database from utf8 to utf8mb4 or MSSQL database from varchar to nvarchar",
2121
Action: runConvert,
2222
}
2323

@@ -35,17 +35,22 @@ func runConvert(ctx *cli.Context) error {
3535
log.Info("Log path: %s", setting.Log.RootPath)
3636
log.Info("Configuration file: %s", setting.CustomConf)
3737

38-
if !setting.Database.Type.IsMySQL() {
39-
fmt.Println("This command can only be used with a MySQL database")
40-
return nil
38+
switch {
39+
case setting.Database.Type.IsMySQL():
40+
if err := db.ConvertUtf8ToUtf8mb4(); err != nil {
41+
log.Fatal("Failed to convert database from utf8 to utf8mb4: %v", err)
42+
return err
43+
}
44+
fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")
45+
case setting.Database.Type.IsMSSQL():
46+
if err := db.ConvertVarcharToNVarchar(); err != nil {
47+
log.Fatal("Failed to convert database from varchar to nvarchar: %v", err)
48+
return err
49+
}
50+
fmt.Println("Converted successfully, please confirm your database's all columns character is NVARCHAR now")
51+
default:
52+
fmt.Println("This command can only be used with a MySQL or MSSQL database")
4153
}
4254

43-
if err := db.ConvertUtf8ToUtf8mb4(); err != nil {
44-
log.Fatal("Failed to convert database from utf8 to utf8mb4: %v", err)
45-
return err
46-
}
47-
48-
fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")
49-
5055
return nil
5156
}

docs/content/doc/administration/command-line.en-us.md

+25
Original file line numberDiff line numberDiff line change
@@ -551,3 +551,28 @@ Restore-repo restore repository data from disk dir:
551551
- `--owner_name lunny`: Restore destination owner name
552552
- `--repo_name tango`: Restore destination repository name
553553
- `--units <units>`: Which items will be restored, one or more units should be separated as comma. wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.
554+
555+
### actions generate-runner-token
556+
557+
Generate a new token for a runner to use to register with the server
558+
559+
- Options:
560+
- `--scope {owner}[/{repo}]`, `-s {owner}[/{repo}]`: To limit the scope of the runner, no scope means the runner can be used for all repos, but you can also limit it to a specific repo or owner
561+
562+
To register a global runner:
563+
564+
```
565+
gitea actions generate-runner-token
566+
```
567+
568+
To register a runner for a specific organization, in this case `org`:
569+
570+
```
571+
gitea actions generate-runner-token -s org
572+
```
573+
574+
To register a runner for a specific repo, in this case `username/test-repo`:
575+
576+
```
577+
gitea actions generate-runner-token -s username/test-repo
578+
```

docs/content/doc/administration/https-support.zh-cn.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ PORT_TO_REDIRECT = 3080
5858

5959
[ACME](https://tools.ietf.org/html/rfc8555) 是一种证书颁发机构标准协议,允许您自动请求和续订 SSL/TLS 证书。[Let`s Encrypt](https://letsencrypt.org/) 是使用此标准的免费公开信任的证书颁发机构服务器。仅实施“HTTP-01”和“TLS-ALPN-01”挑战。为了使 ACME 质询通过并验证您的域所有权,“80”端口(“HTTP-01”)或“443”端口(“TLS-ALPN-01”)上 gitea 域的外部流量必须由 gitea 实例提供服务。可能需要设置 [HTTP 重定向](#设置http重定向) 和端口转发才能正确路由外部流量。否则,到端口“80”的正常流量将自动重定向到 HTTPS。**您必须同意**ACME提供商的服务条款(默认为Let's Encrypt的 [服务条款](https://letsencrypt.org/documents/LE-SA-v1.2-2017年11月15日.pdf)
6060

61-
实用默认 Let's Encrypt 的最小配置如下:
61+
使用默认 Let's Encrypt 的最小配置如下:
6262

6363
```ini
6464
[server]
@@ -92,7 +92,7 @@ ACME_EMAIL=email@example.com
9292

9393
按照 [reverse proxy guide](../reverse-proxies) 的规则设置你的反向代理服务器
9494

95-
然后,按照下面的想到启用 HTTPS:
95+
然后,按照下面的向导启用 HTTPS:
9696

9797
- [nginx](https://nginx.org/en/docs/http/configuring_https_servers.html)
9898
- [apache2/httpd](https://httpd.apache.org/docs/2.4/ssl/ssl_howto.html)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
date: "2021-09-02T16:00:00+08:00"
3+
title: "从旧版 Gitea 升级"
4+
slug: "upgrade-from-gitea"
5+
weight: 100
6+
toc: false
7+
draft: false
8+
menu:
9+
sidebar:
10+
parent: "installation"
11+
name: "从旧版 Gitea 升级"
12+
weight: 100
13+
identifier: "upgrade-from-gitea"
14+
---
15+
16+
# 从旧版 Gitea 升级
17+
18+
**目录**
19+
20+
{{< toc >}}
21+
22+
想要升级 Gitea,只需要下载新版,停止运行旧版,进行数据备份,然后运行新版就好。
23+
每次 Gitea 实例启动时,它都会检查是否要进行数据库迁移。
24+
如果需要进行数据库迁移,Gitea 会花一些时间完成升级然后继续服务。
25+
26+
## 为重大变更检查更新日志
27+
28+
为了让 Gitea 变得更好,进行重大变更是不可避免的,尤其是一些里程碑更新的发布。
29+
在更新前,请 [在 Gitea 博客上阅读更新日志](https://blog.gitea.io/)
30+
并检查重大变更是否会影响你的 Gitea 实例。
31+
32+
## 降级前的备份
33+
34+
Gitea 会保留首二位版本号相同的版本的兼容性 (`a.b.x` -> `a.b.y`),
35+
这些版本拥有相同的数据库结构,可以自由升级或降级。
36+
其他情况 (`a.b.?` -> `a.c.?`)下,
37+
新版 Gitea 可能将会将数据库升级到与旧版数据库不同的结构。
38+
39+
举个例子:
40+
41+
| 当前 | 目标 | 结果 |
42+
| --- | --- | --- |
43+
| 1.4.0 | 1.4.1 ||
44+
| 1.4.1 | 1.4.0 | ⚠️ 不建议,后果自负!尽管数据库结构可能不会变更,让它可以正常工作。我们强烈建议降级前进行完全的备份。 |
45+
| 1.4.x | 1.5.y | ✅ 数据库会被自动升级。你可以直接从 1.4.x 升级到最新的 1.5.y。 |
46+
| 1.5.y | 1.4.x | ❌ 数据库已被升级且不可被旧版 Gitea 利用,使用备份来进行降级。 |
47+
48+
**因为你不能基于升级后的数据库运行旧版 Gitea,所以你应该在数据库升级前完成数据备份。**
49+
50+
如果你在生产环境下使用 Gitea,你应该在升级前做好备份,哪怕只是小版本的补丁更新。
51+
52+
备份步骤:
53+
54+
* 停止 Gitea 实例
55+
* 备份数据库
56+
* 备份 Gitea 配置文件
57+
* 备份 Gitea 在 `APP_DATA_PATH` 中的数据文件
58+
* 备份 Gitea 的外部存储 (例如: S3/MinIO 或被使用的其他存储)
59+
60+
如果你在使用云服务或拥有快照功能的文件系统,
61+
最好对 Gitea 的数据盘及相关资料存储进行一次快照。
62+
63+
## 从 Docker 升级
64+
65+
* `docker pull` 拉取 Gitea 的最新发布版。
66+
* 停止运行中的实例,备份数据。
67+
* 使用 `docker``docker-compose` 启动更新的 Gitea Docker 容器.
68+
69+
## 从包升级
70+
71+
* 停止运行中的实例,备份数据。
72+
* 使用你的包管理器更新 Gitea 到最新版本。
73+
* 启动 Gitea 实例。
74+
75+
## 从二进制升级
76+
77+
* 下载最新的 Gitea 二进制文件到临时文件夹中。
78+
* 停止运行中的实例,备份数据。
79+
* 将旧的 Gitea 二进制文件覆盖成新的。
80+
* 启动 Gitea 实例。
81+
82+
在 Linux 系统上自动执行以上步骤的脚本可在 [Gitea 的 source tree 中找到 `contrib/upgrade.sh` 来获取](https://github.com/go-gitea/gitea/blob/main/contrib/upgrade.sh).
83+
84+
## 小心你的自定义模板
85+
86+
Gitea 的模板结构与变量可能会随着各个版本的发布发生变化,如果你使用了自定义模板,
87+
你得注意你的模板与你使用的 Gitea 版本的兼容性。
88+
89+
如果自定义模板与 Gitea 版本不兼容,你可能会得到:
90+
`50x` 服务器错误,页面元素丢失或故障,莫名其妙的页面布局,等等…
91+
移除或更新不兼容的模板,Gitea Web 才可以正常工作。

main.go

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ arguments - which can alternatively be run by running the subcommand web.`
7575
cmd.CmdDocs,
7676
cmd.CmdDumpRepository,
7777
cmd.CmdRestoreRepository,
78+
cmd.CmdActions,
7879
}
7980
// Now adjust these commands to add our global configuration options
8081

models/activities/user_heatmap.go

+9
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,12 @@ func getUserHeatmapData(user *user_model.User, team *organization.Team, doer *us
6969
OrderBy("timestamp").
7070
Find(&hdata)
7171
}
72+
73+
// GetTotalContributionsInHeatmap returns the total number of contributions in a heatmap
74+
func GetTotalContributionsInHeatmap(hdata []*UserHeatmapData) int64 {
75+
var total int64
76+
for _, v := range hdata {
77+
total += v.Contributions
78+
}
79+
return total
80+
}

models/db/convert.go

+27
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,33 @@ func ConvertUtf8ToUtf8mb4() error {
4242
return nil
4343
}
4444

45+
// ConvertVarcharToNVarchar converts database and tables from varchar to nvarchar if it's mssql
46+
func ConvertVarcharToNVarchar() error {
47+
if x.Dialect().URI().DBType != schemas.MSSQL {
48+
return nil
49+
}
50+
51+
sess := x.NewSession()
52+
defer sess.Close()
53+
res, err := sess.QuerySliceString(`SELECT 'ALTER TABLE ' + OBJECT_NAME(SC.object_id) + ' MODIFY SC.name NVARCHAR(' + CONVERT(VARCHAR(5),SC.max_length) + ')'
54+
FROM SYS.columns SC
55+
JOIN SYS.types ST
56+
ON SC.system_type_id = ST.system_type_id
57+
AND SC.user_type_id = ST.user_type_id
58+
WHERE ST.name ='varchar'`)
59+
if err != nil {
60+
return err
61+
}
62+
for _, row := range res {
63+
if len(row) == 1 {
64+
if _, err = sess.Exec(row[0]); err != nil {
65+
return err
66+
}
67+
}
68+
}
69+
return err
70+
}
71+
4572
// Cell2Int64 converts a xorm.Cell type to int64,
4673
// and handles possible irregular cases.
4774
func Cell2Int64(val xorm.Cell) int64 {

models/db/iterate_test.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ func TestIterate(t *testing.T) {
1919
xe := unittest.GetXORMEngine()
2020
assert.NoError(t, xe.Sync(&repo_model.RepoUnit{}))
2121

22-
var repoCnt int
23-
err := db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repo *repo_model.RepoUnit) error {
24-
repoCnt++
22+
cnt, err := db.GetEngine(db.DefaultContext).Count(&repo_model.RepoUnit{})
23+
assert.NoError(t, err)
24+
25+
var repoUnitCnt int
26+
err = db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repo *repo_model.RepoUnit) error {
27+
repoUnitCnt++
2528
return nil
2629
})
2730
assert.NoError(t, err)
28-
assert.EqualValues(t, 84, repoCnt)
31+
assert.EqualValues(t, cnt, repoUnitCnt)
2932

3033
err = db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repoUnit *repo_model.RepoUnit) error {
3134
reopUnit2 := repo_model.RepoUnit{ID: repoUnit.ID}

models/db/list_test.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,20 @@ func TestFind(t *testing.T) {
3131
xe := unittest.GetXORMEngine()
3232
assert.NoError(t, xe.Sync(&repo_model.RepoUnit{}))
3333

34+
var repoUnitCount int
35+
_, err := db.GetEngine(db.DefaultContext).SQL("SELECT COUNT(*) FROM repo_unit").Get(&repoUnitCount)
36+
assert.NoError(t, err)
37+
assert.NotEmpty(t, repoUnitCount)
38+
3439
opts := mockListOptions{}
3540
var repoUnits []repo_model.RepoUnit
36-
err := db.Find(db.DefaultContext, &opts, &repoUnits)
41+
err = db.Find(db.DefaultContext, &opts, &repoUnits)
3742
assert.NoError(t, err)
38-
assert.EqualValues(t, 84, len(repoUnits))
43+
assert.EqualValues(t, repoUnitCount, len(repoUnits))
3944

4045
cnt, err := db.Count(db.DefaultContext, &opts, new(repo_model.RepoUnit))
4146
assert.NoError(t, err)
42-
assert.EqualValues(t, 84, cnt)
47+
assert.EqualValues(t, repoUnitCount, cnt)
4348

4449
repoUnits = make([]repo_model.RepoUnit, 0, 10)
4550
newCnt, err := db.FindAndCount(db.DefaultContext, &opts, &repoUnits)

models/dbfs/dbfs_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"code.gitea.io/gitea/models/db"
1313

1414
"github.com/stretchr/testify/assert"
15-
16-
_ "github.com/mattn/go-sqlite3"
1715
)
1816

1917
func changeDefaultFileBlockSize(n int64) (restore func()) {

0 commit comments

Comments
 (0)