def main(targets, file): if len(targets) == 0: targets = ["default"] if hasattr(file, 'name') \ and isinstance(file.name, str) \ and os.path.isfile(file.name): # If filename available and file exists, load file to allow docker-compose integration parameters = Parameters(file.name, targets, 1) else: parameters = Parameters(file, targets, 1) project = load_project(parameters) context = core.create_context(project, parameters) print("Running RunCI pipeline for the following target(s): %s" % str.join(" ", targets)) unknown_targets = [t for t in targets if t not in [t.name for t in project.targets]] if any(unknown_targets): print("Unkown targets: %s" % str.join(" ", unknown_targets), file=sys.stderr) sys.exit(1) result = asyncio.run(run_project(context)) if result == JobStatus.SUCCEEDED: print("Pipeline has run succesfully.") sys.exit(0) elif result == JobStatus.FAILED: print("Pipeline has failed.", file=sys.stderr) sys.exit(1) elif result == JobStatus.CANCELED: print("Pipeline has been canceled.", file=sys.stderr) sys.exit(2) else: print("Pipeline has been run but outcome is undetermined. Please report this as a bug.", file=sys.stderr) sys.exit(3)
def test_failing_build(self, mock, project, parameters, calls, noparallel): def side_effect(self, project): self._status = runner.RunnerStatus.FAILED mock.side_effect = side_effect context = core.create_context(project, parameters) tree = core.DependencyTree(context) tree.run(noparallel) self.assertEqual(tree.status, job.JobStatus.FAILED)
def test_invalid_step_type(self, mock): target = Target("test", "", [Step("test", "invalid", {})]) project = Project([], [target]) context = core.create_context(project, None) job = Job(context, target) job.run() self.assertEqual(job.status, JobStatus.FAILED) self.assertTrue( any([ mock_call for mock_call in mock.mock_calls if isinstance(mock_call.args[0], JobStepUnknownTypeEvent) ]))
def test_exception(self, mock): class TestRunner(RunnerBase): async def run_internal(self, project: Project): raise Exception("Simulating an exception") target = Target("test", "", [Step("test", "mock", {})]) project = Project([], [target]) context = core.create_context(project, None) job = Job(context, target) job.run() self.assertEqual(job.status, JobStatus.FAILED) self.assertEqual(mock.call_count, 3) self.assertIsInstance(mock.mock_calls[0].args[0], JobStartEvent) self.assertIsInstance(mock.mock_calls[1].args[0], JobStepUnknownTypeEvent) self.assertIsInstance(mock.mock_calls[2].args[0], JobFailureEvent)
def test_release_messages(self): command = self.test_command class TestRunner(RunnerBase): async def run_internal(self, context: Context): await self._run_process(["sh", "-c", command]) target = Target("test", "", [Step("test", "mock", {})]) project = Project([], [target]) context = core.create_context(project, None) context.runners["mock"] = TestRunner job = Job(context, target) job.run() self.assertEqual(job.status, JobStatus.SUCCEEDED) self.assertTrue(job.has_new_events()) asyncio.run(job.process_events()) self.assertFalse(job.has_new_events())
def test_command_line_args(self, mock, project, parameters, calls, noparallel): context = core.create_context(project, parameters) core.DependencyTree(context).run(noparallel) mock.assert_has_calls(calls)
def test_runner_run(self, mock, project, parameters, calls): context = core.create_context(project, parameters) core.DependencyTree(context).run() mock.assert_has_calls([call(context)])
def test_inexistent(self, project, parameters): with self.assertRaises(UnknownTargetException): context = core.create_context(project, parameters) core.DependencyTree(context).run()
def test_integration(self, mock): context = create_context(self.project, self.parameters) DependencyTree(context).run() mock.assert_called_once()
async def run(): runner = DockerPullRunner(self.project.targets[0], self.step, lambda e: None) context = create_context(self.project, self.parameters) await runner.run(context)
async def run(): runner = ComposeBuildRunner(None, self.step, lambda e: None) context = create_context(self.project, self.parameters) await runner.run(context)