@@ -33,9 +33,19 @@ import (
3333 "xorm.io/builder"
3434)
3535
36+ func getRunIndex (ctx * context_module.Context ) int64 {
37+ // if run param is "latest", get the latest run index
38+ if ctx .PathParam ("run" ) == "latest" {
39+ if run , _ := actions_model .GetLatestRun (ctx , ctx .Repo .Repository .ID ); run != nil {
40+ return run .Index
41+ }
42+ }
43+ return ctx .PathParamInt64 ("run" )
44+ }
45+
3646func View (ctx * context_module.Context ) {
3747 ctx .Data ["PageIsActions" ] = true
38- runIndex := ctx . PathParamInt64 ( "run" )
48+ runIndex := getRunIndex ( ctx )
3949 jobIndex := ctx .PathParamInt64 ("job" )
4050 ctx .Data ["RunIndex" ] = runIndex
4151 ctx .Data ["JobIndex" ] = jobIndex
@@ -130,7 +140,7 @@ type ViewStepLogLine struct {
130140
131141func ViewPost (ctx * context_module.Context ) {
132142 req := web .GetForm (ctx ).(* ViewRequest )
133- runIndex := ctx . PathParamInt64 ( "run" )
143+ runIndex := getRunIndex ( ctx )
134144 jobIndex := ctx .PathParamInt64 ("job" )
135145
136146 current , jobs := getRunJobs (ctx , runIndex , jobIndex )
@@ -289,7 +299,7 @@ func ViewPost(ctx *context_module.Context) {
289299// Rerun will rerun jobs in the given run
290300// If jobIndexStr is a blank string, it means rerun all jobs
291301func Rerun (ctx * context_module.Context ) {
292- runIndex := ctx . PathParamInt64 ( "run" )
302+ runIndex := getRunIndex ( ctx )
293303 jobIndexStr := ctx .PathParam ("job" )
294304 var jobIndex int64
295305 if jobIndexStr != "" {
@@ -379,7 +389,7 @@ func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob, shou
379389}
380390
381391func Logs (ctx * context_module.Context ) {
382- runIndex := ctx . PathParamInt64 ( "run" )
392+ runIndex := getRunIndex ( ctx )
383393 jobIndex := ctx .PathParamInt64 ("job" )
384394
385395 job , _ := getRunJobs (ctx , runIndex , jobIndex )
@@ -428,7 +438,7 @@ func Logs(ctx *context_module.Context) {
428438}
429439
430440func Cancel (ctx * context_module.Context ) {
431- runIndex := ctx . PathParamInt64 ( "run" )
441+ runIndex := getRunIndex ( ctx )
432442
433443 _ , jobs := getRunJobs (ctx , runIndex , - 1 )
434444 if ctx .Written () {
@@ -469,7 +479,7 @@ func Cancel(ctx *context_module.Context) {
469479}
470480
471481func Approve (ctx * context_module.Context ) {
472- runIndex := ctx . PathParamInt64 ( "run" )
482+ runIndex := getRunIndex ( ctx )
473483
474484 current , jobs := getRunJobs (ctx , runIndex , - 1 )
475485 if ctx .Written () {
@@ -518,7 +528,6 @@ func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*actions
518528 return nil , nil
519529 }
520530 run .Repo = ctx .Repo .Repository
521-
522531 jobs , err := actions_model .GetRunJobsByRunID (ctx , run .ID )
523532 if err != nil {
524533 ctx .Error (http .StatusInternalServerError , err .Error ())
@@ -550,7 +559,7 @@ type ArtifactsViewItem struct {
550559}
551560
552561func ArtifactsView (ctx * context_module.Context ) {
553- runIndex := ctx . PathParamInt64 ( "run" )
562+ runIndex := getRunIndex ( ctx )
554563 run , err := actions_model .GetRunByIndex (ctx , ctx .Repo .Repository .ID , runIndex )
555564 if err != nil {
556565 if errors .Is (err , util .ErrNotExist ) {
@@ -588,7 +597,7 @@ func ArtifactsDeleteView(ctx *context_module.Context) {
588597 return
589598 }
590599
591- runIndex := ctx . PathParamInt64 ( "run" )
600+ runIndex := getRunIndex ( ctx )
592601 artifactName := ctx .PathParam ("artifact_name" )
593602
594603 run , err := actions_model .GetRunByIndex (ctx , ctx .Repo .Repository .ID , runIndex )
@@ -606,7 +615,7 @@ func ArtifactsDeleteView(ctx *context_module.Context) {
606615}
607616
608617func ArtifactsDownloadView (ctx * context_module.Context ) {
609- runIndex := ctx . PathParamInt64 ( "run" )
618+ runIndex := getRunIndex ( ctx )
610619 artifactName := ctx .PathParam ("artifact_name" )
611620
612621 run , err := actions_model .GetRunByIndex (ctx , ctx .Repo .Repository .ID , runIndex )
0 commit comments