feat(apps): change log message

This commit is contained in:
Denis Gukov 2024-07-10 13:12:01 +05:00
parent da6fa99980
commit 989d3b4a8e
7 changed files with 31 additions and 20 deletions

View File

@ -2,6 +2,7 @@ package projects
import (
"fmt"
"github.com/ansible-semaphore/semaphore/util"
"net/http"
"github.com/ansible-semaphore/semaphore/api/helpers"
@ -81,6 +82,12 @@ func AddTemplate(w http.ResponseWriter, r *http.Request) {
return
}
if _, ok := util.Config.Apps[string(newTemplate.App)]; !ok {
helpers.WriteErrorStatus(w, "Invalid app id", http.StatusBadRequest)
return
}
// Check workspace and create it if required.
if newTemplate.App.IsTerraform() {
var inv db.Inventory
@ -138,6 +145,11 @@ func UpdateTemplate(w http.ResponseWriter, r *http.Request) {
return
}
if _, ok := util.Config.Apps[string(template.App)]; !ok {
helpers.WriteErrorStatus(w, "Invalid app id", http.StatusBadRequest)
return
}
// project ID and template ID in the body and the path must be the same
if template.ID != oldTemplate.ID {

View File

@ -18,28 +18,19 @@ func CreateApp(template db.Template, repository db.Repository, logger task_logge
Logger: logger,
},
}
case db.TemplateTerraform:
case db.TemplateTerraform, db.TemplateTofu:
return &TerraformApp{
Template: template,
Repository: repository,
Logger: logger,
Name: TerraformAppTerraform,
Name: TerraformAppName(template.App),
}
case db.TemplateTofu:
return &TerraformApp{
Template: template,
Repository: repository,
Logger: logger,
Name: TerraformAppTofu,
}
case db.TemplateBash, db.TemplatePowerShell, db.TemplatePython:
default:
return &ShellApp{
Template: template,
Repository: repository,
Logger: logger,
App: template.App,
}
default:
panic("unknown app: " + template.App)
}
}

View File

@ -95,6 +95,12 @@ func (t *ShellApp) makeShellCmd(args []string, environmentVars *[]string) *exec.
case db.TemplatePowerShell:
command = "powershell"
appArgs = []string{"-File"}
default:
if app, ok := util.Config.Apps[string(t.App)]; ok && app.AppPath != "" {
command = app.AppPath
} else {
command = string(t.App)
}
}
return t.makeCmd(command, append(appArgs, args...), environmentVars)
}

View File

@ -165,7 +165,7 @@ func (t *LocalJob) getEnvironmentENV() (arr []string, err error) {
}
// nolint: gocyclo
func (t *LocalJob) getBashArgs(username string, incomingVersion *string) (args []string, err error) {
func (t *LocalJob) getShellArgs(username string, incomingVersion *string) (args []string, err error) {
extraVars, err := t.getEnvironmentExtraVars(username, incomingVersion)
args = append(args, t.Template.Playbook)
@ -378,10 +378,8 @@ func (t *LocalJob) Run(username string, incomingVersion *string) (err error) {
args, inputs, err = t.getPlaybookArgs(username, incomingVersion)
case db.TemplateTerraform, db.TemplateTofu:
args, err = t.getTerraformArgs(username, incomingVersion)
case db.TemplateBash, db.TemplatePowerShell, db.TemplatePython:
args, err = t.getBashArgs(username, incomingVersion)
default:
panic("unknown template app")
args, err = t.getShellArgs(username, incomingVersion)
}
if err != nil {

View File

@ -158,7 +158,7 @@ func (t *TaskRunner) run() {
err = t.job.Run(username, incomingVersion)
if err != nil {
t.Log("Running playbook failed: " + err.Error())
t.Log("Running app failed: " + err.Error())
t.SetStatus(task_logger.TaskFailStatus)
return
}
@ -172,7 +172,7 @@ func (t *TaskRunner) run() {
AutorunOnly: true,
}, db.RetrieveQueryParams{})
if err != nil {
t.Log("Running playbook failed: " + err.Error())
t.Log("Running app failed: " + err.Error())
return
}
@ -183,7 +183,7 @@ func (t *TaskRunner) run() {
BuildTaskID: &t.Task.ID,
}, nil, tpl.ProjectID)
if err != nil {
t.Log("Running playbook failed: " + err.Error())
t.Log("Running app failed: " + err.Error())
continue
}
}

View File

@ -1,5 +1,6 @@
<template>
<EditDialog
v-if="isAppsLoaded"
:max-width="700"
:min-content-height="457"
v-model="dialog"

View File

@ -340,7 +340,8 @@ export default {
props: {
sourceItemId: Number,
fields: Array,
fields: Object,
app: String,
},
data() {
@ -563,6 +564,8 @@ export default {
cron_format: this.cronFormat,
},
});
this.item.app = this.app;
},
async afterSave(newItem) {