mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
Merge branch 'xyz' into develop
This commit is contained in:
commit
6ef0d474bc
@ -9,13 +9,14 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type RepositorySchema string
|
||||
type RepositoryType string
|
||||
|
||||
const (
|
||||
RepositoryGit RepositorySchema = "git"
|
||||
RepositorySSH RepositorySchema = "ssh"
|
||||
RepositoryHTTPS RepositorySchema = "https"
|
||||
RepositoryFile RepositorySchema = "file"
|
||||
RepositoryGit RepositoryType = "git"
|
||||
RepositorySSH RepositoryType = "ssh"
|
||||
RepositoryHTTPS RepositoryType = "https"
|
||||
RepositoryFile RepositoryType = "file"
|
||||
RepositoryLocal RepositoryType = "local"
|
||||
)
|
||||
|
||||
// Repository is the model for code stored in a git repository
|
||||
@ -65,13 +66,16 @@ func (r Repository) GetDirName(templateID int) string {
|
||||
}
|
||||
|
||||
func (r Repository) GetFullPath(templateID int) string {
|
||||
if r.GetType() == RepositoryLocal {
|
||||
return r.GetGitURL()
|
||||
}
|
||||
return path.Join(util.Config.TmpPath, r.GetDirName(templateID))
|
||||
}
|
||||
|
||||
func (r Repository) GetGitURL() string {
|
||||
url := r.GitURL
|
||||
|
||||
if r.getSchema() == RepositoryHTTPS {
|
||||
if r.GetType() == RepositoryHTTPS {
|
||||
auth := ""
|
||||
switch r.SSHKey.Type {
|
||||
case AccessKeyLoginPassword:
|
||||
@ -88,13 +92,18 @@ func (r Repository) GetGitURL() string {
|
||||
return url
|
||||
}
|
||||
|
||||
func (r Repository) getSchema() RepositorySchema {
|
||||
func (r Repository) GetType() RepositoryType {
|
||||
if strings.HasPrefix(r.GitURL, "/") {
|
||||
return RepositoryLocal
|
||||
}
|
||||
|
||||
re := regexp.MustCompile(`^(\w+)://`)
|
||||
m := re.FindStringSubmatch(r.GitURL)
|
||||
if m == nil {
|
||||
return RepositoryFile
|
||||
return RepositorySSH
|
||||
}
|
||||
return RepositorySchema(m[1])
|
||||
|
||||
return RepositoryType(m[1])
|
||||
}
|
||||
|
||||
func (r Repository) Validate() error {
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func TestRepository_GetSchema(t *testing.T) {
|
||||
repo := Repository{GitURL: "https://example.com/hello/world"}
|
||||
schema := repo.getSchema()
|
||||
schema := repo.GetType()
|
||||
if schema != "https" {
|
||||
t.Fatal()
|
||||
}
|
||||
|
@ -18,10 +18,6 @@ import (
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
)
|
||||
|
||||
const (
|
||||
gitURLFilePrefix = "file://"
|
||||
)
|
||||
|
||||
type TaskRunner struct {
|
||||
task db.Task
|
||||
template db.Template
|
||||
@ -159,8 +155,7 @@ func (t *TaskRunner) prepareRun() {
|
||||
|
||||
t.Log("Preparing: " + strconv.Itoa(t.task.ID))
|
||||
|
||||
err := checkTmpDir(util.Config.TmpPath)
|
||||
if err != nil {
|
||||
if err := checkTmpDir(util.Config.TmpPath); err != nil {
|
||||
t.Log("Creating tmp dir failed: " + err.Error())
|
||||
t.fail()
|
||||
return
|
||||
@ -168,15 +163,15 @@ func (t *TaskRunner) prepareRun() {
|
||||
|
||||
objType := db.EventTask
|
||||
desc := "Task ID " + strconv.Itoa(t.task.ID) + " (" + t.template.Name + ")" + " is preparing"
|
||||
_, err = t.pool.store.CreateEvent(db.Event{
|
||||
evt := db.Event{
|
||||
UserID: t.task.UserID,
|
||||
ProjectID: &t.task.ProjectID,
|
||||
ObjectType: &objType,
|
||||
ObjectID: &t.task.ID,
|
||||
Description: &desc,
|
||||
})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if _, err := t.pool.store.CreateEvent(evt); err != nil {
|
||||
t.Log("Fatal error inserting an event")
|
||||
panic(err)
|
||||
}
|
||||
@ -185,10 +180,9 @@ func (t *TaskRunner) prepareRun() {
|
||||
|
||||
t.updateStatus()
|
||||
|
||||
if strings.HasPrefix(t.repository.GitURL, gitURLFilePrefix) {
|
||||
repositoryPath := strings.TrimPrefix(t.repository.GitURL, gitURLFilePrefix)
|
||||
if _, err := os.Stat(repositoryPath); err != nil {
|
||||
t.Log("Failed in finding static repository at " + repositoryPath + ": " + err.Error())
|
||||
if t.repository.GetType() == db.RepositoryLocal {
|
||||
if _, err := os.Stat(t.repository.GitURL); err != nil {
|
||||
t.Log("Failed in finding static repository at " + t.repository.GitURL + ": " + err.Error())
|
||||
t.fail()
|
||||
return
|
||||
}
|
||||
@ -198,12 +192,11 @@ func (t *TaskRunner) prepareRun() {
|
||||
t.fail()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err := t.checkoutRepository(); err != nil {
|
||||
t.Log("Failed to checkout repository to required commit: " + err.Error())
|
||||
t.fail()
|
||||
return
|
||||
if err := t.checkoutRepository(); err != nil {
|
||||
t.Log("Failed to checkout repository to required commit: " + err.Error())
|
||||
t.fail()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err := t.installInventory(); err != nil {
|
||||
@ -416,6 +409,7 @@ func (t *TaskRunner) installVaultKeyFile() error {
|
||||
}
|
||||
|
||||
func (t *TaskRunner) checkoutRepository() error {
|
||||
|
||||
repo := lib.GitRepository{
|
||||
Logger: t,
|
||||
TemplateID: t.template.ID,
|
||||
@ -491,7 +485,7 @@ func (t *TaskRunner) installCollectionsRequirements() error {
|
||||
t.Log("No collections/requirements.yml file found. Skip galaxy install process.\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
if hasRequirementsChanges(requirementsFilePath, requirementsHashFilePath) {
|
||||
if err := t.runGalaxy([]string{
|
||||
"collection",
|
||||
@ -508,19 +502,19 @@ func (t *TaskRunner) installCollectionsRequirements() error {
|
||||
} else {
|
||||
t.Log("collections/requirements.yml has no changes. Skip galaxy install process.\n")
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TaskRunner) installRolesRequirements() error {
|
||||
requirementsFilePath := fmt.Sprintf("%s/roles/requirements.yml", t.getRepoPath())
|
||||
requirementsHashFilePath := fmt.Sprintf("%s.md5", requirementsFilePath)
|
||||
|
||||
|
||||
if _, err := os.Stat(requirementsFilePath); err != nil {
|
||||
t.Log("No roles/requirements.yml file found. Skip galaxy install process.\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
if hasRequirementsChanges(requirementsFilePath, requirementsHashFilePath) {
|
||||
if err := t.runGalaxy([]string{
|
||||
"role",
|
||||
@ -537,7 +531,7 @@ func (t *TaskRunner) installRolesRequirements() error {
|
||||
} else {
|
||||
t.Log("roles/requirements.yml has no changes. Skip galaxy install process.\n")
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user