Skip to content

Commit 90d7d0f

Browse files
authored
Merge branch 'main' into lunny/add_webhook_test_compare_url
2 parents 54cf2d2 + 9d4ebc1 commit 90d7d0f

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

+1817
-470
lines changed

.github/workflows/pull-db-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
services:
1919
pgsql:
20-
image: postgres:12
20+
image: postgres:14
2121
env:
2222
POSTGRES_DB: test
2323
POSTGRES_PASSWORD: postgres

cmd/dump_repo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ wiki, issues, labels, releases, release_assets, milestones, pull_requests, comme
8080
}
8181

8282
func runDumpRepository(ctx *cli.Context) error {
83+
setupConsoleLogger(log.INFO, log.CanColorStderr, os.Stderr)
84+
85+
setting.DisableLoggerInit()
86+
setting.LoadSettings() // cannot access skip_tls_verify settings otherwise
87+
8388
stdCtx, cancel := installSignals()
8489
defer cancel()
8590

cmd/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
const (
27-
hookBatchSize = 30
27+
hookBatchSize = 500
2828
)
2929

3030
var (

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ replace github.com/hashicorp/go-version => github.com/6543/go-version v1.3.1
317317

318318
replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0
319319

320-
replace github.com/nektos/act => gitea.com/gitea/act v0.261.4
320+
replace github.com/nektos/act => gitea.com/gitea/act v0.261.6
321321

322322
// TODO: the only difference is in `PutObject`: the fork doesn't use `NewVerifyingReader(r, sha256.New(), oid, expectedSize)`, need to figure out why
323323
replace github.com/charmbracelet/git-lfs-transfer => gitea.com/gitea/git-lfs-transfer v0.2.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
1414
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
1515
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
1616
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
17-
gitea.com/gitea/act v0.261.4 h1:Tf9eLlvsYFtKcpuxlMvf9yT3g4Hshb2Beqw6C1STuH8=
18-
gitea.com/gitea/act v0.261.4/go.mod h1:Pg5C9kQY1CEA3QjthjhlrqOC/QOT5NyWNjOjRHw23Ok=
17+
gitea.com/gitea/act v0.261.6 h1:CjZwKOyejonNFDmsXOw3wGm5Vet573hHM6VMLsxtvPY=
18+
gitea.com/gitea/act v0.261.6/go.mod h1:Pg5C9kQY1CEA3QjthjhlrqOC/QOT5NyWNjOjRHw23Ok=
1919
gitea.com/gitea/git-lfs-transfer v0.2.0 h1:baHaNoBSRaeq/xKayEXwiDQtlIjps4Ac/Ll4KqLMB40=
2020
gitea.com/gitea/git-lfs-transfer v0.2.0/go.mod h1:UrXUCm3xLQkq15fu7qlXHUMlrhdlXHoi13KH2Dfiits=
2121
gitea.com/gitea/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:BAFmdZpRW7zMQZQDClaCWobRj9uL1MR3MzpCVJvc5s4=

models/actions/run.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
user_model "code.gitea.io/gitea/models/user"
1717
"code.gitea.io/gitea/modules/git"
1818
"code.gitea.io/gitea/modules/json"
19+
"code.gitea.io/gitea/modules/setting"
1920
api "code.gitea.io/gitea/modules/structs"
2021
"code.gitea.io/gitea/modules/timeutil"
2122
"code.gitea.io/gitea/modules/util"
@@ -343,13 +344,13 @@ func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWork
343344
return committer.Commit()
344345
}
345346

346-
func GetRunByID(ctx context.Context, id int64) (*ActionRun, error) {
347+
func GetRunByRepoAndID(ctx context.Context, repoID, runID int64) (*ActionRun, error) {
347348
var run ActionRun
348-
has, err := db.GetEngine(ctx).Where("id=?", id).Get(&run)
349+
has, err := db.GetEngine(ctx).Where("id=? AND repo_id=?", runID, repoID).Get(&run)
349350
if err != nil {
350351
return nil, err
351352
} else if !has {
352-
return nil, fmt.Errorf("run with id %d: %w", id, util.ErrNotExist)
353+
return nil, fmt.Errorf("run with id %d: %w", runID, util.ErrNotExist)
353354
}
354355

355356
return &run, nil
@@ -420,17 +421,10 @@ func UpdateRun(ctx context.Context, run *ActionRun, cols ...string) error {
420421

421422
if run.Status != 0 || slices.Contains(cols, "status") {
422423
if run.RepoID == 0 {
423-
run, err = GetRunByID(ctx, run.ID)
424-
if err != nil {
425-
return err
426-
}
424+
setting.PanicInDevOrTesting("RepoID should not be 0")
427425
}
428-
if run.Repo == nil {
429-
repo, err := repo_model.GetRepositoryByID(ctx, run.RepoID)
430-
if err != nil {
431-
return err
432-
}
433-
run.Repo = repo
426+
if err = run.LoadRepo(ctx); err != nil {
427+
return err
434428
}
435429
if err := updateRepoRunsNumbers(ctx, run.Repo); err != nil {
436430
return err

models/actions/run_job.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (job *ActionRunJob) Duration() time.Duration {
5151

5252
func (job *ActionRunJob) LoadRun(ctx context.Context) error {
5353
if job.Run == nil {
54-
run, err := GetRunByID(ctx, job.RunID)
54+
run, err := GetRunByRepoAndID(ctx, job.RepoID, job.RunID)
5555
if err != nil {
5656
return err
5757
}
@@ -142,7 +142,7 @@ func UpdateRunJob(ctx context.Context, job *ActionRunJob, cond builder.Cond, col
142142
{
143143
// Other goroutines may aggregate the status of the run and update it too.
144144
// So we need load the run and its jobs before updating the run.
145-
run, err := GetRunByID(ctx, job.RunID)
145+
run, err := GetRunByRepoAndID(ctx, job.RepoID, job.RunID)
146146
if err != nil {
147147
return 0, err
148148
}

models/actions/runner.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package actions
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910
"strings"
1011
"time"
@@ -298,6 +299,23 @@ func DeleteRunner(ctx context.Context, id int64) error {
298299
return err
299300
}
300301

302+
// DeleteEphemeralRunner deletes a ephemeral runner by given ID.
303+
func DeleteEphemeralRunner(ctx context.Context, id int64) error {
304+
runner, err := GetRunnerByID(ctx, id)
305+
if err != nil {
306+
if errors.Is(err, util.ErrNotExist) {
307+
return nil
308+
}
309+
return err
310+
}
311+
if !runner.Ephemeral {
312+
return nil
313+
}
314+
315+
_, err = db.DeleteByID[ActionRunner](ctx, id)
316+
return err
317+
}
318+
301319
// CreateRunner creates new runner.
302320
func CreateRunner(ctx context.Context, t *ActionRunner) error {
303321
if t.OwnerID != 0 && t.RepoID != 0 {

models/actions/task.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ func UpdateTask(ctx context.Context, task *ActionTask, cols ...string) error {
336336
sess.Cols(cols...)
337337
}
338338
_, err := sess.Update(task)
339+
340+
// Automatically delete the ephemeral runner if the task is done
341+
if err == nil && task.Status.IsDone() && util.SliceContainsString(cols, "status") {
342+
return DeleteEphemeralRunner(ctx, task.RunnerID)
343+
}
339344
return err
340345
}
341346

models/actions/task_list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func (tasks TaskList) LoadAttributes(ctx context.Context) error {
4848
type FindTaskOptions struct {
4949
db.ListOptions
5050
RepoID int64
51+
JobID int64
5152
OwnerID int64
5253
CommitSHA string
5354
Status Status
@@ -61,6 +62,9 @@ func (opts FindTaskOptions) ToConds() builder.Cond {
6162
if opts.RepoID > 0 {
6263
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
6364
}
65+
if opts.JobID > 0 {
66+
cond = cond.And(builder.Eq{"job_id": opts.JobID})
67+
}
6468
if opts.OwnerID > 0 {
6569
cond = cond.And(builder.Eq{"owner_id": opts.OwnerID})
6670
}

models/actions/utils.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,22 @@ func calculateDuration(started, stopped timeutil.TimeStamp, status Status) time.
8282
}
8383
return timeSince(s).Truncate(time.Second)
8484
}
85+
86+
// best effort function to convert an action schedule to action run, to be used in GenerateGiteaContext
87+
func (s *ActionSchedule) ToActionRun() *ActionRun {
88+
return &ActionRun{
89+
Title: s.Title,
90+
RepoID: s.RepoID,
91+
Repo: s.Repo,
92+
OwnerID: s.OwnerID,
93+
WorkflowID: s.WorkflowID,
94+
TriggerUserID: s.TriggerUserID,
95+
TriggerUser: s.TriggerUser,
96+
Ref: s.Ref,
97+
CommitSHA: s.CommitSHA,
98+
Event: s.Event,
99+
EventPayload: s.EventPayload,
100+
Created: s.Created,
101+
Updated: s.Updated,
102+
}
103+
}

models/activities/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ func ActivityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder.
530530

531531
if opts.RequestedTeam != nil {
532532
env := repo_model.AccessibleTeamReposEnv(organization.OrgFromUser(opts.RequestedUser), opts.RequestedTeam)
533-
teamRepoIDs, err := env.RepoIDs(ctx, 1, opts.RequestedUser.NumRepos)
533+
teamRepoIDs, err := env.RepoIDs(ctx)
534534
if err != nil {
535535
return nil, fmt.Errorf("GetTeamRepositories: %w", err)
536536
}

models/fixtures/action_artifact.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,39 @@
105105
created_unix: 1730330775
106106
updated_unix: 1730330775
107107
expired_unix: 1738106775
108+
109+
-
110+
id: 24
111+
run_id: 795
112+
runner_id: 1
113+
repo_id: 2
114+
owner_id: 2
115+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
116+
storage_path: "27/5/1730330775594233150.chunk"
117+
file_size: 1024
118+
file_compressed_size: 1024
119+
content_encoding: "application/zip"
120+
artifact_path: "artifact-795-1.zip"
121+
artifact_name: "artifact-795-1"
122+
status: 2
123+
created_unix: 1730330775
124+
updated_unix: 1730330775
125+
expired_unix: 1738106775
126+
127+
-
128+
id: 25
129+
run_id: 795
130+
runner_id: 1
131+
repo_id: 2
132+
owner_id: 2
133+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
134+
storage_path: "27/5/1730330775594233150.chunk"
135+
file_size: 1024
136+
file_compressed_size: 1024
137+
content_encoding: "application/zip"
138+
artifact_path: "artifact-795-2.zip"
139+
artifact_name: "artifact-795-2"
140+
status: 2
141+
created_unix: 1730330775
142+
updated_unix: 1730330775
143+
expired_unix: 1738106775

models/fixtures/action_run.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
4949
event: "push"
5050
is_fork_pull_request: 0
51-
status: 1
51+
status: 6 # running
5252
started: 1683636528
5353
stopped: 1683636626
5454
created: 1683636108
@@ -74,3 +74,23 @@
7474
updated: 1683636626
7575
need_approval: 0
7676
approved_by: 0
77+
78+
-
79+
id: 795
80+
title: "to be deleted (test)"
81+
repo_id: 2
82+
owner_id: 2
83+
workflow_id: "test.yaml"
84+
index: 191
85+
trigger_user_id: 1
86+
ref: "refs/heads/test"
87+
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
88+
event: "push"
89+
is_fork_pull_request: 0
90+
status: 2
91+
started: 1683636528
92+
stopped: 1683636626
93+
created: 1683636108
94+
updated: 1683636626
95+
need_approval: 0
96+
approved_by: 0

models/fixtures/action_run_job.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,33 @@
6969
status: 5
7070
started: 1683636528
7171
stopped: 1683636626
72+
73+
-
74+
id: 198
75+
run_id: 795
76+
repo_id: 2
77+
owner_id: 2
78+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
79+
is_fork_pull_request: 0
80+
name: job_1
81+
attempt: 1
82+
job_id: job_1
83+
task_id: 53
84+
status: 1
85+
started: 1683636528
86+
stopped: 1683636626
87+
88+
-
89+
id: 199
90+
run_id: 795
91+
repo_id: 2
92+
owner_id: 2
93+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
94+
is_fork_pull_request: 0
95+
name: job_2
96+
attempt: 1
97+
job_id: job_2
98+
task_id: 54
99+
status: 2
100+
started: 1683636528
101+
stopped: 1683636626

models/fixtures/action_runner.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@
3838
repo_id: 0
3939
description: "This runner is going to be deleted"
4040
agent_labels: '["runner_to_be_deleted","linux"]'
41+
-
42+
id: 34350
43+
name: runner_to_be_deleted-org-ephemeral
44+
uuid: 3FF231BD-FBB7-4E4B-9602-E6F28363EF20
45+
token_hash: 3FF231BD-FBB7-4E4B-9602-E6F28363EF20
46+
ephemeral: true
47+
version: "1.0.0"
48+
owner_id: 3
49+
repo_id: 0
50+
description: "This runner is going to be deleted"
51+
agent_labels: '["runner_to_be_deleted","linux"]'

0 commit comments

Comments
 (0)