diff --git a/src/Component.php b/src/Component.php index 14fb65a9..c0cc9ea1 100644 --- a/src/Component.php +++ b/src/Component.php @@ -186,6 +186,7 @@ protected function getSyncActions(): array /** * @return array + * @throws \Keboola\Component\UserException */ protected function actionDbtDocs(): array { @@ -194,6 +195,7 @@ protected function actionDbtDocs(): array $branchId = $this->getConfig()->getBranchId(); $this->artifacts->downloadLastRun($componentId, $configId, $branchId); + $this->artifacts->checkIfCorrectStepIsDownloaded(DbtService::COMMAND_DOCS_GENERATE); $html = $this->artifacts->readFromFile(DbtService::COMMAND_DOCS_GENERATE, 'index.html'); $manifest = $this->artifacts->readFromFile(DbtService::COMMAND_DOCS_GENERATE, 'manifest.json'); diff --git a/src/Service/ArtifactsService.php b/src/Service/ArtifactsService.php index faad9e9c..b2bb11a4 100644 --- a/src/Service/ArtifactsService.php +++ b/src/Service/ArtifactsService.php @@ -48,6 +48,9 @@ public function writeResults(string $projectPath, string $step): void $this->filesystem->mirror(sprintf('%s/target/', $projectPath), $artifactsPath); } + /** + * @throws \Keboola\Component\UserException + */ public function downloadLastRun(string $componentId, string $configId, string $branchId): ?int { $query = sprintf( @@ -86,9 +89,15 @@ public function downloadLastRun(string $componentId, string $configId, string $b return $file['id']; } + /** + * @throws \Keboola\Component\UserException + */ public function readFromFile(string $step, string $filePath): string { $file = new SplFileInfo(sprintf('%s/%s/%s', $this->getDownloadDir(), $step, $filePath)); + if (!$file->isFile()) { + throw new UserException(sprintf('Missing "%s" file in downloaded artifact', $filePath)); + } return (string) file_get_contents($file->getPathname()); } @@ -111,4 +120,16 @@ private function mkdir(string $path): void $this->filesystem->mkdir($path); } } + + /** + * @throws \Keboola\Component\UserException + */ + public function checkIfCorrectStepIsDownloaded(string $step): void + { + $docsPath = sprintf('%s/%s', $this->getDownloadDir(), $step); + if (!$this->filesystem->exists($docsPath)) { + throw new UserException('No artifact from previous dbt docs generate found. ' . + 'Run the component first with dbt docs generate command enabled.'); + } + } } diff --git a/tests/functionalSyncActions/run-sync-action-dbt-docs-missing-index/expected-code b/tests/functionalSyncActions/run-sync-action-dbt-docs-missing-index/expected-code new file mode 100644 index 00000000..56a6051c --- /dev/null +++ b/tests/functionalSyncActions/run-sync-action-dbt-docs-missing-index/expected-code @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/tests/functionalSyncActions/run-sync-action-dbt-docs-missing-index/expected-stderr b/tests/functionalSyncActions/run-sync-action-dbt-docs-missing-index/expected-stderr new file mode 100644 index 00000000..12355437 --- /dev/null +++ b/tests/functionalSyncActions/run-sync-action-dbt-docs-missing-index/expected-stderr @@ -0,0 +1 @@ +Missing "index.html" file in downloaded artifact \ No newline at end of file diff --git a/tests/functionalSyncActions/run-sync-action-dbt-docs-missing-index/expected/data/out/files/.gitkeep b/tests/functionalSyncActions/run-sync-action-dbt-docs-missing-index/expected/data/out/files/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/tests/functionalSyncActions/run-sync-action-dbt-docs-missing-index/expected/data/out/tables/.gitkeep b/tests/functionalSyncActions/run-sync-action-dbt-docs-missing-index/expected/data/out/tables/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/tests/functionalSyncActions/run-sync-action-dbt-docs-missing-index/source/data/config.json b/tests/functionalSyncActions/run-sync-action-dbt-docs-missing-index/source/data/config.json new file mode 100644 index 00000000..caf22ec2 --- /dev/null +++ b/tests/functionalSyncActions/run-sync-action-dbt-docs-missing-index/source/data/config.json @@ -0,0 +1,7 @@ +{ + "componentId": "keboola.dbt-transformation", + "action": "dbtDocs", + "parameters": { + "configId": "12345" + } +}