mirror of https://github.com/databricks/cli.git
Include job source information in deployed jobs
This commit is contained in:
parent
f7a76ff5d8
commit
8e8c47b477
|
@ -0,0 +1,65 @@
|
||||||
|
package mutator
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/databricks/cli/bundle"
|
||||||
|
"github.com/databricks/cli/libs/git"
|
||||||
|
"github.com/databricks/databricks-sdk-go/service/jobs"
|
||||||
|
)
|
||||||
|
|
||||||
|
type setJobSources struct{}
|
||||||
|
|
||||||
|
// TranslatePaths converts paths to local notebook files into paths in the workspace file system.
|
||||||
|
func SetJobSources() bundle.Mutator {
|
||||||
|
return &setJobSources{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *setJobSources) Name() string {
|
||||||
|
return "SetJobSources"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *setJobSources) Apply(ctx context.Context, b *bundle.Bundle) error {
|
||||||
|
repo, err := git.NewRepository(b.Config.Path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !repo.IsRealRepo() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, job := range b.Config.Resources.Jobs {
|
||||||
|
branch := ""
|
||||||
|
commit := ""
|
||||||
|
|
||||||
|
if b.Config.Bundle.Git.Branch != "" {
|
||||||
|
// Set branch, If current checkout is a branch.
|
||||||
|
branch = b.Config.Bundle.Git.Branch
|
||||||
|
} else {
|
||||||
|
// Set the commit SHA if current checkout is not a branch.
|
||||||
|
commit = b.Config.Bundle.Git.Commit
|
||||||
|
}
|
||||||
|
|
||||||
|
relPath, err := filepath.Rel(repo.Root(), job.ConfigFilePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
relPath = filepath.ToSlash(relPath)
|
||||||
|
|
||||||
|
job.GitSource = &jobs.GitSource{
|
||||||
|
GitBranch: branch,
|
||||||
|
GitCommit: commit,
|
||||||
|
GitUrl: b.Config.Bundle.Git.OriginURL,
|
||||||
|
JobSource: &jobs.JobSource{
|
||||||
|
ImportFromGitBranch: branch,
|
||||||
|
|
||||||
|
// Set job source config path, i.e the path to yml file containing
|
||||||
|
// the job definition.
|
||||||
|
JobConfigPath: relPath,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ func Initialize() bundle.Mutator {
|
||||||
mutator.OverrideCompute(),
|
mutator.OverrideCompute(),
|
||||||
mutator.ProcessEnvironmentMode(),
|
mutator.ProcessEnvironmentMode(),
|
||||||
mutator.TranslatePaths(),
|
mutator.TranslatePaths(),
|
||||||
|
mutator.SetJobSources(),
|
||||||
terraform.Initialize(),
|
terraform.Initialize(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -43,6 +43,11 @@ func (r *Repository) Root() string {
|
||||||
return r.rootPath
|
return r.rootPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns if the *Repository struct represents a real git repository
|
||||||
|
func (r *Repository) IsRealRepo() bool {
|
||||||
|
return r.real
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Repository) CurrentBranch() (string, error) {
|
func (r *Repository) CurrentBranch() (string, error) {
|
||||||
// load .git/HEAD
|
// load .git/HEAD
|
||||||
ref, err := LoadReferenceFile(filepath.Join(r.rootPath, ".git", "HEAD"))
|
ref, err := LoadReferenceFile(filepath.Join(r.rootPath, ".git", "HEAD"))
|
||||||
|
|
Loading…
Reference in New Issue