Skip to content

Commit 0573139

Browse files
authored
Merge branch 'main' into fix-default-branch-label
2 parents eba9bd1 + 0989f43 commit 0573139

Some content is hidden

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

82 files changed

+1403
-373
lines changed

.github/actionlint.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
self-hosted-runner:
2+
labels:
3+
- actuated-4cpu-8gb
4+
- actuated-4cpu-16gb

.github/labeler.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ kind/build:
1919

2020
theme/package-registry:
2121
- "modules/packages/**"
22+
- "services/packages/**"
23+
- "routers/api/packages/**"
24+
- "routers/web/shared/packages/**"
2225

2326
kind/cli:
2427
- "cmd/**"

.github/workflows/release-nightly.yml

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ on:
44
push:
55
branches: [ main, release/v* ]
66

7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
9+
cancel-in-progress: true
10+
711
jobs:
812
nightly-binary:
9-
runs-on: ubuntu-latest
13+
runs-on: actuated-4cpu-8gb
1014
steps:
1115
- uses: actions/checkout@v3
1216
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
@@ -51,13 +55,17 @@ jobs:
5155
AWS_REGION: ${{ secrets.AWS_REGION }}
5256
SOURCE_DIR: dist/release
5357
DEST_DIR: gitea/${{ steps.clean_name.outputs.branch }}
54-
nightly-docker:
55-
runs-on: ubuntu-latest
58+
nightly-docker-rootful:
59+
runs-on: actuated-4cpu-16gb
5660
steps:
5761
- uses: actions/checkout@v3
5862
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
5963
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
6064
- run: git fetch --unshallow --quiet --tags --force
65+
- uses: actions/setup-go@v4
66+
with:
67+
go-version: "~1.21"
68+
check-latest: true
6169
- uses: docker/setup-qemu-action@v2
6270
- uses: docker/setup-buildx-action@v2
6371
- name: Get cleaned branch name
@@ -75,13 +83,45 @@ jobs:
7583
with:
7684
username: ${{ secrets.DOCKERHUB_USERNAME }}
7785
password: ${{ secrets.DOCKERHUB_TOKEN }}
86+
- name: fetch go modules
87+
run: make vendor
7888
- name: build rootful docker image
7989
uses: docker/build-push-action@v4
8090
with:
8191
context: .
8292
platforms: linux/amd64,linux/arm64
8393
push: true
8494
tags: gitea/gitea:${{ steps.clean_name.outputs.branch }}
95+
nightly-docker-rootless:
96+
runs-on: actuated-4cpu-8gb
97+
steps:
98+
- uses: actions/checkout@v3
99+
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
100+
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
101+
- run: git fetch --unshallow --quiet --tags --force
102+
- uses: actions/setup-go@v4
103+
with:
104+
go-version: "~1.21"
105+
check-latest: true
106+
- uses: docker/setup-qemu-action@v2
107+
- uses: docker/setup-buildx-action@v2
108+
- name: Get cleaned branch name
109+
id: clean_name
110+
run: |
111+
# if main then say nightly otherwise cleanup name
112+
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
113+
echo "branch=nightly" >> "$GITHUB_OUTPUT"
114+
exit 0
115+
fi
116+
REF_NAME=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\///' -e 's/release\/v//')
117+
echo "branch=${REF_NAME}-nightly" >> "$GITHUB_OUTPUT"
118+
- name: Login to Docker Hub
119+
uses: docker/login-action@v2
120+
with:
121+
username: ${{ secrets.DOCKERHUB_USERNAME }}
122+
password: ${{ secrets.DOCKERHUB_TOKEN }}
123+
- name: fetch go modules
124+
run: make vendor
85125
- name: build rootless docker image
86126
uses: docker/build-push-action@v4
87127
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ cpu.out
9595
/.go-licenses
9696

9797
# Snapcraft
98+
/gitea_a*.txt
9899
snap/.snapcraft/
99100
parts/
100101
stage/

docs/content/usage/packages/cargo.en-us.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ Add the following text to the configuration file located in the current users ho
5050
default = "gitea"
5151
5252
[registries.gitea]
53-
index = "https://gitea.example.com/{owner}/_cargo-index.git"
53+
index = "sparse+https://gitea.example.com/api/packages/{owner}/cargo/" # Sparse index
54+
# index = "https://gitea.example.com/{owner}/_cargo-index.git" # Git
5455
55-
[net]
56-
git-fetch-with-cli = true
56+
# [net]
57+
# git-fetch-with-cli = true
5758
```
5859

5960
| Parameter | Description |
@@ -72,6 +73,12 @@ token = "Bearer {token}"
7273
| --------- | ----------- |
7374
| `token` | Your [personal access token](development/api-usage.md#authentication) |
7475

76+
## Git vs Sparse
77+
78+
Currently, cargo supports two ways for fetching crates in a registry: Git index & sparse index.
79+
Sparse index is the newest method and offers better performance when updating crates compared to git.
80+
Since Rust 1.68, sparse is the default method for crates.io.
81+
7582
## Publish a package
7683

7784
Publish a package by running the following command in your project:

docs/content/usage/packages/cargo.zh-cn.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ Cargo 将可用软件包的信息存储在一个存储在 git 仓库中的软件
5050
default = "gitea"
5151
5252
[registries.gitea]
53-
index = "https://gitea.example.com/{owner}/_cargo-index.git"
53+
index = "sparse+https://gitea.example.com/api/packages/{owner}/cargo/" # Sparse index
54+
# index = "https://gitea.example.com/{owner}/_cargo-index.git" # Git
5455
5556
[net]
5657
git-fetch-with-cli = true

models/actions/runner.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ func (opts FindRunnerOptions) toOrder() string {
189189
return "last_online ASC"
190190
case "alphabetically":
191191
return "name ASC"
192+
case "reversealphabetically":
193+
return "name DESC"
194+
case "newest":
195+
return "id DESC"
196+
case "oldest":
197+
return "id ASC"
192198
}
193199
return "last_online DESC"
194200
}

models/repo/git.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
package repo
55

6-
import "code.gitea.io/gitea/models/db"
6+
import (
7+
"code.gitea.io/gitea/models/db"
8+
)
79

810
// MergeStyle represents the approach to merge commits into base branch.
911
type MergeStyle string

modules/indexer/code/git.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ func getRepoChanges(ctx context.Context, repo *repo_model.Repository, revision s
3030
return nil, err
3131
}
3232

33-
if len(status.CommitSha) == 0 {
33+
needGenesis := len(status.CommitSha) == 0
34+
if !needGenesis {
35+
hasAncestorCmd := git.NewCommand(ctx, "merge-base").AddDynamicArguments(repo.CodeIndexerStatus.CommitSha, revision)
36+
stdout, _, _ := hasAncestorCmd.RunStdString(&git.RunOpts{Dir: repo.RepoPath()})
37+
needGenesis = len(stdout) == 0
38+
}
39+
40+
if needGenesis {
3441
return genesisChanges(ctx, repo, revision)
3542
}
3643
return nonGenesisChanges(ctx, repo, revision)

modules/markup/orgmode/orgmode.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,31 @@ func (r *Writer) WriteRegularLink(l org.RegularLink) {
153153
link = []byte(util.URLJoin(r.URLPrefix, lnk))
154154
}
155155

156-
description := string(link)
157-
if l.Description != nil {
158-
description = r.WriteNodesAsString(l.Description...)
159-
}
156+
// Inspired by https://github.com/niklasfasching/go-org/blob/6eb20dbda93cb88c3503f7508dc78cbbc639378f/org/html_writer.go#L406-L427
160157
switch l.Kind() {
161158
case "image":
162-
imageSrc := getMediaURL(link)
163-
fmt.Fprintf(r, `<img src="%s" alt="%s" title="%s" />`, imageSrc, description, description)
159+
if l.Description == nil {
160+
imageSrc := getMediaURL(link)
161+
fmt.Fprintf(r, `<img src="%s" alt="%s" title="%s" />`, imageSrc, link, link)
162+
} else {
163+
description := strings.TrimPrefix(org.String(l.Description...), "file:")
164+
imageSrc := getMediaURL([]byte(description))
165+
fmt.Fprintf(r, `<a href="%s"><img src="%s" alt="%s" /></a>`, link, imageSrc, imageSrc)
166+
}
164167
case "video":
165-
videoSrc := getMediaURL(link)
166-
fmt.Fprintf(r, `<video src="%s" title="%s">%s</video>`, videoSrc, description, description)
168+
if l.Description == nil {
169+
imageSrc := getMediaURL(link)
170+
fmt.Fprintf(r, `<video src="%s" title="%s">%s</video>`, imageSrc, link, link)
171+
} else {
172+
description := strings.TrimPrefix(org.String(l.Description...), "file:")
173+
videoSrc := getMediaURL([]byte(description))
174+
fmt.Fprintf(r, `<a href="%s"><video src="%s" title="%s"></video></a>`, link, videoSrc, videoSrc)
175+
}
167176
default:
177+
description := string(link)
178+
if l.Description != nil {
179+
description = r.WriteNodesAsString(l.Description...)
180+
}
168181
fmt.Fprintf(r, `<a href="%s" title="%s">%s</a>`, link, description, description)
169182
}
170183
}

modules/markup/orgmode/orgmode_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestRender_StandardLinks(t *testing.T) {
4242
"<p><a href=\""+lnk+"\" title=\"UncycloPage\">UncycloPage</a></p>")
4343
}
4444

45-
func TestRender_Images(t *testing.T) {
45+
func TestRender_Media(t *testing.T) {
4646
setting.AppURL = AppURL
4747
setting.AppSubURL = AppSubURL
4848

@@ -60,6 +60,18 @@ func TestRender_Images(t *testing.T) {
6060

6161
test("[[file:"+url+"]]",
6262
"<p><img src=\""+result+"\" alt=\""+result+"\" title=\""+result+"\" /></p>")
63+
64+
// With description.
65+
test("[[https://example.com][https://example.com/example.svg]]",
66+
`<p><a href="https://example.com"><img src="https://example.com/example.svg" alt="https://example.com/example.svg" /></a></p>`)
67+
test("[[https://example.com][https://example.com/example.mp4]]",
68+
`<p><a href="https://example.com"><video src="https://example.com/example.mp4" title="https://example.com/example.mp4"></video></a></p>`)
69+
70+
// Without description.
71+
test("[[https://example.com/example.svg]]",
72+
`<p><img src="https://example.com/example.svg" alt="https://example.com/example.svg" title="https://example.com/example.svg" /></p>`)
73+
test("[[https://example.com/example.mp4]]",
74+
`<p><video src="https://example.com/example.mp4" title="https://example.com/example.mp4">https://example.com/example.mp4</video></p>`)
6375
}
6476

6577
func TestRender_Source(t *testing.T) {

modules/storage/minio.go

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ func convertMinioErr(err error) error {
7171
return err
7272
}
7373

74+
var getBucketVersioning = func(ctx context.Context, minioClient *minio.Client, bucket string) error {
75+
_, err := minioClient.GetBucketVersioning(ctx, bucket)
76+
return err
77+
}
78+
7479
// NewMinioStorage returns a minio storage
7580
func NewMinioStorage(ctx context.Context, cfg *setting.Storage) (ObjectStorage, error) {
7681
config := cfg.MinioConfig
@@ -90,6 +95,23 @@ func NewMinioStorage(ctx context.Context, cfg *setting.Storage) (ObjectStorage,
9095
return nil, convertMinioErr(err)
9196
}
9297

98+
// The GetBucketVersioning is only used for checking whether the Object Storage parameters are generally good. It doesn't need to succeed.
99+
// The assumption is that if the API returns the HTTP code 400, then the parameters could be incorrect.
100+
// Otherwise even if the request itself fails (403, 404, etc), the code should still continue because the parameters seem "good" enough.
101+
// Keep in mind that GetBucketVersioning requires "owner" to really succeed, so it can't be used to check the existence.
102+
// Not using "BucketExists (HeadBucket)" because it doesn't include detailed failure reasons.
103+
err = getBucketVersioning(ctx, minioClient, config.Bucket)
104+
if err != nil {
105+
errResp, ok := err.(minio.ErrorResponse)
106+
if !ok {
107+
return nil, err
108+
}
109+
if errResp.StatusCode == http.StatusBadRequest {
110+
log.Error("S3 storage connection failure at %s:%s with base path %s and region: %s", config.Endpoint, config.Bucket, config.Location, errResp.Message)
111+
return nil, err
112+
}
113+
}
114+
93115
// Check to see if we already own this bucket
94116
exists, err := minioClient.BucketExists(ctx, config.Bucket)
95117
if err != nil {
@@ -114,9 +136,18 @@ func NewMinioStorage(ctx context.Context, cfg *setting.Storage) (ObjectStorage,
114136
}
115137

116138
func (m *MinioStorage) buildMinioPath(p string) string {
117-
p = util.PathJoinRelX(m.basePath, p)
139+
p = strings.TrimPrefix(util.PathJoinRelX(m.basePath, p), "/") // object store doesn't use slash for root path
118140
if p == "." {
119-
p = "" // minio doesn't use dot as relative path
141+
p = "" // object store doesn't use dot as relative path
142+
}
143+
return p
144+
}
145+
146+
func (m *MinioStorage) buildMinioDirPrefix(p string) string {
147+
// ending slash is required for avoiding matching like "foo/" and "foobar/" with prefix "foo"
148+
p = m.buildMinioPath(p) + "/"
149+
if p == "/" {
150+
p = "" // object store doesn't use slash for root path
120151
}
121152
return p
122153
}
@@ -215,20 +246,11 @@ func (m *MinioStorage) URL(path, name string) (*url.URL, error) {
215246
// IterateObjects iterates across the objects in the miniostorage
216247
func (m *MinioStorage) IterateObjects(dirName string, fn func(path string, obj Object) error) error {
217248
opts := minio.GetObjectOptions{}
218-
lobjectCtx, cancel := context.WithCancel(m.ctx)
219-
defer cancel()
220-
221-
basePath := m.basePath
222-
if dirName != "" {
223-
// ending slash is required for avoiding matching like "foo/" and "foobar/" with prefix "foo"
224-
basePath = m.buildMinioPath(dirName) + "/"
225-
}
226-
227-
for mObjInfo := range m.client.ListObjects(lobjectCtx, m.bucket, minio.ListObjectsOptions{
228-
Prefix: basePath,
249+
for mObjInfo := range m.client.ListObjects(m.ctx, m.bucket, minio.ListObjectsOptions{
250+
Prefix: m.buildMinioDirPrefix(dirName),
229251
Recursive: true,
230252
}) {
231-
object, err := m.client.GetObject(lobjectCtx, m.bucket, mObjInfo.Key, opts)
253+
object, err := m.client.GetObject(m.ctx, m.bucket, mObjInfo.Key, opts)
232254
if err != nil {
233255
return convertMinioErr(err)
234256
}

0 commit comments

Comments
 (0)