Skip to content

Commit

Permalink
Merge branch 'main' into fix-empty-repo
Browse files Browse the repository at this point in the history
# Conflicts:
#	models/db/iterate_test.go
#	models/db/list_test.go
#	models/fixtures/repo_unit.yml
  • Loading branch information
wxiaoguang committed Apr 19, 2023
2 parents 2c86adf + 5fcf328 commit 2a03ba6
Show file tree
Hide file tree
Showing 143 changed files with 1,976 additions and 2,054 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
* text=auto eol=lf
*.tmpl linguist-language=Handlebars
/assets/*.json linguist-generated
/public/img/svg/*.svg linguist-generated
/public/vendor/** -text -eol linguist-vendored
/vendor/** -text -eol linguist-vendored
/web_src/fomantic/build/** linguist-generated
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ IMPORT := code.gitea.io/gitea

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

XGO_VERSION := go-1.20.x
Expand All @@ -41,7 +41,7 @@ DOCKER_IMAGE ?= gitea/gitea
DOCKER_TAG ?= latest
DOCKER_REF := $(DOCKER_IMAGE):$(DOCKER_TAG)

ifeq ($(HAS_GO), GO)
ifeq ($(HAS_GO), yes)
GOPATH ?= $(shell $(GO) env GOPATH)
export PATH := $(GOPATH)/bin:$(PATH)

Expand Down
56 changes: 56 additions & 0 deletions cmd/actions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package cmd

import (
"fmt"

"code.gitea.io/gitea/modules/private"
"code.gitea.io/gitea/modules/setting"

"github.com/urfave/cli"
)

var (
// CmdActions represents the available actions sub-commands.
CmdActions = cli.Command{
Name: "actions",
Usage: "",
Description: "Commands for managing Gitea Actions",
Subcommands: []cli.Command{
subcmdActionsGenRunnerToken,
},
}

subcmdActionsGenRunnerToken = cli.Command{
Name: "generate-runner-token",
Usage: "Generate a new token for a runner to use to register with the server",
Action: runGenerateActionsRunnerToken,
Aliases: []string{"grt"},
Flags: []cli.Flag{
cli.StringFlag{
Name: "scope, s",
Value: "",
Usage: "{owner}[/{repo}] - leave empty for a global runner",
},
},
}
)

func runGenerateActionsRunnerToken(c *cli.Context) error {
ctx, cancel := installSignals()
defer cancel()

setting.InitProviderFromExistingFile()
setting.LoadCommonSettings()

scope := c.String("scope")

respText, extra := private.GenerateActionsRunnerToken(ctx, scope)
if extra.HasError() {
return handleCliResponseExtra(extra)
}
_, _ = fmt.Printf("%s\n", respText)
return nil
}
27 changes: 16 additions & 11 deletions cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
var CmdConvert = cli.Command{
Name: "convert",
Usage: "Convert the database",
Description: "A command to convert an existing MySQL database from utf8 to utf8mb4",
Description: "A command to convert an existing MySQL database from utf8 to utf8mb4 or MSSQL database from varchar to nvarchar",
Action: runConvert,
}

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

if !setting.Database.Type.IsMySQL() {
fmt.Println("This command can only be used with a MySQL database")
return nil
switch {
case setting.Database.Type.IsMySQL():
if err := db.ConvertUtf8ToUtf8mb4(); err != nil {
log.Fatal("Failed to convert database from utf8 to utf8mb4: %v", err)
return err
}
fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")
case setting.Database.Type.IsMSSQL():
if err := db.ConvertVarcharToNVarchar(); err != nil {
log.Fatal("Failed to convert database from varchar to nvarchar: %v", err)
return err
}
fmt.Println("Converted successfully, please confirm your database's all columns character is NVARCHAR now")
default:
fmt.Println("This command can only be used with a MySQL or MSSQL database")
}

if err := db.ConvertUtf8ToUtf8mb4(); err != nil {
log.Fatal("Failed to convert database from utf8 to utf8mb4: %v", err)
return err
}

fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")

return nil
}
25 changes: 25 additions & 0 deletions docs/content/doc/administration/command-line.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,3 +551,28 @@ Restore-repo restore repository data from disk dir:
- `--owner_name lunny`: Restore destination owner name
- `--repo_name tango`: Restore destination repository name
- `--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.

### actions generate-runner-token

Generate a new token for a runner to use to register with the server

- Options:
- `--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

To register a global runner:

```
gitea actions generate-runner-token
```

To register a runner for a specific organization, in this case `org`:

```
gitea actions generate-runner-token -s org
```

To register a runner for a specific repo, in this case `username/test-repo`:

```
gitea actions generate-runner-token -s username/test-repo
```
4 changes: 2 additions & 2 deletions docs/content/doc/administration/https-support.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ PORT_TO_REDIRECT = 3080

[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)

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

```ini
[server]
Expand Down Expand Up @@ -92,7 +92,7 @@ ACME_EMAIL=email@example.com

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

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

- [nginx](https://nginx.org/en/docs/http/configuring_https_servers.html)
- [apache2/httpd](https://httpd.apache.org/docs/2.4/ssl/ssl_howto.html)
Expand Down
91 changes: 91 additions & 0 deletions docs/content/doc/installation/upgrade-from-gitea.zh-cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
date: "2021-09-02T16:00:00+08:00"
title: "从旧版 Gitea 升级"
slug: "upgrade-from-gitea"
weight: 100
toc: false
draft: false
menu:
sidebar:
parent: "installation"
name: "从旧版 Gitea 升级"
weight: 100
identifier: "upgrade-from-gitea"
---

# 从旧版 Gitea 升级

**目录**

{{< toc >}}

想要升级 Gitea,只需要下载新版,停止运行旧版,进行数据备份,然后运行新版就好。
每次 Gitea 实例启动时,它都会检查是否要进行数据库迁移。
如果需要进行数据库迁移,Gitea 会花一些时间完成升级然后继续服务。

## 为重大变更检查更新日志

为了让 Gitea 变得更好,进行重大变更是不可避免的,尤其是一些里程碑更新的发布。
在更新前,请 [在 Gitea 博客上阅读更新日志](https://blog.gitea.io/)
并检查重大变更是否会影响你的 Gitea 实例。

## 降级前的备份

Gitea 会保留首二位版本号相同的版本的兼容性 (`a.b.x` -> `a.b.y`),
这些版本拥有相同的数据库结构,可以自由升级或降级。
其他情况 (`a.b.?` -> `a.c.?`)下,
新版 Gitea 可能将会将数据库升级到与旧版数据库不同的结构。

举个例子:

| 当前 | 目标 | 结果 |
| --- | --- | --- |
| 1.4.0 | 1.4.1 ||
| 1.4.1 | 1.4.0 | ⚠️ 不建议,后果自负!尽管数据库结构可能不会变更,让它可以正常工作。我们强烈建议降级前进行完全的备份。 |
| 1.4.x | 1.5.y | ✅ 数据库会被自动升级。你可以直接从 1.4.x 升级到最新的 1.5.y。 |
| 1.5.y | 1.4.x | ❌ 数据库已被升级且不可被旧版 Gitea 利用,使用备份来进行降级。 |

**因为你不能基于升级后的数据库运行旧版 Gitea,所以你应该在数据库升级前完成数据备份。**

如果你在生产环境下使用 Gitea,你应该在升级前做好备份,哪怕只是小版本的补丁更新。

备份步骤:

* 停止 Gitea 实例
* 备份数据库
* 备份 Gitea 配置文件
* 备份 Gitea 在 `APP_DATA_PATH` 中的数据文件
* 备份 Gitea 的外部存储 (例如: S3/MinIO 或被使用的其他存储)

如果你在使用云服务或拥有快照功能的文件系统,
最好对 Gitea 的数据盘及相关资料存储进行一次快照。

## 从 Docker 升级

* `docker pull` 拉取 Gitea 的最新发布版。
* 停止运行中的实例,备份数据。
* 使用 `docker``docker-compose` 启动更新的 Gitea Docker 容器.

## 从包升级

* 停止运行中的实例,备份数据。
* 使用你的包管理器更新 Gitea 到最新版本。
* 启动 Gitea 实例。

## 从二进制升级

* 下载最新的 Gitea 二进制文件到临时文件夹中。
* 停止运行中的实例,备份数据。
* 将旧的 Gitea 二进制文件覆盖成新的。
* 启动 Gitea 实例。

在 Linux 系统上自动执行以上步骤的脚本可在 [Gitea 的 source tree 中找到 `contrib/upgrade.sh` 来获取](https://github.com/go-gitea/gitea/blob/main/contrib/upgrade.sh).

## 小心你的自定义模板

Gitea 的模板结构与变量可能会随着各个版本的发布发生变化,如果你使用了自定义模板,
你得注意你的模板与你使用的 Gitea 版本的兼容性。

如果自定义模板与 Gitea 版本不兼容,你可能会得到:
`50x` 服务器错误,页面元素丢失或故障,莫名其妙的页面布局,等等…
移除或更新不兼容的模板,Gitea Web 才可以正常工作。
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ arguments - which can alternatively be run by running the subcommand web.`
cmd.CmdDocs,
cmd.CmdDumpRepository,
cmd.CmdRestoreRepository,
cmd.CmdActions,
}
// Now adjust these commands to add our global configuration options

Expand Down
9 changes: 9 additions & 0 deletions models/activities/user_heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,12 @@ func getUserHeatmapData(user *user_model.User, team *organization.Team, doer *us
OrderBy("timestamp").
Find(&hdata)
}

// GetTotalContributionsInHeatmap returns the total number of contributions in a heatmap
func GetTotalContributionsInHeatmap(hdata []*UserHeatmapData) int64 {
var total int64
for _, v := range hdata {
total += v.Contributions
}
return total
}
27 changes: 27 additions & 0 deletions models/db/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,33 @@ func ConvertUtf8ToUtf8mb4() error {
return nil
}

// ConvertVarcharToNVarchar converts database and tables from varchar to nvarchar if it's mssql
func ConvertVarcharToNVarchar() error {
if x.Dialect().URI().DBType != schemas.MSSQL {
return nil
}

sess := x.NewSession()
defer sess.Close()
res, err := sess.QuerySliceString(`SELECT 'ALTER TABLE ' + OBJECT_NAME(SC.object_id) + ' MODIFY SC.name NVARCHAR(' + CONVERT(VARCHAR(5),SC.max_length) + ')'
FROM SYS.columns SC
JOIN SYS.types ST
ON SC.system_type_id = ST.system_type_id
AND SC.user_type_id = ST.user_type_id
WHERE ST.name ='varchar'`)
if err != nil {
return err
}
for _, row := range res {
if len(row) == 1 {
if _, err = sess.Exec(row[0]); err != nil {
return err
}
}
}
return err
}

// Cell2Int64 converts a xorm.Cell type to int64,
// and handles possible irregular cases.
func Cell2Int64(val xorm.Cell) int64 {
Expand Down
42 changes: 42 additions & 0 deletions models/fixtures/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,45 @@
is_prerelease: true
is_tag: false
created_unix: 946684800

- id: 6
repo_id: 57
publisher_id: 2
tag_name: "v1.0"
lower_tag_name: "v1.0"
target: "main"
title: "v1.0"
sha1: "a8a700e8c644c783ba2c6e742bb81bf91e244bff"
num_commits: 3
is_draft: false
is_prerelease: false
is_tag: false
created_unix: 946684801

- id: 7
repo_id: 57
publisher_id: 2
tag_name: "v1.1"
lower_tag_name: "v1.1"
target: "main"
title: "v1.1"
sha1: "cef06e48f2642cd0dc9597b4bea09f4b3f74aad6"
num_commits: 5
is_draft: false
is_prerelease: false
is_tag: false
created_unix: 946684802

- id: 8
repo_id: 57
publisher_id: 2
tag_name: "v2.0"
lower_tag_name: "v2.0"
target: "main"
title: "v2.0"
sha1: "7197b56fdc75b453f47c9110938cb46a303579fd"
num_commits: 6
is_draft: false
is_prerelease: false
is_tag: false
created_unix: 946684803
Loading

0 comments on commit 2a03ba6

Please sign in to comment.