From 402fcdd62cccbaa08cff5d89b0f99b6afde97614 Mon Sep 17 00:00:00 2001 From: stikkireddy <54602805+stikkireddy@users.noreply.github.com> Date: Wed, 7 Jun 2023 06:34:59 -0400 Subject: [PATCH] Skip path translation of job task for jobs with a Git source (#404) ## Changes Added skipping of translating paths for notebook path in notebook tasks and python file path in spark python tasks if the git source is not null. Resolves: #402 ## Tests There is a unit test and also tested with a sample bundle: ``` resources: jobs: demo: git_source: git_branch: master git_provider: github git_url: https://github.com/test/dummy .... ``` --------- Co-authored-by: Pieter Noordhuis --- bundle/config/mutator/translate_paths.go | 5 ++ bundle/config/mutator/translate_paths_test.go | 67 +++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/bundle/config/mutator/translate_paths.go b/bundle/config/mutator/translate_paths.go index ab2534ac..940ac212 100644 --- a/bundle/config/mutator/translate_paths.go +++ b/bundle/config/mutator/translate_paths.go @@ -154,6 +154,11 @@ func (m *translatePaths) Apply(_ context.Context, b *bundle.Bundle) error { return fmt.Errorf("unable to determine directory for job %s: %w", key, err) } + // Do not translate job task paths if using git source + if job.GitSource != nil { + continue + } + for i := 0; i < len(job.Tasks); i++ { err := m.translateJobTask(dir, b, &job.Tasks[i]) if err != nil { diff --git a/bundle/config/mutator/translate_paths_test.go b/bundle/config/mutator/translate_paths_test.go index ef7bed6c..df99bc19 100644 --- a/bundle/config/mutator/translate_paths_test.go +++ b/bundle/config/mutator/translate_paths_test.go @@ -31,6 +31,73 @@ func touchEmptyFile(t *testing.T, path string) { f.Close() } +func TestTranslatePathsSkippedWithGitSource(t *testing.T) { + dir := t.TempDir() + bundle := &bundle.Bundle{ + Config: config.Root{ + Path: dir, + Workspace: config.Workspace{ + FilesPath: "/bundle", + }, + Resources: config.Resources{ + Jobs: map[string]*resources.Job{ + "job": { + + Paths: resources.Paths{ + ConfigFilePath: filepath.Join(dir, "resource.yml"), + }, + JobSettings: &jobs.JobSettings{ + GitSource: &jobs.GitSource{ + GitBranch: "somebranch", + GitCommit: "somecommit", + GitProvider: "github", + GitTag: "sometag", + GitUrl: "https://github.com/someuser/somerepo", + }, + Tasks: []jobs.JobTaskSettings{ + { + NotebookTask: &jobs.NotebookTask{ + NotebookPath: "my_job_notebook.py", + }, + }, + { + PythonWheelTask: &jobs.PythonWheelTask{ + PackageName: "foo", + }, + }, + { + SparkPythonTask: &jobs.SparkPythonTask{ + PythonFile: "my_python_file.py", + }, + }, + }, + }, + }, + }, + }, + }, + } + + err := mutator.TranslatePaths().Apply(context.Background(), bundle) + require.NoError(t, err) + + assert.Equal( + t, + "my_job_notebook.py", + bundle.Config.Resources.Jobs["job"].Tasks[0].NotebookTask.NotebookPath, + ) + assert.Equal( + t, + "foo", + bundle.Config.Resources.Jobs["job"].Tasks[1].PythonWheelTask.PackageName, + ) + assert.Equal( + t, + "my_python_file.py", + bundle.Config.Resources.Jobs["job"].Tasks[2].SparkPythonTask.PythonFile, + ) +} + func TestTranslatePaths(t *testing.T) { dir := t.TempDir() touchNotebookFile(t, filepath.Join(dir, "my_job_notebook.py"))