Skip to content

Commit 67288da

Browse files
committed
Merge branch 'main' into support-actions-concurrency
2 parents 0ed98a5 + d28a484 commit 67288da

File tree

210 files changed

+1501
-1007
lines changed

Some content is hidden

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

210 files changed

+1501
-1007
lines changed

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ linters:
1919
- revive
2020
- staticcheck
2121
- stylecheck
22+
- tenv
23+
- testifylint
2224
- typecheck
2325
- unconvert
2426
- unused
@@ -34,6 +36,10 @@ output:
3436
show-stats: true
3537

3638
linters-settings:
39+
testifylint:
40+
disable:
41+
- go-require
42+
- require-error
3743
stylecheck:
3844
checks: ["all", "-ST1005", "-ST1003"]
3945
nakedret:

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ Wim <wim@42.be> (@42wim)
4646
Jason Song <i@wolfogre.com> (@wolfogre)
4747
Yarden Shoham <git@yardenshoham.com> (@yardenshoham)
4848
Yu Tian <zettat123@gmail.com> (@Zettat123)
49-
Eddie Yang <576951401@qq.com> (@yp05327)
5049
Dong Ge <gedong_1994@163.com> (@sillyguodong)
5150
Xinyi Gong <hestergong@gmail.com> (@HesterG)
5251
wxiaoguang <wxiaoguang@gmail.com> (@wxiaoguang)

Makefile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ XGO_VERSION := go-1.23.x
2828
AIR_PACKAGE ?= github.com/air-verse/air@v1
2929
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.7.0
3030
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.7.0
31-
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3
31+
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2
3232
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11
3333
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.5.1
3434
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0
@@ -377,12 +377,12 @@ lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig
377377
.PHONY: lint-js
378378
lint-js: node_modules
379379
npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES)
380-
# npx vue-tsc
380+
npx vue-tsc
381381

382382
.PHONY: lint-js-fix
383383
lint-js-fix: node_modules
384384
npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES) --fix
385-
# npx vue-tsc
385+
npx vue-tsc
386386

387387
.PHONY: lint-css
388388
lint-css: node_modules
@@ -451,10 +451,6 @@ lint-templates: .venv node_modules
451451
lint-yaml: .venv
452452
@poetry run yamllint .
453453

454-
.PHONY: tsc
455-
tsc:
456-
npx vue-tsc
457-
458454
.PHONY: watch
459455
watch:
460456
@bash tools/watch.sh

custom/conf/app.example.ini

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,9 +1040,13 @@ LEVEL = Info
10401040
;; Don't allow download source archive files from UI
10411041
;DISABLE_DOWNLOAD_SOURCE_ARCHIVES = false
10421042

1043-
;; Allow fork repositories without maximum number limit
1043+
;; Allow to fork repositories without maximum number limit
10441044
;ALLOW_FORK_WITHOUT_MAXIMUM_LIMIT = true
10451045

1046+
;; Allow to fork repositories into the same owner (user or organization)
1047+
;; This feature is experimental, not fully tested, and may be changed in the future
1048+
;ALLOW_FORK_INTO_SAME_OWNER = false
1049+
10461050
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10471051
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10481052
;[repository.editor]

models/actions/run_job.go

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func UpdateRunJob(ctx context.Context, job *ActionRunJob, cond builder.Cond, col
143143
if err != nil {
144144
return 0, err
145145
}
146-
run.Status = aggregateJobStatus(jobs)
146+
run.Status = AggregateJobStatus(jobs)
147147
if run.Started.IsZero() && run.Status.IsRunning() {
148148
run.Started = timeutil.TimeStampNow()
149149
}
@@ -158,29 +158,34 @@ func UpdateRunJob(ctx context.Context, job *ActionRunJob, cond builder.Cond, col
158158
return affected, nil
159159
}
160160

161-
func aggregateJobStatus(jobs []*ActionRunJob) Status {
162-
allDone := true
163-
allWaiting := true
164-
hasFailure := false
161+
func AggregateJobStatus(jobs []*ActionRunJob) Status {
162+
allSuccessOrSkipped := true
163+
var hasFailure, hasCancelled, hasSkipped, hasWaiting, hasRunning, hasBlocked bool
165164
for _, job := range jobs {
166-
if !job.Status.IsDone() {
167-
allDone = false
168-
}
169-
if job.Status != StatusWaiting && !job.Status.IsDone() {
170-
allWaiting = false
171-
}
172-
if job.Status == StatusFailure || job.Status == StatusCancelled {
173-
hasFailure = true
174-
}
165+
allSuccessOrSkipped = allSuccessOrSkipped && (job.Status == StatusSuccess || job.Status == StatusSkipped)
166+
hasFailure = hasFailure || job.Status == StatusFailure
167+
hasCancelled = hasCancelled || job.Status == StatusCancelled
168+
hasSkipped = hasSkipped || job.Status == StatusSkipped
169+
hasWaiting = hasWaiting || job.Status == StatusWaiting
170+
hasRunning = hasRunning || job.Status == StatusRunning
171+
hasBlocked = hasBlocked || job.Status == StatusBlocked
175172
}
176-
if allDone {
177-
if hasFailure {
178-
return StatusFailure
179-
}
173+
switch {
174+
case allSuccessOrSkipped:
180175
return StatusSuccess
181-
}
182-
if allWaiting {
176+
case hasFailure:
177+
return StatusFailure
178+
case hasRunning:
179+
return StatusRunning
180+
case hasWaiting:
183181
return StatusWaiting
182+
case hasBlocked:
183+
return StatusBlocked
184+
case hasCancelled:
185+
return StatusCancelled
186+
case hasSkipped:
187+
return StatusSkipped
188+
default:
189+
return StatusUnknown // it shouldn't happen
184190
}
185-
return StatusRunning
186191
}

models/actions/run_job_status_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package actions
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestAggregateJobStatus(t *testing.T) {
13+
testStatuses := func(expected Status, statuses []Status) {
14+
var jobs []*ActionRunJob
15+
for _, v := range statuses {
16+
jobs = append(jobs, &ActionRunJob{Status: v})
17+
}
18+
actual := AggregateJobStatus(jobs)
19+
if !assert.Equal(t, expected, actual) {
20+
var statusStrings []string
21+
for _, s := range statuses {
22+
statusStrings = append(statusStrings, s.String())
23+
}
24+
t.Errorf("AggregateJobStatus(%v) = %v, want %v", statusStrings, statusNames[actual], statusNames[expected])
25+
}
26+
}
27+
28+
cases := []struct {
29+
statuses []Status
30+
expected Status
31+
}{
32+
// success with other status
33+
{[]Status{StatusSuccess}, StatusSuccess},
34+
{[]Status{StatusSuccess, StatusSkipped}, StatusSuccess}, // skipped doesn't affect success
35+
{[]Status{StatusSuccess, StatusFailure}, StatusFailure},
36+
{[]Status{StatusSuccess, StatusCancelled}, StatusCancelled},
37+
{[]Status{StatusSuccess, StatusWaiting}, StatusWaiting},
38+
{[]Status{StatusSuccess, StatusRunning}, StatusRunning},
39+
{[]Status{StatusSuccess, StatusBlocked}, StatusBlocked},
40+
41+
// failure with other status, fail fast
42+
// Should "running" win? Maybe no: old code does make "running" win, but GitHub does fail fast.
43+
{[]Status{StatusFailure}, StatusFailure},
44+
{[]Status{StatusFailure, StatusSuccess}, StatusFailure},
45+
{[]Status{StatusFailure, StatusSkipped}, StatusFailure},
46+
{[]Status{StatusFailure, StatusCancelled}, StatusFailure},
47+
{[]Status{StatusFailure, StatusWaiting}, StatusFailure},
48+
{[]Status{StatusFailure, StatusRunning}, StatusFailure},
49+
{[]Status{StatusFailure, StatusBlocked}, StatusFailure},
50+
51+
// skipped with other status
52+
{[]Status{StatusSkipped}, StatusSuccess},
53+
{[]Status{StatusSkipped, StatusSuccess}, StatusSuccess},
54+
{[]Status{StatusSkipped, StatusFailure}, StatusFailure},
55+
{[]Status{StatusSkipped, StatusCancelled}, StatusCancelled},
56+
{[]Status{StatusSkipped, StatusWaiting}, StatusWaiting},
57+
{[]Status{StatusSkipped, StatusRunning}, StatusRunning},
58+
{[]Status{StatusSkipped, StatusBlocked}, StatusBlocked},
59+
}
60+
61+
for _, c := range cases {
62+
testStatuses(c.expected, c.statuses)
63+
}
64+
}

models/actions/runner_token_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestGetLatestRunnerToken(t *testing.T) {
1717
token := unittest.AssertExistsAndLoadBean(t, &ActionRunnerToken{ID: 3})
1818
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
1919
assert.NoError(t, err)
20-
assert.EqualValues(t, token, expectedToken)
20+
assert.EqualValues(t, expectedToken, token)
2121
}
2222

2323
func TestNewRunnerToken(t *testing.T) {
@@ -26,7 +26,7 @@ func TestNewRunnerToken(t *testing.T) {
2626
assert.NoError(t, err)
2727
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
2828
assert.NoError(t, err)
29-
assert.EqualValues(t, token, expectedToken)
29+
assert.EqualValues(t, expectedToken, token)
3030
}
3131

3232
func TestUpdateRunnerToken(t *testing.T) {
@@ -36,5 +36,5 @@ func TestUpdateRunnerToken(t *testing.T) {
3636
assert.NoError(t, UpdateRunnerToken(db.DefaultContext, token))
3737
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
3838
assert.NoError(t, err)
39-
assert.EqualValues(t, token, expectedToken)
39+
assert.EqualValues(t, expectedToken, token)
4040
}

models/activities/user_heatmap_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package activities_test
55

66
import (
7-
"fmt"
87
"testing"
98
"time"
109

@@ -91,11 +90,11 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
9190
assert.NoError(t, err)
9291
assert.Len(t, actions, contributions, "invalid action count: did the test data became too old?")
9392
assert.Equal(t, count, int64(contributions))
94-
assert.Equal(t, tc.CountResult, contributions, fmt.Sprintf("testcase '%s'", tc.desc))
93+
assert.Equal(t, tc.CountResult, contributions, "testcase '%s'", tc.desc)
9594

9695
// Test JSON rendering
9796
jsonData, err := json.Marshal(heatmap)
9897
assert.NoError(t, err)
99-
assert.Equal(t, tc.JSONResult, string(jsonData))
98+
assert.JSONEq(t, tc.JSONResult, string(jsonData))
10099
}
101100
}

models/auth/oauth2_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestOAuth2Application_GenerateClientSecret(t *testing.T) {
1818
app := unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: 1})
1919
secret, err := app.GenerateClientSecret(db.DefaultContext)
2020
assert.NoError(t, err)
21-
assert.True(t, len(secret) > 0)
21+
assert.NotEmpty(t, secret)
2222
unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: 1, ClientSecret: app.ClientSecret})
2323
}
2424

@@ -165,7 +165,7 @@ func TestOAuth2Grant_GenerateNewAuthorizationCode(t *testing.T) {
165165
code, err := grant.GenerateNewAuthorizationCode(db.DefaultContext, "https://example2.com/callback", "CjvyTLSdR47G5zYenDA-eDWW4lRrO8yvjcWwbD_deOg", "S256")
166166
assert.NoError(t, err)
167167
assert.NotNil(t, code)
168-
assert.True(t, len(code.Code) > 32) // secret length > 32
168+
assert.Greater(t, len(code.Code), 32) // secret length > 32
169169
}
170170

171171
func TestOAuth2Grant_TableName(t *testing.T) {

models/db/iterate_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ func TestIterate(t *testing.T) {
3838
if !has {
3939
return db.ErrNotExist{Resource: "repo_unit", ID: repoUnit.ID}
4040
}
41-
assert.EqualValues(t, repoUnit.RepoID, repoUnit.RepoID)
42-
assert.EqualValues(t, repoUnit.CreatedUnix, repoUnit.CreatedUnix)
4341
return nil
4442
})
4543
assert.NoError(t, err)

models/fixtures/action_run.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,41 @@
3636
updated: 1683636626
3737
need_approval: 0
3838
approved_by: 0
39+
-
40+
id: 793
41+
title: "job output"
42+
repo_id: 4
43+
owner_id: 1
44+
workflow_id: "test.yaml"
45+
index: 189
46+
trigger_user_id: 1
47+
ref: "refs/heads/master"
48+
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
49+
event: "push"
50+
is_fork_pull_request: 0
51+
status: 1
52+
started: 1683636528
53+
stopped: 1683636626
54+
created: 1683636108
55+
updated: 1683636626
56+
need_approval: 0
57+
approved_by: 0
58+
-
59+
id: 794
60+
title: "job output"
61+
repo_id: 4
62+
owner_id: 1
63+
workflow_id: "test.yaml"
64+
index: 190
65+
trigger_user_id: 1
66+
ref: "refs/heads/test"
67+
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
68+
event: "push"
69+
is_fork_pull_request: 0
70+
status: 1
71+
started: 1683636528
72+
stopped: 1683636626
73+
created: 1683636108
74+
updated: 1683636626
75+
need_approval: 0
76+
approved_by: 0

models/fixtures/action_run_job.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,46 @@
2626
status: 1
2727
started: 1683636528
2828
stopped: 1683636626
29+
-
30+
id: 194
31+
run_id: 793
32+
repo_id: 4
33+
owner_id: 1
34+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
35+
is_fork_pull_request: 0
36+
name: job1 (1)
37+
attempt: 1
38+
job_id: job1
39+
task_id: 49
40+
status: 1
41+
started: 1683636528
42+
stopped: 1683636626
43+
-
44+
id: 195
45+
run_id: 793
46+
repo_id: 4
47+
owner_id: 1
48+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
49+
is_fork_pull_request: 0
50+
name: job1 (2)
51+
attempt: 1
52+
job_id: job1
53+
task_id: 50
54+
status: 1
55+
started: 1683636528
56+
stopped: 1683636626
57+
-
58+
id: 196
59+
run_id: 793
60+
repo_id: 4
61+
owner_id: 1
62+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
63+
is_fork_pull_request: 0
64+
name: job2
65+
attempt: 1
66+
job_id: job2
67+
needs: [job1]
68+
task_id: 51
69+
status: 5
70+
started: 1683636528
71+
stopped: 1683636626

0 commit comments

Comments
 (0)