-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Support configuration variables on Gitea Actions #24724
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
Merged
Merged
Changes from all commits
Commits
Show all changes
83 commits
Select commit
Hold shift + click to select a range
c88e2ad
implements varibales
sillyguodong 427dfa2
typo
sillyguodong 3c0aa03
Merge branch 'main' into feature/variables
sillyguodong 5edf8ae
fix context package
sillyguodong 9e860db
Merge branch 'main' into feature/variables
sillyguodong fbe232f
Merge branch 'main' into feature/variables
sillyguodong a438e97
update
sillyguodong b018fee
fix lint
sillyguodong fd6270c
complete
sillyguodong 54d4918
lint
sillyguodong e19b2fe
lint
sillyguodong b1bf9a8
Merge branch 'main' into feature/variables
sillyguodong e1051a3
fmt check
sillyguodong 89928e9
typo
sillyguodong 4007170
typo
sillyguodong 0e37460
Merge branch 'main' into feature/variables
sillyguodong bcaba8b
reanme table name
sillyguodong a580e4a
delete unnecessary where condition
sillyguodong de5cbbc
Merge branch 'main' into feature/variables
sillyguodong 6c28158
delete
sillyguodong 4081980
use button-ghost class
sillyguodong 460ba32
add padding for list items
sillyguodong 8867d20
user level variables
sillyguodong 06eec8b
use fetch request
sillyguodong ae965db
await json
sillyguodong 5e2bf96
Merge branch 'main' into feature/variables
sillyguodong e69f537
lint
sillyguodong e2a7327
make fmt
sillyguodong 45165e4
rename filename and function name
sillyguodong fc9b3fa
delete comment
sillyguodong ba90273
Merge branch 'main' into feature/variables
sillyguodong 3b9d874
getValidateContext
sillyguodong c0552dd
fix path param
sillyguodong 7c184d5
fix jquery.are-you-sure interference
silverwind 238418d
modal fixes
silverwind 0d07e9c
rename field, use ignore-dirty
silverwind 2029461
simplify form validation
silverwind 2ba6a92
use flexbox, fix border-radius
silverwind 57d9e70
Merge branch 'main' into feature/variables
sillyguodong 795cd09
fix secrets list
sillyguodong bb7e455
action modal share js
sillyguodong 83a593d
Update options/locale/locale_en-US.ini
sillyguodong 945efc2
make check
sillyguodong b1f5d83
lint
sillyguodong e632c97
Merge branch 'main' into feature/variables
sillyguodong d849c9e
fix actions meun
sillyguodong a75d1f6
Merge branch 'main' into feature/variables
sillyguodong 5da62b4
update
sillyguodong ad2b53f
fix
sillyguodong 8928823
fix
sillyguodong 2a4d05f
Merge branch 'main' into feature/variables
sillyguodong 935a579
lint-templates
sillyguodong 5811563
no index
sillyguodong cea22db
interact-bg
sillyguodong 2506e95
update
sillyguodong 791983f
init
sillyguodong cc2c282
delete space
sillyguodong 27ded72
keep index of repo_id
sillyguodong fb0681f
modal onApprove
sillyguodong 1d65fad
delete show-modal class
sillyguodong 905e916
Merge branch 'main' into feature/variables
wxiaoguang 058dcc8
fix fmt
wxiaoguang 8e9a11a
use link-action
sillyguodong 81d62c5
prepare to use general "show-modal"
wxiaoguang f766a4b
delete useless key class
sillyguodong 1134fc6
use gt-rounded-bottom
sillyguodong e87c2c3
refactor
wxiaoguang 14467cb
fine tune
wxiaoguang bc8f7ae
fix modal background for loading state
silverwind 403090d
move comment
silverwind 0339408
clean tooltip
sillyguodong 0738c17
Update options/locale/locale_en-US.ini
sillyguodong 9f618a3
delete unused trans
sillyguodong 06b1f39
add top-level trans
sillyguodong 48e9368
Merge branch 'main' into feature/variables
wxiaoguang 9a43909
Merge branch 'main' into feature/variables
silverwind 3c47977
rename column
sillyguodong d8abde9
forbid env name ci
sillyguodong 2d80878
make fmt
sillyguodong aff6008
Merge branch 'main' into feature/variables
sillyguodong b22af4d
Merge branch 'main' into feature/variables
sillyguodong d0f6c54
fix max char count of name and data
sillyguodong 58e9253
Merge branch 'main' into feature/variables
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 hidden or 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,97 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package actions | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
"code.gitea.io/gitea/modules/timeutil" | ||
"code.gitea.io/gitea/modules/util" | ||
|
||
"xorm.io/builder" | ||
) | ||
|
||
type ActionVariable struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
OwnerID int64 `xorm:"UNIQUE(owner_repo_name)"` | ||
RepoID int64 `xorm:"INDEX UNIQUE(owner_repo_name)"` | ||
Name string `xorm:"UNIQUE(owner_repo_name) NOT NULL"` | ||
Data string `xorm:"LONGTEXT NOT NULL"` | ||
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"` | ||
UpdatedUnix timeutil.TimeStamp `xorm:"updated"` | ||
} | ||
|
||
func init() { | ||
db.RegisterModel(new(ActionVariable)) | ||
} | ||
|
||
func (v *ActionVariable) Validate() error { | ||
if v.OwnerID == 0 && v.RepoID == 0 { | ||
return errors.New("the variable is not bound to any scope") | ||
} | ||
return nil | ||
} | ||
|
||
func InsertVariable(ctx context.Context, ownerID, repoID int64, name, data string) (*ActionVariable, error) { | ||
variable := &ActionVariable{ | ||
OwnerID: ownerID, | ||
RepoID: repoID, | ||
Name: strings.ToUpper(name), | ||
Data: data, | ||
} | ||
if err := variable.Validate(); err != nil { | ||
return variable, err | ||
} | ||
return variable, db.Insert(ctx, variable) | ||
} | ||
|
||
type FindVariablesOpts struct { | ||
db.ListOptions | ||
OwnerID int64 | ||
RepoID int64 | ||
} | ||
|
||
func (opts *FindVariablesOpts) toConds() builder.Cond { | ||
cond := builder.NewCond() | ||
if opts.OwnerID > 0 { | ||
cond = cond.And(builder.Eq{"owner_id": opts.OwnerID}) | ||
} | ||
if opts.RepoID > 0 { | ||
cond = cond.And(builder.Eq{"repo_id": opts.RepoID}) | ||
} | ||
return cond | ||
} | ||
|
||
func FindVariables(ctx context.Context, opts FindVariablesOpts) ([]*ActionVariable, error) { | ||
var variables []*ActionVariable | ||
sess := db.GetEngine(ctx) | ||
if opts.PageSize != 0 { | ||
sess = db.SetSessionPagination(sess, &opts.ListOptions) | ||
} | ||
return variables, sess.Where(opts.toConds()).Find(&variables) | ||
} | ||
|
||
func GetVariableByID(ctx context.Context, variableID int64) (*ActionVariable, error) { | ||
var variable ActionVariable | ||
has, err := db.GetEngine(ctx).Where("id=?", variableID).Get(&variable) | ||
if err != nil { | ||
return nil, err | ||
} else if !has { | ||
return nil, fmt.Errorf("variable with id %d: %w", variableID, util.ErrNotExist) | ||
} | ||
return &variable, nil | ||
} | ||
|
||
func UpdateVariable(ctx context.Context, variable *ActionVariable) (bool, error) { | ||
count, err := db.GetEngine(ctx).ID(variable.ID).Cols("name", "data"). | ||
Update(&ActionVariable{ | ||
Name: variable.Name, | ||
Data: variable.Data, | ||
}) | ||
return count != 0, err | ||
} |
This file contains hidden or 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 hidden or 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,24 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_21 //nolint | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/timeutil" | ||
|
||
"xorm.io/xorm" | ||
) | ||
|
||
func CreateVariableTable(x *xorm.Engine) error { | ||
type ActionVariable struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
OwnerID int64 `xorm:"UNIQUE(owner_repo_name)"` | ||
RepoID int64 `xorm:"INDEX UNIQUE(owner_repo_name)"` | ||
Name string `xorm:"UNIQUE(owner_repo_name) NOT NULL"` | ||
Data string `xorm:"LONGTEXT NOT NULL"` | ||
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"` | ||
UpdatedUnix timeutil.TimeStamp `xorm:"updated"` | ||
} | ||
|
||
return x.Sync(new(ActionVariable)) | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.