@ -33,6 +33,7 @@ import (
const (
const (
tplListActions templates . TplName = "repo/actions/list"
tplListActions templates . TplName = "repo/actions/list"
tplDispatchInputsActions templates . TplName = "repo/actions/workflow_dispatch_inputs"
tplViewActions templates . TplName = "repo/actions/view"
tplViewActions templates . TplName = "repo/actions/view"
)
)
@ -64,26 +65,66 @@ func MustEnableActions(ctx *context.Context) {
func List ( ctx * context . Context ) {
func List ( ctx * context . Context ) {
ctx . Data [ "Title" ] = ctx . Tr ( "actions.actions" )
ctx . Data [ "Title" ] = ctx . Tr ( "actions.actions" )
ctx . Data [ "PageIsActions" ] = true
ctx . Data [ "PageIsActions" ] = true
workflowID := ctx . FormString ( "workflow" )
actorID := ctx . FormInt64 ( "actor" )
status := ctx . FormInt ( "status" )
ctx . Data [ "CurWorkflow" ] = workflowID
var workflows [ ] Workflow
var curWorkflow * model . Workflow
if empty , err := ctx . Repo . GitRepo . IsEmpty ( ) ; err != nil {
ctx . ServerError ( "IsEmpty" , err )
return
} else if ! empty {
commit , err := ctx . Repo . GitRepo . GetBranchCommit ( ctx . Repo . Repository . DefaultBranch )
commit , err := ctx . Repo . GitRepo . GetBranchCommit ( ctx . Repo . Repository . DefaultBranch )
if err != nil {
if err != nil {
ctx . ServerError ( "GetBranchCommit" , err )
ctx . ServerError ( "GetBranchCommit" , err )
return
return
}
}
workflows := prepareWorkflowDispatchTemplate ( ctx , commit )
if ctx . Written ( ) {
return
}
prepareWorkflowList ( ctx , workflows )
if ctx . Written ( ) {
return
}
ctx . HTML ( http . StatusOK , tplListActions )
}
func WorkflowDispatchInputs ( ctx * context . Context ) {
ref := ctx . FormString ( "ref" )
if ref == "" {
ctx . NotFound ( "WorkflowDispatchInputs: no ref" , nil )
return
}
// get target commit of run from specified ref
refName := git . RefName ( ref )
var commit * git . Commit
var err error
if refName . IsTag ( ) {
commit , err = ctx . Repo . GitRepo . GetTagCommit ( refName . TagName ( ) )
} else if refName . IsBranch ( ) {
commit , err = ctx . Repo . GitRepo . GetBranchCommit ( refName . BranchName ( ) )
} else {
ctx . ServerError ( "UnsupportedRefType" , nil )
return
}
if err != nil {
ctx . ServerError ( "GetTagCommit/GetBranchCommit" , err )
return
}
prepareWorkflowDispatchTemplate ( ctx , commit )
if ctx . Written ( ) {
return
}
ctx . HTML ( http . StatusOK , tplDispatchInputsActions )
}
func prepareWorkflowDispatchTemplate ( ctx * context . Context , commit * git . Commit ) ( workflows [ ] Workflow ) {
workflowID := ctx . FormString ( "workflow" )
ctx . Data [ "CurWorkflow" ] = workflowID
ctx . Data [ "CurWorkflowExists" ] = false
var curWorkflow * model . Workflow
entries , err := actions . ListWorkflows ( commit )
entries , err := actions . ListWorkflows ( commit )
if err != nil {
if err != nil {
ctx . ServerError ( "ListWorkflows" , err )
ctx . ServerError ( "ListWorkflows" , err )
return
return nil
}
}
// Get all runner labels
// Get all runner labels
@ -94,7 +135,7 @@ func List(ctx *context.Context) {
} )
} )
if err != nil {
if err != nil {
ctx . ServerError ( "FindRunners" , err )
ctx . ServerError ( "FindRunners" , err )
return
return nil
}
}
allRunnerLabels := make ( container . Set [ string ] )
allRunnerLabels := make ( container . Set [ string ] )
for _ , r := range runners {
for _ , r := range runners {
@ -107,7 +148,7 @@ func List(ctx *context.Context) {
content , err := actions . GetContentFromEntry ( entry )
content , err := actions . GetContentFromEntry ( entry )
if err != nil {
if err != nil {
ctx . ServerError ( "GetContentFromEntry" , err )
ctx . ServerError ( "GetContentFromEntry" , err )
return
return nil
}
}
wf , err := model . ReadWorkflow ( bytes . NewReader ( content ) )
wf , err := model . ReadWorkflow ( bytes . NewReader ( content ) )
if err != nil {
if err != nil {
@ -117,7 +158,7 @@ func List(ctx *context.Context) {
}
}
// The workflow must contain at least one job without "needs". Otherwise, a deadlock will occur and no jobs will be able to run.
// The workflow must contain at least one job without "needs". Otherwise, a deadlock will occur and no jobs will be able to run.
hasJobWithoutNeeds := false
hasJobWithoutNeeds := false
// Check whether have matching runner and a job without "needs"
// Check whether you have matching runner and a job without "needs"
emptyJobsNumber := 0
emptyJobsNumber := 0
for _ , j := range wf . Jobs {
for _ , j := range wf . Jobs {
if j == nil {
if j == nil {
@ -154,17 +195,13 @@ func List(ctx *context.Context) {
if workflow . Entry . Name ( ) == workflowID {
if workflow . Entry . Name ( ) == workflowID {
curWorkflow = wf
curWorkflow = wf
ctx . Data [ "CurWorkflowExists" ] = true
}
}
}
}
}
ctx . Data [ "workflows" ] = workflows
ctx . Data [ "workflows" ] = workflows
ctx . Data [ "RepoLink" ] = ctx . Repo . Repository . Link ( )
ctx . Data [ "RepoLink" ] = ctx . Repo . Repository . Link ( )
page := ctx . FormInt ( "page" )
if page <= 0 {
page = 1
}
actionsConfig := ctx . Repo . Repository . MustGetUnit ( ctx , unit . TypeActions ) . ActionsConfig ( )
actionsConfig := ctx . Repo . Repository . MustGetUnit ( ctx , unit . TypeActions ) . ActionsConfig ( )
ctx . Data [ "ActionsConfig" ] = actionsConfig
ctx . Data [ "ActionsConfig" ] = actionsConfig
@ -188,7 +225,7 @@ func List(ctx *context.Context) {
branches , err := git_model . FindBranchNames ( ctx , branchOpts )
branches , err := git_model . FindBranchNames ( ctx , branchOpts )
if err != nil {
if err != nil {
ctx . ServerError ( "FindBranchNames" , err )
ctx . ServerError ( "FindBranchNames" , err )
return
return nil
}
}
// always put default branch on the top if it exists
// always put default branch on the top if it exists
if slices . Contains ( branches , ctx . Repo . Repository . DefaultBranch ) {
if slices . Contains ( branches , ctx . Repo . Repository . DefaultBranch ) {
@ -200,12 +237,23 @@ func List(ctx *context.Context) {
tags , err := repo_model . GetTagNamesByRepoID ( ctx , ctx . Repo . Repository . ID )
tags , err := repo_model . GetTagNamesByRepoID ( ctx , ctx . Repo . Repository . ID )
if err != nil {
if err != nil {
ctx . ServerError ( "GetTagNamesByRepoID" , err )
ctx . ServerError ( "GetTagNamesByRepoID" , err )
return
return nil
}
}
ctx . Data [ "Tags" ] = tags
ctx . Data [ "Tags" ] = tags
}
}
}
}
}
}
return workflows
}
func prepareWorkflowList ( ctx * context . Context , workflows [ ] Workflow ) {
actorID := ctx . FormInt64 ( "actor" )
status := ctx . FormInt ( "status" )
workflowID := ctx . FormString ( "workflow" )
page := ctx . FormInt ( "page" )
if page <= 0 {
page = 1
}
// if status or actor query param is not given to frontend href, (href="/<repoLink>/actions")
// if status or actor query param is not given to frontend href, (href="/<repoLink>/actions")
// they will be 0 by default, which indicates get all status or actors
// they will be 0 by default, which indicates get all status or actors
@ -264,8 +312,6 @@ func List(ctx *context.Context) {
pager . AddParamFromRequest ( ctx . Req )
pager . AddParamFromRequest ( ctx . Req )
ctx . Data [ "Page" ] = pager
ctx . Data [ "Page" ] = pager
ctx . Data [ "HasWorkflowsOrRuns" ] = len ( workflows ) > 0 || len ( runs ) > 0
ctx . Data [ "HasWorkflowsOrRuns" ] = len ( workflows ) > 0 || len ( runs ) > 0
ctx . HTML ( http . StatusOK , tplListActions )
}
}
// loadIsRefDeleted loads the IsRefDeleted field for each run in the list.
// loadIsRefDeleted loads the IsRefDeleted field for each run in the list.