-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support upload outputs
and use needs
context on Actions
#24230
Merged
silverwind
merged 19 commits into
go-gitea:main
from
wolfogre:feature/actions_outputs_needs
Apr 22, 2023
Merged
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3646ea4
chore: update actions-proto-go
wolfogre 29ad93f
test: debug
wolfogre 1294750
Revert "test: debug"
wolfogre 8b543c4
feat: ActionTaskOutput
wolfogre 13fbbea
fix: send needs outputs
wolfogre 673d58a
fix: send outputs
wolfogre 3c975ff
chore: NewMigration
wolfogre 1d381a4
Merge branch 'main' into feature/actions_outputs_needs
wolfogre ce5eb47
fix: lint
wolfogre 737446d
chore: tidy
wolfogre 9eb634e
fix: update field name
wolfogre 70f8437
fix: use sha256
wolfogre 5519d9d
fix: drop key hash
wolfogre d6db381
fix: limitation for value
wolfogre 52fd9d5
Merge branch 'main' into feature/actions_outputs_needs
GiteaBot 5a1a72c
Merge branch 'main' into feature/actions_outputs_needs
GiteaBot 7f8fa70
Merge branch 'main' into feature/actions_outputs_needs
GiteaBot 0ee38ef
Merge branch 'main' into feature/actions_outputs_needs
GiteaBot 876d587
Merge branch 'main' into feature/actions_outputs_needs
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package actions | ||
|
||
import ( | ||
"context" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
) | ||
|
||
// ActionTaskOutput represents an output of ActionTask. | ||
// So the outputs are bound to a task, that means when a completed job has been rerun, | ||
// the outputs of the job will be reset because the task is new. | ||
// It's by design, to avoid the outputs of the old task to be mixed with the new task. | ||
type ActionTaskOutput struct { | ||
ID int64 | ||
TaskID int64 `xorm:"INDEX UNIQUE(task_id_output_key)"` | ||
OutputKey string `xorm:"VARCHAR(255) UNIQUE(task_id_output_key)"` | ||
OutputValue string `xorm:"MEDIUMTEXT"` | ||
} | ||
|
||
// FindTaskOutputByTaskID returns the outputs of the task. | ||
func FindTaskOutputByTaskID(ctx context.Context, taskID int64) ([]*ActionTaskOutput, error) { | ||
var outputs []*ActionTaskOutput | ||
return outputs, db.GetEngine(ctx).Where("task_id=?", taskID).Find(&outputs) | ||
} | ||
|
||
// FindTaskOutputKeyByTaskID returns the keys of the outputs of the task. | ||
func FindTaskOutputKeyByTaskID(ctx context.Context, taskID int64) ([]string, error) { | ||
var keys []string | ||
return keys, db.GetEngine(ctx).Table(ActionTaskOutput{}).Where("task_id=?", taskID).Cols("output_key").Find(&keys) | ||
} | ||
|
||
// InsertTaskOutputIfNotExist inserts a new task output if it does not exist. | ||
func InsertTaskOutputIfNotExist(ctx context.Context, taskID int64, key, value string) error { | ||
return db.WithTx(ctx, func(ctx context.Context) error { | ||
sess := db.GetEngine(ctx) | ||
if exist, err := sess.Exist(&ActionTaskOutput{TaskID: taskID, OutputKey: key}); err != nil { | ||
return err | ||
} else if exist { | ||
return nil | ||
} | ||
_, err := sess.Insert(&ActionTaskOutput{ | ||
TaskID: taskID, | ||
OutputKey: key, | ||
OutputValue: value, | ||
}) | ||
return err | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_20 //nolint | ||
|
||
import ( | ||
"xorm.io/xorm" | ||
) | ||
|
||
func AddActionTaskOutputTable(x *xorm.Engine) error { | ||
type ActionTaskOutput struct { | ||
ID int64 | ||
TaskID int64 `xorm:"INDEX UNIQUE(task_id_output_key)"` | ||
OutputKey string `xorm:"VARCHAR(255) UNIQUE(task_id_output_key)"` | ||
OutputValue string `xorm:"MEDIUMTEXT"` | ||
} | ||
return x.Sync(new(ActionTaskOutput)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nit, such operation would fail if there are concurrent requests. The transaction doesn't help.
The
Exist
(SELECT) doesn't acquire write lock, so 2 sameInsert
statements would execute concurrently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw it and tried to do something like
db.IsErrDuplicateKey(err)
, but I didn't find the way on xorm. So I just copied:gitea/models/migrations/v1_18/v227.go
Lines 31 to 40 in 0585ac3
Any good ideas? Maybe it doesn't really hurt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In migration, there is no concurrent request, so it's fine.
Just a nit, Gitea has a lot of code is not concurrency-safe. One more or fewer doesn't change the whole situation.