diff --git a/src/ploigos_step_runner/__main__.py b/src/ploigos_step_runner/__main__.py index 85518f35..2fe78af7 100644 --- a/src/ploigos_step_runner/__main__.py +++ b/src/ploigos_step_runner/__main__.py @@ -111,7 +111,12 @@ def main(argv=None): sys.exit(102) config.set_step_config_overrides(args.step, args.step_config) - step_runner = StepRunner(config) + # it is VERY important that the working dir be an absolute path because some + # commands (looking at you maven) will change the context of relative paths on you + step_runner = StepRunner( + config=config, + work_dir_path=os.path.abspath('step-runner-working') + ) try: if not step_runner.run_step(args.step, args.environment): diff --git a/src/ploigos_step_runner/utils/maven.py b/src/ploigos_step_runner/utils/maven.py index ceeb3d94..490c338d 100644 --- a/src/ploigos_step_runner/utils/maven.py +++ b/src/ploigos_step_runner/utils/maven.py @@ -1,6 +1,7 @@ """Shared utils for maven operations. """ +import os import xml.etree.ElementTree as ET import sh @@ -420,6 +421,15 @@ def write_effective_pom( If issue generating effective pom. """ + if not os.path.isabs(output_path): + raise StepRunnerException( + f"Given output path ({output_path}) is not absolute which will mean your output" + f" file will actually end up being relative to the pom file ({pom_file_path}) rather" + " than your expected root. Rather then handling this, just give this function an" + " absolute path." + " If you are a user seeing this, a programmer messed up somewhere, report an issue." + ) + try: sh.mvn( # pylint: disable=no-member 'help:effective-pom', diff --git a/tests/utils/test_maven.py b/tests/utils/test_maven.py index 5c90362e..4f031610 100644 --- a/tests/utils/test_maven.py +++ b/tests/utils/test_maven.py @@ -971,7 +971,7 @@ def test_add_maven_mirrors_dict_missing_mirror_of(self): @patch('sh.mvn', create=True) def test_write_effective_pom_success(self, mvn_mock): pom_file_path = 'input/pom.xml' - effective_pom_path = 'output/effective-pom.xml' + effective_pom_path = '/tmp/output/effective-pom.xml' actual_effective_pom_path = write_effective_pom( pom_file_path=pom_file_path, @@ -987,7 +987,7 @@ def test_write_effective_pom_success(self, mvn_mock): @patch('sh.mvn', create=True) def test_write_effective_pom_fail(self, mvn_mock): pom_file_path = 'input/pom.xml' - effective_pom_path = 'output/effective-pom.xml' + effective_pom_path = '/tmp/output/effective-pom.xml' mvn_mock.side_effect = sh.ErrorReturnCode('mvn', b'mock stdout', b'mock error') @@ -1012,3 +1012,32 @@ def test_write_effective_pom_fail(self, mvn_mock): f'-f={pom_file_path}', f'-Doutput={effective_pom_path}' ) + + @patch('sh.mvn', create=True) + def test_write_effective_pom_fail_not_absolute_path(self, mvn_mock): + pom_file_path = 'input/pom.xml' + effective_pom_path = 'output/effective-pom.xml' + + mvn_mock.side_effect = sh.ErrorReturnCode('mvn', b'mock stdout', b'mock error') + + with self.assertRaisesRegex( + StepRunnerException, + re.compile( + rf"Given output path \({effective_pom_path}\) is not absolute which will mean " + rf"your output file will actually end up being relative to the pom file " + rf"\({pom_file_path}\) rather than your expected root. Rather then handling this, " + rf"just give this function an absolute path. " + rf"If you are a user seeing this, a programmer messed up somewhere, " + rf"report an issue.", + re.DOTALL + ) + ): + write_effective_pom( + pom_file_path=pom_file_path, + output_path=effective_pom_path + ) + mvn_mock.assert_any_call( + 'help:effective-pom', + f'-f={pom_file_path}', + f'-Doutput={effective_pom_path}' + ) \ No newline at end of file