Skip to content

Commit 2087b53

Browse files
Merge branch 'main' into admin-ip-info
2 parents f45ff5a + ae0af8e commit 2087b53

Some content is hidden

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

53 files changed

+1307
-899
lines changed

.github/workflows/release-nightly.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ jobs:
5959
aws s3 sync dist/release s3://${{ secrets.AWS_S3_BUCKET }}/gitea/${{ steps.clean_name.outputs.branch }} --no-progress
6060
nightly-docker-rootful:
6161
runs-on: namespace-profile-gitea-release-docker
62+
permissions:
63+
packages: write # to publish to ghcr.io
6264
steps:
6365
- uses: actions/checkout@v4
6466
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
@@ -85,6 +87,12 @@ jobs:
8587
with:
8688
username: ${{ secrets.DOCKERHUB_USERNAME }}
8789
password: ${{ secrets.DOCKERHUB_TOKEN }}
90+
- name: Login to GHCR using PAT
91+
uses: docker/login-action@v3
92+
with:
93+
registry: ghcr.io
94+
username: ${{ github.repository_owner }}
95+
password: ${{ secrets.GITHUB_TOKEN }}
8896
- name: fetch go modules
8997
run: make vendor
9098
- name: build rootful docker image
@@ -93,9 +101,13 @@ jobs:
93101
context: .
94102
platforms: linux/amd64,linux/arm64
95103
push: true
96-
tags: gitea/gitea:${{ steps.clean_name.outputs.branch }}
104+
tags: |-
105+
gitea/gitea:${{ steps.clean_name.outputs.branch }}
106+
ghcr.io/go-gitea/gitea:${{ steps.clean_name.outputs.branch }}
97107
nightly-docker-rootless:
98108
runs-on: namespace-profile-gitea-release-docker
109+
permissions:
110+
packages: write # to publish to ghcr.io
99111
steps:
100112
- uses: actions/checkout@v4
101113
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
@@ -122,6 +134,12 @@ jobs:
122134
with:
123135
username: ${{ secrets.DOCKERHUB_USERNAME }}
124136
password: ${{ secrets.DOCKERHUB_TOKEN }}
137+
- name: Login to GHCR using PAT
138+
uses: docker/login-action@v3
139+
with:
140+
registry: ghcr.io
141+
username: ${{ github.repository_owner }}
142+
password: ${{ secrets.GITHUB_TOKEN }}
125143
- name: fetch go modules
126144
run: make vendor
127145
- name: build rootless docker image
@@ -131,4 +149,6 @@ jobs:
131149
platforms: linux/amd64,linux/arm64
132150
push: true
133151
file: Dockerfile.rootless
134-
tags: gitea/gitea:${{ steps.clean_name.outputs.branch }}-rootless
152+
tags: |-
153+
gitea/gitea:${{ steps.clean_name.outputs.branch }}-rootless
154+
ghcr.io/go-gitea/gitea:${{ steps.clean_name.outputs.branch }}-rootless

.github/workflows/release-tag-rc.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ jobs:
6969
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
7070
docker-rootful:
7171
runs-on: namespace-profile-gitea-release-docker
72+
permissions:
73+
packages: write # to publish to ghcr.io
7274
steps:
7375
- uses: actions/checkout@v4
7476
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
@@ -79,7 +81,9 @@ jobs:
7981
- uses: docker/metadata-action@v5
8082
id: meta
8183
with:
82-
images: gitea/gitea
84+
images: |-
85+
gitea/gitea
86+
ghcr.io/go-gitea/gitea
8387
flavor: |
8488
latest=false
8589
# 1.2.3-rc0
@@ -90,6 +94,12 @@ jobs:
9094
with:
9195
username: ${{ secrets.DOCKERHUB_USERNAME }}
9296
password: ${{ secrets.DOCKERHUB_TOKEN }}
97+
- name: Login to GHCR using PAT
98+
uses: docker/login-action@v3
99+
with:
100+
registry: ghcr.io
101+
username: ${{ github.repository_owner }}
102+
password: ${{ secrets.GITHUB_TOKEN }}
93103
- name: build rootful docker image
94104
uses: docker/build-push-action@v5
95105
with:
@@ -100,6 +110,8 @@ jobs:
100110
labels: ${{ steps.meta.outputs.labels }}
101111
docker-rootless:
102112
runs-on: namespace-profile-gitea-release-docker
113+
permissions:
114+
packages: write # to publish to ghcr.io
103115
steps:
104116
- uses: actions/checkout@v4
105117
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
@@ -110,7 +122,9 @@ jobs:
110122
- uses: docker/metadata-action@v5
111123
id: meta
112124
with:
113-
images: gitea/gitea
125+
images: |-
126+
gitea/gitea
127+
ghcr.io/go-gitea/gitea
114128
# each tag below will have the suffix of -rootless
115129
flavor: |
116130
latest=false
@@ -123,6 +137,12 @@ jobs:
123137
with:
124138
username: ${{ secrets.DOCKERHUB_USERNAME }}
125139
password: ${{ secrets.DOCKERHUB_TOKEN }}
140+
- name: Login to GHCR using PAT
141+
uses: docker/login-action@v3
142+
with:
143+
registry: ghcr.io
144+
username: ${{ github.repository_owner }}
145+
password: ${{ secrets.GITHUB_TOKEN }}
126146
- name: build rootless docker image
127147
uses: docker/build-push-action@v5
128148
with:

.github/workflows/release-tag-version.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ concurrency:
1414
jobs:
1515
binary:
1616
runs-on: namespace-profile-gitea-release-binary
17+
permissions:
18+
packages: write # to publish to ghcr.io
1719
steps:
1820
- uses: actions/checkout@v4
1921
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
@@ -71,6 +73,8 @@ jobs:
7173
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
7274
docker-rootful:
7375
runs-on: namespace-profile-gitea-release-docker
76+
permissions:
77+
packages: write # to publish to ghcr.io
7478
steps:
7579
- uses: actions/checkout@v4
7680
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
@@ -81,7 +85,9 @@ jobs:
8185
- uses: docker/metadata-action@v5
8286
id: meta
8387
with:
84-
images: gitea/gitea
88+
images: |-
89+
gitea/gitea
90+
ghcr.io/go-gitea/gitea
8591
# this will generate tags in the following format:
8692
# latest
8793
# 1
@@ -96,6 +102,12 @@ jobs:
96102
with:
97103
username: ${{ secrets.DOCKERHUB_USERNAME }}
98104
password: ${{ secrets.DOCKERHUB_TOKEN }}
105+
- name: Login to GHCR using PAT
106+
uses: docker/login-action@v3
107+
with:
108+
registry: ghcr.io
109+
username: ${{ github.repository_owner }}
110+
password: ${{ secrets.GITHUB_TOKEN }}
99111
- name: build rootful docker image
100112
uses: docker/build-push-action@v5
101113
with:
@@ -116,7 +128,9 @@ jobs:
116128
- uses: docker/metadata-action@v5
117129
id: meta
118130
with:
119-
images: gitea/gitea
131+
images: |-
132+
gitea/gitea
133+
ghcr.io/go-gitea/gitea
120134
# each tag below will have the suffix of -rootless
121135
flavor: |
122136
suffix=-rootless,onlatest=true
@@ -134,6 +148,12 @@ jobs:
134148
with:
135149
username: ${{ secrets.DOCKERHUB_USERNAME }}
136150
password: ${{ secrets.DOCKERHUB_TOKEN }}
151+
- name: Login to GHCR using PAT
152+
uses: docker/login-action@v3
153+
with:
154+
registry: ghcr.io
155+
username: ${{ github.repository_owner }}
156+
password: ${{ secrets.GITHUB_TOKEN }}
137157
- name: build rootless docker image
138158
uses: docker/build-push-action@v5
139159
with:

modules/git/attribute.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

modules/git/attribute/attribute.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package attribute
5+
6+
import (
7+
"strings"
8+
9+
"code.gitea.io/gitea/modules/optional"
10+
)
11+
12+
type Attribute string
13+
14+
const (
15+
LinguistVendored = "linguist-vendored"
16+
LinguistGenerated = "linguist-generated"
17+
LinguistDocumentation = "linguist-documentation"
18+
LinguistDetectable = "linguist-detectable"
19+
LinguistLanguage = "linguist-language"
20+
GitlabLanguage = "gitlab-language"
21+
Lockable = "lockable"
22+
Filter = "filter"
23+
)
24+
25+
var LinguistAttributes = []string{
26+
LinguistVendored,
27+
LinguistGenerated,
28+
LinguistDocumentation,
29+
LinguistDetectable,
30+
LinguistLanguage,
31+
GitlabLanguage,
32+
}
33+
34+
func (a Attribute) IsUnspecified() bool {
35+
return a == "" || a == "unspecified"
36+
}
37+
38+
func (a Attribute) ToString() optional.Option[string] {
39+
if !a.IsUnspecified() {
40+
return optional.Some(string(a))
41+
}
42+
return optional.None[string]()
43+
}
44+
45+
// ToBool converts the attribute value to optional boolean: true if "set"/"true", false if "unset"/"false", none otherwise
46+
func (a Attribute) ToBool() optional.Option[bool] {
47+
switch a {
48+
case "set", "true":
49+
return optional.Some(true)
50+
case "unset", "false":
51+
return optional.Some(false)
52+
}
53+
return optional.None[bool]()
54+
}
55+
56+
type Attributes struct {
57+
m map[string]Attribute
58+
}
59+
60+
func NewAttributes() *Attributes {
61+
return &Attributes{m: make(map[string]Attribute)}
62+
}
63+
64+
func (attrs *Attributes) Get(name string) Attribute {
65+
if value, has := attrs.m[name]; has {
66+
return value
67+
}
68+
return ""
69+
}
70+
71+
func (attrs *Attributes) GetVendored() optional.Option[bool] {
72+
return attrs.Get(LinguistVendored).ToBool()
73+
}
74+
75+
func (attrs *Attributes) GetGenerated() optional.Option[bool] {
76+
return attrs.Get(LinguistGenerated).ToBool()
77+
}
78+
79+
func (attrs *Attributes) GetDocumentation() optional.Option[bool] {
80+
return attrs.Get(LinguistDocumentation).ToBool()
81+
}
82+
83+
func (attrs *Attributes) GetDetectable() optional.Option[bool] {
84+
return attrs.Get(LinguistDetectable).ToBool()
85+
}
86+
87+
func (attrs *Attributes) GetLinguistLanguage() optional.Option[string] {
88+
return attrs.Get(LinguistLanguage).ToString()
89+
}
90+
91+
func (attrs *Attributes) GetGitlabLanguage() optional.Option[string] {
92+
attrStr := attrs.Get(GitlabLanguage).ToString()
93+
if attrStr.Has() {
94+
raw := attrStr.Value()
95+
// gitlab-language may have additional parameters after the language
96+
// ignore them and just use the main language
97+
// https://docs.gitlab.com/ee/user/project/highlighting.html#override-syntax-highlighting-for-a-file-type
98+
if idx := strings.IndexByte(raw, '?'); idx >= 0 {
99+
return optional.Some(raw[:idx])
100+
}
101+
}
102+
return attrStr
103+
}
104+
105+
func (attrs *Attributes) GetLanguage() optional.Option[string] {
106+
// prefer linguist-language over gitlab-language
107+
// if linguist-language is not set, use gitlab-language
108+
// if both are not set, return none
109+
language := attrs.GetLinguistLanguage()
110+
if language.Value() == "" {
111+
language = attrs.GetGitlabLanguage()
112+
}
113+
return language
114+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package attribute
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func Test_Attribute(t *testing.T) {
13+
assert.Empty(t, Attribute("").ToString().Value())
14+
assert.Empty(t, Attribute("unspecified").ToString().Value())
15+
assert.Equal(t, "python", Attribute("python").ToString().Value())
16+
assert.Equal(t, "Java", Attribute("Java").ToString().Value())
17+
18+
attributes := Attributes{
19+
m: map[string]Attribute{
20+
LinguistGenerated: "true",
21+
LinguistDocumentation: "false",
22+
LinguistDetectable: "set",
23+
LinguistLanguage: "Python",
24+
GitlabLanguage: "Java",
25+
"filter": "unspecified",
26+
"test": "",
27+
},
28+
}
29+
30+
assert.Empty(t, attributes.Get("test").ToString().Value())
31+
assert.Empty(t, attributes.Get("filter").ToString().Value())
32+
assert.Equal(t, "Python", attributes.Get(LinguistLanguage).ToString().Value())
33+
assert.Equal(t, "Java", attributes.Get(GitlabLanguage).ToString().Value())
34+
assert.True(t, attributes.Get(LinguistGenerated).ToBool().Value())
35+
assert.False(t, attributes.Get(LinguistDocumentation).ToBool().Value())
36+
assert.True(t, attributes.Get(LinguistDetectable).ToBool().Value())
37+
}

0 commit comments

Comments
 (0)