diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 4ba7608aaa348..587a2b14bcf21 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3503,6 +3503,7 @@ workflow.disable = Disable Workflow workflow.disable_success = Workflow '%s' disabled successfully. workflow.enable = Enable Workflow workflow.enable_success = Workflow '%s' enabled successfully. +workflow.disabled = Workflow is disabled. need_approval_desc = Need approval to run workflows for fork pull request. diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index af2ec21e4bdda..e4ca6a71987f6 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -259,31 +259,35 @@ func ViewPost(ctx *context_module.Context) { ctx.JSON(http.StatusOK, resp) } -func RerunOne(ctx *context_module.Context) { +// Rerun will rerun jobs in the given run +// jobIndex = 0 means rerun all jobs +func Rerun(ctx *context_module.Context) { runIndex := ctx.ParamsInt64("run") jobIndex := ctx.ParamsInt64("job") - job, _ := getRunJobs(ctx, runIndex, jobIndex) - if ctx.Written() { + run, err := actions_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex) + if err != nil { + ctx.Error(http.StatusInternalServerError, err.Error()) return } - if err := rerunJob(ctx, job); err != nil { - ctx.Error(http.StatusInternalServerError, err.Error()) + // can not rerun job when workflow is disabled + cfgUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions) + cfg := cfgUnit.ActionsConfig() + if cfg.IsWorkflowDisabled(run.WorkflowID) { + ctx.JSONError(ctx.Locale.Tr("actions.workflow.disabled")) return } - ctx.JSON(http.StatusOK, struct{}{}) -} - -func RerunAll(ctx *context_module.Context) { - runIndex := ctx.ParamsInt64("run") - - _, jobs := getRunJobs(ctx, runIndex, 0) + job, jobs := getRunJobs(ctx, runIndex, jobIndex) if ctx.Written() { return } + if jobIndex != 0 { + jobs = []*actions_model.ActionRunJob{job} + } + for _, j := range jobs { if err := rerunJob(ctx, j); err != nil { ctx.Error(http.StatusInternalServerError, err.Error()) diff --git a/routers/web/web.go b/routers/web/web.go index e70e360d5991d..bbab9b37b5973 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1211,14 +1211,14 @@ func registerRoutes(m *web.Route) { m.Combo(""). Get(actions.View). Post(web.Bind(actions.ViewRequest{}), actions.ViewPost) - m.Post("/rerun", reqRepoActionsWriter, actions.RerunOne) + m.Post("/rerun", reqRepoActionsWriter, actions.Rerun) m.Get("/logs", actions.Logs) }) m.Post("/cancel", reqRepoActionsWriter, actions.Cancel) m.Post("/approve", reqRepoActionsWriter, actions.Approve) m.Post("/artifacts", actions.ArtifactsView) m.Get("/artifacts/{artifact_name}", actions.ArtifactsDownloadView) - m.Post("/rerun", reqRepoActionsWriter, actions.RerunAll) + m.Post("/rerun", reqRepoActionsWriter, actions.Rerun) }) }, reqRepoActionsReader, actions.MustEnableActions) diff --git a/templates/base/head_script.tmpl b/templates/base/head_script.tmpl index c7477ff4c0f2e..03916fa6370c9 100644 --- a/templates/base/head_script.tmpl +++ b/templates/base/head_script.tmpl @@ -4,7 +4,9 @@ If you are customizing Gitea, please do not change this file. If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly. */}}