Skip to content

Commit bab3026

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: (25 commits) zh-cn support on doc pages (go-gitea#24166) [skip ci] Updated translations via Crowdin Use double quotes consistently in en-US (go-gitea#24141) Use correct locale key for forks page (go-gitea#24172) Improve Wiki TOC (go-gitea#24137) Localize activity heatmap (except tooltip) (go-gitea#24131) Support triggering workflows by wiki related events (go-gitea#24119) add CLI command to register runner tokens (go-gitea#23762) Add new user types `reserved`, `bot`, and `remote` (go-gitea#24026) Fix Org edit page bugs: renaming detection, maxlength (go-gitea#24161) Make HAS_GO a simply expanded variable (go-gitea#24169) Support converting varchar to nvarchar for mssql database (go-gitea#24105) Fix math and mermaid rendering bugs (go-gitea#24049) Refactor locale number (go-gitea#24134) [skip ci] Updated translations via Crowdin Use 1.18's aria role for dropdown menus (go-gitea#24144) Set EasyMDE heading font-size to the same size as the resulting markdown (go-gitea#24151) Fix 2-dot direct compare to use the right base commit (go-gitea#24133) Add migration to fix external unit access mode of owner/admin team (go-gitea#24117) Remove untranslatable `on_date` key (go-gitea#24106) ...
2 parents 9ecde7f + f82ee30 commit bab3026

File tree

132 files changed

+1172
-610
lines changed

Some content is hidden

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

132 files changed

+1172
-610
lines changed

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/issues/assignees.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ func IsUserAssignedToIssue(ctx context.Context, issue *Issue, user *user_model.U
6363
}
6464

6565
// ToggleIssueAssignee changes a user between assigned and not assigned for this issue, and make issue comment for it.
66-
func ToggleIssueAssignee(issue *Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *Comment, err error) {
67-
ctx, committer, err := db.TxContext(db.DefaultContext)
66+
func ToggleIssueAssignee(ctx context.Context, issue *Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *Comment, err error) {
67+
ctx, committer, err := db.TxContext(ctx)
6868
if err != nil {
6969
return false, nil, err
7070
}

models/issues/assignees_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ func TestUpdateAssignee(t *testing.T) {
2424
// Assign multiple users
2525
user2, err := user_model.GetUserByID(db.DefaultContext, 2)
2626
assert.NoError(t, err)
27-
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user2.ID)
27+
_, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user2.ID)
2828
assert.NoError(t, err)
2929

3030
user3, err := user_model.GetUserByID(db.DefaultContext, 3)
3131
assert.NoError(t, err)
32-
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user3.ID)
32+
_, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user3.ID)
3333
assert.NoError(t, err)
3434

3535
user1, err := user_model.GetUserByID(db.DefaultContext, 1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
3636
assert.NoError(t, err)
37-
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user1.ID)
37+
_, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user1.ID)
3838
assert.NoError(t, err)
3939

4040
// Check if he got removed

models/issues/issue.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,8 @@ func ChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.User,
743743
}
744744

745745
// ChangeIssueTitle changes the title of this issue, as the given user.
746-
func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err error) {
747-
ctx, committer, err := db.TxContext(db.DefaultContext)
746+
func ChangeIssueTitle(ctx context.Context, issue *Issue, doer *user_model.User, oldTitle string) (err error) {
747+
ctx, committer, err := db.TxContext(ctx)
748748
if err != nil {
749749
return err
750750
}

models/issues/issue_xref_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestXRef_NeuterCrossReferences(t *testing.T) {
8383

8484
d := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
8585
i.Title = "title2, no mentions"
86-
assert.NoError(t, issues_model.ChangeIssueTitle(i, d, title))
86+
assert.NoError(t, issues_model.ChangeIssueTitle(db.DefaultContext, i, d, title))
8787

8888
ref = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: itarget.ID, RefIssueID: i.ID, RefCommentID: 0})
8989
assert.Equal(t, issues_model.CommentTypeIssueRef, ref.Type)

models/migrations/migrations.go

+2
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ var migrations = []Migration{
483483
NewMigration("Fix incorrect owner team unit access mode", v1_20.FixIncorrectOwnerTeamUnitAccessMode),
484484
// v252 -> v253
485485
NewMigration("Fix incorrect admin team unit access mode", v1_20.FixIncorrectAdminTeamUnitAccessMode),
486+
// v253 -> v254
487+
NewMigration("Fix ExternalTracker and ExternalWiki accessMode in owner and admin team", v1_20.FixExternalTrackerAndExternalWikiAccessModeInOwnerAndAdminTeam),
486488
}
487489

488490
// GetCurrentDBVersion returns the current db version

0 commit comments

Comments
 (0)