recce-nightly 1.15.0.20250806__py3-none-any.whl → 1.26.0.20251124__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of recce-nightly might be problematic. Click here for more details.

Files changed (167) hide show
  1. recce/VERSION +1 -1
  2. recce/__init__.py +5 -0
  3. recce/adapter/dbt_adapter/__init__.py +12 -3
  4. recce/artifact.py +74 -1
  5. recce/cli.py +642 -101
  6. recce/config.py +2 -2
  7. recce/connect_to_cloud.py +1 -1
  8. recce/core.py +2 -2
  9. recce/data/404.html +1 -1
  10. recce/data/__next.__PAGE__.txt +10 -0
  11. recce/data/__next._full.txt +23 -0
  12. recce/data/__next._head.txt +8 -0
  13. recce/data/__next._index.txt +8 -0
  14. recce/data/__next._tree.txt +5 -0
  15. recce/data/_next/static/52aV_JrNUZU6dMFgvTQEO/_buildManifest.js +11 -0
  16. recce/data/_next/static/52aV_JrNUZU6dMFgvTQEO/_clientMiddlewareManifest.json +1 -0
  17. recce/data/_next/static/chunks/02b996c7f6a29a06.js +4 -0
  18. recce/data/_next/static/chunks/19c10d219a6a21ff.js +1 -0
  19. recce/data/_next/static/chunks/2df9ec28a061971d.js +11 -0
  20. recce/data/_next/static/chunks/3098c987393bda15.js +1 -0
  21. recce/data/_next/static/chunks/393dc43e483f717a.css +2 -0
  22. recce/data/_next/static/chunks/399e8d91a7e45073.js +2 -0
  23. recce/data/_next/static/chunks/4d0186f631230245.js +1 -0
  24. recce/data/_next/static/chunks/5794ba9e10a9c060.js +11 -0
  25. recce/data/_next/static/chunks/715761c929a3f28b.js +110 -0
  26. recce/data/_next/static/chunks/71f88fcc615bf282.js +1 -0
  27. recce/data/_next/static/chunks/80d2a95eaf1201ea.js +1 -0
  28. recce/data/_next/static/chunks/9979c6109bbbee35.js +1 -0
  29. recce/data/_next/static/chunks/99d638224186c118.js +1 -0
  30. recce/data/_next/static/chunks/d003eb36240e92f3.js +1 -0
  31. recce/data/_next/static/chunks/d3167cdfec4fc351.js +1 -0
  32. recce/data/_next/static/chunks/e124bccf574a3361.css +1 -0
  33. recce/data/_next/static/chunks/f40141db1bdb46f0.css +6 -0
  34. recce/data/_next/static/chunks/fcc53a88741a52f9.js +1 -0
  35. recce/data/_next/static/chunks/turbopack-b1920d28cfb1f28d.js +3 -0
  36. recce/data/_next/static/media/favicon.a8d38d84.ico +0 -0
  37. recce/data/_next/static/media/montserrat-cyrillic-800-normal.d80d830d.woff2 +0 -0
  38. recce/data/_next/static/media/{montserrat-cyrillic-800-normal.bd5c9f50.woff → montserrat-cyrillic-800-normal.f9d58125.woff} +0 -0
  39. recce/data/_next/static/media/montserrat-cyrillic-ext-800-normal.076c2a93.woff2 +0 -0
  40. recce/data/_next/static/media/montserrat-latin-800-normal.cde454cc.woff2 +0 -0
  41. recce/data/_next/static/media/{montserrat-latin-800-normal.fc315020.woff → montserrat-latin-800-normal.d5761935.woff} +0 -0
  42. recce/data/_next/static/media/montserrat-latin-ext-800-normal.40ec0659.woff2 +0 -0
  43. recce/data/_next/static/media/{montserrat-latin-ext-800-normal.2e5381b2.woff → montserrat-latin-ext-800-normal.b671449b.woff} +0 -0
  44. recce/data/_next/static/media/{montserrat-vietnamese-800-normal.20c545e6.woff → montserrat-vietnamese-800-normal.9f7b8541.woff} +0 -0
  45. recce/data/_next/static/media/montserrat-vietnamese-800-normal.f9eb854e.woff2 +0 -0
  46. recce/data/_not-found/__next._full.txt +17 -0
  47. recce/data/_not-found/__next._head.txt +8 -0
  48. recce/data/_not-found/__next._index.txt +8 -0
  49. recce/data/_not-found/__next._not-found.__PAGE__.txt +5 -0
  50. recce/data/_not-found/__next._not-found.txt +4 -0
  51. recce/data/_not-found/__next._tree.txt +3 -0
  52. recce/data/_not-found.html +1 -0
  53. recce/data/_not-found.txt +17 -0
  54. recce/data/index.html +1 -1
  55. recce/data/index.txt +21 -23
  56. recce/event/__init__.py +9 -8
  57. recce/event/collector.py +3 -1
  58. recce/event/track.py +10 -0
  59. recce/github.py +1 -1
  60. recce/mcp_server.py +716 -0
  61. recce/models/types.py +35 -2
  62. recce/pull_request.py +1 -1
  63. recce/run.py +2 -2
  64. recce/server.py +105 -3
  65. recce/state/__init__.py +31 -0
  66. recce/state/cloud.py +632 -0
  67. recce/state/const.py +26 -0
  68. recce/state/local.py +56 -0
  69. recce/state/state.py +119 -0
  70. recce/state/state_loader.py +174 -0
  71. recce/summary.py +21 -1
  72. recce/tasks/dataframe.py +63 -1
  73. recce/tasks/rowcount.py +4 -1
  74. recce/tasks/schema.py +4 -1
  75. recce/util/api_token.py +9 -2
  76. recce/util/breaking.py +1 -1
  77. recce/util/io.py +2 -2
  78. recce/util/lineage.py +14 -18
  79. recce/util/recce_cloud.py +187 -7
  80. recce/yaml/__init__.py +2 -2
  81. recce_cloud/__init__.py +24 -0
  82. recce_cloud/api/__init__.py +17 -0
  83. recce_cloud/api/base.py +111 -0
  84. recce_cloud/api/client.py +150 -0
  85. recce_cloud/api/exceptions.py +26 -0
  86. recce_cloud/api/factory.py +63 -0
  87. recce_cloud/api/github.py +76 -0
  88. recce_cloud/api/gitlab.py +82 -0
  89. recce_cloud/artifact.py +57 -0
  90. recce_cloud/ci_providers/__init__.py +9 -0
  91. recce_cloud/ci_providers/base.py +82 -0
  92. recce_cloud/ci_providers/detector.py +147 -0
  93. recce_cloud/ci_providers/github_actions.py +136 -0
  94. recce_cloud/ci_providers/gitlab_ci.py +130 -0
  95. recce_cloud/cli.py +245 -0
  96. recce_cloud/upload.py +214 -0
  97. {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/METADATA +54 -28
  98. recce_nightly-1.26.0.20251124.dist-info/RECORD +180 -0
  99. {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/top_level.txt +1 -0
  100. tests/adapter/dbt_adapter/test_dbt_cll.py +4 -2
  101. tests/recce_cloud/__init__.py +0 -0
  102. tests/recce_cloud/test_ci_providers.py +351 -0
  103. tests/recce_cloud/test_cli.py +372 -0
  104. tests/recce_cloud/test_client.py +273 -0
  105. tests/recce_cloud/test_platform_clients.py +333 -0
  106. tests/test_cli.py +106 -3
  107. tests/test_cli_mcp_optional.py +45 -0
  108. tests/test_cloud_listing_cli.py +324 -0
  109. tests/test_core.py +147 -0
  110. tests/test_mcp_server.py +332 -0
  111. tests/test_server.py +6 -6
  112. tests/test_summary.py +14 -6
  113. recce/data/_next/static/Q_5ThPsmamd4VAGXuqwgi/_buildManifest.js +0 -1
  114. recce/data/_next/static/chunks/0376eeba-3db2196398d62270.js +0 -1
  115. recce/data/_next/static/chunks/068b80ea-833a129468ee1622.js +0 -1
  116. recce/data/_next/static/chunks/0ddaf06c-c7961285f66460f6.js +0 -1
  117. recce/data/_next/static/chunks/1268aea1-6dc1251c01bd724b.js +0 -54
  118. recce/data/_next/static/chunks/12f8fac4-16838e42d28d45c3.js +0 -1
  119. recce/data/_next/static/chunks/235b8375-8c84c51d7bd4f6aa.js +0 -1
  120. recce/data/_next/static/chunks/2541941f-2cd3a7c2d629bd33.js +0 -1
  121. recce/data/_next/static/chunks/273-f3fa401bd2b6fc91.js +0 -10
  122. recce/data/_next/static/chunks/2fc37c1e-910deebeb3d77c90.js +0 -1
  123. recce/data/_next/static/chunks/338-2e7eed5135c64550.js +0 -30
  124. recce/data/_next/static/chunks/367-ab8b16dd5f8586ca.js +0 -1
  125. recce/data/_next/static/chunks/3a92ee20-0400ffe460c7c803.js +0 -1
  126. recce/data/_next/static/chunks/62446465-423c03bb8c1f59b6.js +0 -1
  127. recce/data/_next/static/chunks/6af7f9e9-60aa8706f49dae45.js +0 -1
  128. recce/data/_next/static/chunks/6cf54382-49d52ae6e564e2ac.js +0 -1
  129. recce/data/_next/static/chunks/6dc81886-78e2efe4538794ae.js +0 -1
  130. recce/data/_next/static/chunks/715e4acc-9e2e6df4eb3809d1.js +0 -1
  131. recce/data/_next/static/chunks/72-181b430654230f0e.js +0 -1
  132. recce/data/_next/static/chunks/786-774e3e3ed70a41b3.js +0 -1
  133. recce/data/_next/static/chunks/8d700b6a.7fe2c8c3f4e333a6.js +0 -1
  134. recce/data/_next/static/chunks/a69d64b4-d6890125a87b0aba.js +0 -1
  135. recce/data/_next/static/chunks/ae307f12-01100009689ace61.js +0 -1
  136. recce/data/_next/static/chunks/app/_not-found/page-c7ef8ed6dc07aaeb.js +0 -1
  137. recce/data/_next/static/chunks/app/layout-744f0a78e9e50e60.js +0 -1
  138. recce/data/_next/static/chunks/app/page-e8f798c2ae3f59c2.js +0 -1
  139. recce/data/_next/static/chunks/c0015c5c-82c219792582c104.js +0 -1
  140. recce/data/_next/static/chunks/d90cfbaa-e7d779b3912afeec.js +0 -1
  141. recce/data/_next/static/chunks/e07c302e-cd170429646873e1.js +0 -1
  142. recce/data/_next/static/chunks/fa5fb511-15fb438349ad5b97.js +0 -1
  143. recce/data/_next/static/chunks/framework-7950757d31580329.js +0 -1
  144. recce/data/_next/static/chunks/main-app-4df79eb11c34d43c.js +0 -1
  145. recce/data/_next/static/chunks/main-cd6c104af638214a.js +0 -1
  146. recce/data/_next/static/chunks/pages/_app-73008661edbd5e05.js +0 -1
  147. recce/data/_next/static/chunks/pages/_error-cf8bbdc3cf76c83f.js +0 -1
  148. recce/data/_next/static/chunks/webpack-84df6dd5ae3cf908.js +0 -1
  149. recce/data/_next/static/css/188a3a1687e2a064.css +0 -1
  150. recce/data/_next/static/css/8edca58d4abcf908.css +0 -14
  151. recce/data/_next/static/css/abdb9814a3dd18bb.css +0 -1
  152. recce/data/_next/static/css/c21263c1520b615b.css +0 -1
  153. recce/data/_next/static/media/montserrat-cyrillic-800-normal.22628180.woff2 +0 -0
  154. recce/data/_next/static/media/montserrat-cyrillic-ext-800-normal.94a63aea.woff2 +0 -0
  155. recce/data/_next/static/media/montserrat-latin-800-normal.6f8fa298.woff2 +0 -0
  156. recce/data/_next/static/media/montserrat-latin-ext-800-normal.013b84f9.woff2 +0 -0
  157. recce/data/_next/static/media/montserrat-vietnamese-800-normal.c0035377.woff2 +0 -0
  158. recce/state.py +0 -865
  159. recce_nightly-1.15.0.20250806.dist-info/RECORD +0 -156
  160. tests/test_state.py +0 -134
  161. /recce/data/_next/static/{Q_5ThPsmamd4VAGXuqwgi → 52aV_JrNUZU6dMFgvTQEO}/_ssgManifest.js +0 -0
  162. /recce/data/_next/static/chunks/{polyfills-42372ed130431b0a.js → a6dad97d9634a72d.js} +0 -0
  163. /recce/data/_next/static/media/{montserrat-cyrillic-ext-800-normal.e6e0d8d0.woff → montserrat-cyrillic-ext-800-normal.a4fa76b5.woff} +0 -0
  164. /recce/data/_next/static/media/{reload-image.79aabb7d.svg → reload-image.7aa931c7.svg} +0 -0
  165. {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/WHEEL +0 -0
  166. {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/entry_points.txt +0 -0
  167. {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,130 @@
1
+ """
2
+ GitLab CI/CD provider.
3
+ """
4
+
5
+ import os
6
+ from typing import Optional
7
+
8
+ from recce_cloud.ci_providers.base import BaseCIProvider, CIInfo
9
+
10
+
11
+ class GitLabCIProvider(BaseCIProvider):
12
+ """GitLab CI/CD provider implementation."""
13
+
14
+ def can_handle(self) -> bool:
15
+ """
16
+ Check if running in GitLab CI.
17
+
18
+ Returns:
19
+ True if GITLAB_CI environment variable is 'true'
20
+ """
21
+ return os.getenv("GITLAB_CI") == "true"
22
+
23
+ def extract_ci_info(self) -> CIInfo:
24
+ """
25
+ Extract CI information from GitLab CI environment.
26
+
27
+ Environment variables used:
28
+ - CI_MERGE_REQUEST_IID: Merge request number
29
+ - CI_COMMIT_SHA: Commit SHA
30
+ - CI_MERGE_REQUEST_TARGET_BRANCH_NAME: Target branch (MR only)
31
+ - CI_MERGE_REQUEST_SOURCE_BRANCH_NAME: Source branch (MR only)
32
+ - CI_COMMIT_REF_NAME: Branch name (fallback)
33
+ - CI_PROJECT_PATH: Repository path (group/project)
34
+ - CI_SERVER_URL: GitLab instance URL (defaults to https://gitlab.com)
35
+ - CI_JOB_TOKEN: Default access token (automatically provided by GitLab CI)
36
+
37
+ Returns:
38
+ CIInfo object with extracted information
39
+ """
40
+ cr_number = self._extract_mr_number()
41
+ commit_sha = self._extract_commit_sha()
42
+ base_branch = self._extract_base_branch()
43
+ source_branch = self._extract_source_branch()
44
+ repository = os.getenv("CI_PROJECT_PATH")
45
+ access_token = os.getenv("CI_JOB_TOKEN")
46
+
47
+ # Build CR URL (MR URL) if we have the necessary information
48
+ cr_url = None
49
+ if cr_number is not None and repository:
50
+ server_url = os.getenv("CI_SERVER_URL", "https://gitlab.com")
51
+ cr_url = f"{server_url}/{repository}/-/merge_requests/{cr_number}"
52
+
53
+ session_type = self.determine_session_type(cr_number, source_branch)
54
+
55
+ return CIInfo(
56
+ platform="gitlab-ci",
57
+ cr_number=cr_number,
58
+ cr_url=cr_url,
59
+ session_type=session_type,
60
+ commit_sha=commit_sha,
61
+ base_branch=base_branch,
62
+ source_branch=source_branch,
63
+ repository=repository,
64
+ access_token=access_token,
65
+ )
66
+
67
+ def _extract_mr_number(self) -> Optional[int]:
68
+ """
69
+ Extract MR number from GitLab CI environment.
70
+
71
+ Returns:
72
+ MR number if detected, None otherwise
73
+ """
74
+ mr_iid = os.getenv("CI_MERGE_REQUEST_IID")
75
+ if mr_iid:
76
+ try:
77
+ return int(mr_iid)
78
+ except ValueError:
79
+ pass
80
+
81
+ return None
82
+
83
+ def _extract_commit_sha(self) -> Optional[str]:
84
+ """
85
+ Extract commit SHA from GitLab CI environment.
86
+
87
+ Returns:
88
+ Commit SHA if detected, falls back to git command
89
+ """
90
+ commit_sha = os.getenv("CI_COMMIT_SHA")
91
+ if commit_sha:
92
+ return commit_sha
93
+
94
+ # Fallback to git command
95
+ return self.run_git_command(["git", "rev-parse", "HEAD"])
96
+
97
+ def _extract_base_branch(self) -> str:
98
+ """
99
+ Extract base/target branch from GitLab CI environment.
100
+
101
+ Returns:
102
+ Base branch name, defaults to 'main' if not detected
103
+ """
104
+ # CI_MERGE_REQUEST_TARGET_BRANCH_NAME is only set for merge request pipelines
105
+ base_branch = os.getenv("CI_MERGE_REQUEST_TARGET_BRANCH_NAME")
106
+ if base_branch:
107
+ return base_branch
108
+
109
+ # Default to main
110
+ return "main"
111
+
112
+ def _extract_source_branch(self) -> Optional[str]:
113
+ """
114
+ Extract source branch from GitLab CI environment.
115
+
116
+ Returns:
117
+ Source branch name if detected
118
+ """
119
+ # CI_MERGE_REQUEST_SOURCE_BRANCH_NAME is only set for merge request pipelines
120
+ source_branch = os.getenv("CI_MERGE_REQUEST_SOURCE_BRANCH_NAME")
121
+ if source_branch:
122
+ return source_branch
123
+
124
+ # Fallback to CI_COMMIT_REF_NAME
125
+ source_branch = os.getenv("CI_COMMIT_REF_NAME")
126
+ if source_branch:
127
+ return source_branch
128
+
129
+ # Fallback to git command
130
+ return self.run_git_command(["git", "branch", "--show-current"])
recce_cloud/cli.py ADDED
@@ -0,0 +1,245 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ Recce Cloud CLI - Lightweight command for managing Recce Cloud operations.
4
+ """
5
+
6
+ import logging
7
+ import os
8
+ import sys
9
+
10
+ import click
11
+ from rich.console import Console
12
+ from rich.logging import RichHandler
13
+
14
+ from recce_cloud import __version__
15
+ from recce_cloud.artifact import get_adapter_type, verify_artifacts_path
16
+ from recce_cloud.ci_providers import CIDetector
17
+ from recce_cloud.upload import upload_to_existing_session, upload_with_platform_apis
18
+
19
+ # Configure logging
20
+ logging.basicConfig(
21
+ level=logging.INFO,
22
+ format="%(message)s",
23
+ handlers=[RichHandler(console=Console(stderr=True), show_time=False, show_path=False)],
24
+ )
25
+ logger = logging.getLogger(__name__)
26
+
27
+ # Suppress CI detector logs since we display formatted output in the CLI
28
+ logging.getLogger("recce_cloud.ci_providers.detector").setLevel(logging.WARNING)
29
+
30
+
31
+ @click.group()
32
+ def cloud_cli():
33
+ """
34
+ Recce Cloud CLI - Manage Recce Cloud sessions and state files.
35
+
36
+ A lightweight tool for CI/CD environments to interact with Recce Cloud
37
+ without the heavy dependencies of the full recce package.
38
+ """
39
+ pass
40
+
41
+
42
+ @cloud_cli.command()
43
+ def version():
44
+ """Show the version of recce-cloud."""
45
+ click.echo(__version__)
46
+
47
+
48
+ @cloud_cli.command()
49
+ @click.option(
50
+ "--target-path",
51
+ type=click.Path(exists=True),
52
+ default="target",
53
+ help="Path to dbt target directory containing manifest.json and catalog.json",
54
+ )
55
+ @click.option(
56
+ "--session-id",
57
+ envvar="RECCE_SESSION_ID",
58
+ help="Recce Cloud session ID to upload artifacts to (or use RECCE_SESSION_ID env var). "
59
+ "If not provided, session will be created automatically using platform-specific APIs (GitHub/GitLab).",
60
+ )
61
+ @click.option(
62
+ "--cr",
63
+ type=int,
64
+ help="Change request number (PR/MR) (overrides auto-detection)",
65
+ )
66
+ @click.option(
67
+ "--type",
68
+ "session_type",
69
+ type=click.Choice(["cr", "prod", "dev"]),
70
+ help="Session type (overrides auto-detection)",
71
+ )
72
+ @click.option(
73
+ "--dry-run",
74
+ is_flag=True,
75
+ help="Show what would be uploaded without actually uploading",
76
+ )
77
+ def upload(target_path, session_id, cr, session_type, dry_run):
78
+ """
79
+ Upload dbt artifacts (manifest.json, catalog.json) to Recce Cloud.
80
+
81
+ \b
82
+ Authentication (auto-detected):
83
+ - RECCE_API_TOKEN (for --session-id workflow)
84
+ - GITHUB_TOKEN (GitHub Actions)
85
+ - CI_JOB_TOKEN (GitLab CI)
86
+
87
+ \b
88
+ Common Examples:
89
+ # Auto-create session in PR/MR
90
+ recce-cloud upload
91
+
92
+ # Upload production metadata from main branch
93
+ recce-cloud upload --type prod
94
+
95
+ # Upload to specific session
96
+ recce-cloud upload --session-id abc123
97
+
98
+ # Custom target path
99
+ recce-cloud upload --target-path custom-target
100
+ """
101
+ console = Console()
102
+
103
+ # 1. Auto-detect CI environment information
104
+ console.rule("CI Environment Detection", style="blue")
105
+ try:
106
+ ci_info = CIDetector.detect()
107
+ ci_info = CIDetector.apply_overrides(ci_info, cr=cr, session_type=session_type)
108
+
109
+ # Display detected CI information immediately
110
+ if ci_info:
111
+ info_table = []
112
+ if ci_info.platform:
113
+ info_table.append(f"[cyan]Platform:[/cyan] {ci_info.platform}")
114
+
115
+ # Display CR number as PR or MR based on platform
116
+ if ci_info.cr_number is not None:
117
+ if ci_info.platform == "github-actions":
118
+ info_table.append(f"[cyan]PR Number:[/cyan] {ci_info.cr_number}")
119
+ elif ci_info.platform == "gitlab-ci":
120
+ info_table.append(f"[cyan]MR Number:[/cyan] {ci_info.cr_number}")
121
+ else:
122
+ info_table.append(f"[cyan]CR Number:[/cyan] {ci_info.cr_number}")
123
+
124
+ # Display CR URL as PR URL or MR URL based on platform
125
+ if ci_info.cr_url:
126
+ if ci_info.platform == "github-actions":
127
+ info_table.append(f"[cyan]PR URL:[/cyan] {ci_info.cr_url}")
128
+ elif ci_info.platform == "gitlab-ci":
129
+ info_table.append(f"[cyan]MR URL:[/cyan] {ci_info.cr_url}")
130
+ else:
131
+ info_table.append(f"[cyan]CR URL:[/cyan] {ci_info.cr_url}")
132
+
133
+ if ci_info.session_type:
134
+ info_table.append(f"[cyan]Session Type:[/cyan] {ci_info.session_type}")
135
+ if ci_info.commit_sha:
136
+ info_table.append(f"[cyan]Commit SHA:[/cyan] {ci_info.commit_sha[:8]}...")
137
+ if ci_info.base_branch:
138
+ info_table.append(f"[cyan]Base Branch:[/cyan] {ci_info.base_branch}")
139
+ if ci_info.source_branch:
140
+ info_table.append(f"[cyan]Source Branch:[/cyan] {ci_info.source_branch}")
141
+ if ci_info.repository:
142
+ info_table.append(f"[cyan]Repository:[/cyan] {ci_info.repository}")
143
+
144
+ for line in info_table:
145
+ console.print(line)
146
+ else:
147
+ console.print("[yellow]No CI environment detected[/yellow]")
148
+ except Exception as e:
149
+ console.print(f"[yellow]Warning:[/yellow] Failed to detect CI environment: {e}")
150
+ console.print("Continuing without CI metadata...")
151
+ ci_info = None
152
+
153
+ # 2. Validate artifacts exist
154
+ if not verify_artifacts_path(target_path):
155
+ console.print(f"[red]Error:[/red] Invalid target path: {target_path}")
156
+ console.print("Please provide a valid target path containing manifest.json and catalog.json.")
157
+ sys.exit(3)
158
+
159
+ manifest_path = os.path.join(target_path, "manifest.json")
160
+ catalog_path = os.path.join(target_path, "catalog.json")
161
+
162
+ # 3. Extract adapter type from manifest
163
+ try:
164
+ adapter_type = get_adapter_type(manifest_path)
165
+ except Exception as e:
166
+ console.print("[red]Error:[/red] Failed to parse adapter type from manifest.json")
167
+ console.print(f"Reason: {e}")
168
+ sys.exit(3)
169
+
170
+ # 4. Handle dry-run mode (before authentication or API calls)
171
+ if dry_run:
172
+ console.rule("Dry Run Summary", style="yellow")
173
+ console.print("[yellow]Dry run mode enabled - no actual upload will be performed[/yellow]")
174
+ console.print()
175
+
176
+ # Display platform information if detected
177
+ if ci_info and ci_info.platform:
178
+ console.print("[cyan]Platform Information:[/cyan]")
179
+ console.print(f" • Platform: {ci_info.platform}")
180
+ if ci_info.repository:
181
+ console.print(f" • Repository: {ci_info.repository}")
182
+ if ci_info.cr_number is not None:
183
+ console.print(f" • CR Number: {ci_info.cr_number}")
184
+ if ci_info.commit_sha:
185
+ console.print(f" • Commit SHA: {ci_info.commit_sha[:8]}")
186
+ if ci_info.source_branch:
187
+ console.print(f" • Source Branch: {ci_info.source_branch}")
188
+ if ci_info.base_branch:
189
+ console.print(f" • Base Branch: {ci_info.base_branch}")
190
+ if ci_info.session_type:
191
+ console.print(f" • Session Type: {ci_info.session_type}")
192
+ console.print()
193
+
194
+ # Display upload summary
195
+ console.print("[cyan]Upload Workflow:[/cyan]")
196
+ if session_id:
197
+ console.print(" • Upload to existing session")
198
+ console.print(f" • Session ID: {session_id}")
199
+ else:
200
+ console.print(" • Auto-create session and upload")
201
+ if ci_info and ci_info.platform in ["github-actions", "gitlab-ci"]:
202
+ console.print(" • Platform-specific APIs will be used")
203
+ else:
204
+ console.print(" • [yellow]Warning: Platform not supported for auto-session creation[/yellow]")
205
+
206
+ console.print()
207
+ console.print("[cyan]Files to upload:[/cyan]")
208
+ console.print(f" • manifest.json: {os.path.abspath(manifest_path)}")
209
+ console.print(f" • catalog.json: {os.path.abspath(catalog_path)}")
210
+ console.print(f" • Adapter type: {adapter_type}")
211
+
212
+ console.print()
213
+ console.print("[green]✓[/green] Dry run completed successfully")
214
+ sys.exit(0)
215
+
216
+ # 5. Choose upload workflow based on whether session_id is provided
217
+ if session_id:
218
+ # Generic workflow: Upload to existing session using session ID
219
+ # This workflow requires RECCE_API_TOKEN
220
+ token = os.getenv("RECCE_API_TOKEN")
221
+ if not token:
222
+ console.print("[red]Error:[/red] No RECCE_API_TOKEN provided")
223
+ console.print("Set RECCE_API_TOKEN environment variable for session-based upload")
224
+ sys.exit(2)
225
+
226
+ upload_to_existing_session(console, token, session_id, manifest_path, catalog_path, adapter_type, target_path)
227
+ else:
228
+ # Platform-specific workflow: Use platform APIs to create session and upload
229
+ # This workflow MUST use CI job tokens (CI_JOB_TOKEN or GITHUB_TOKEN)
230
+ if not ci_info or not ci_info.access_token:
231
+ console.print("[red]Error:[/red] Platform-specific upload requires CI environment")
232
+ console.print("Either run in GitHub Actions/GitLab CI or provide --session-id for generic upload")
233
+ sys.exit(2)
234
+
235
+ token = ci_info.access_token
236
+ if ci_info.platform == "github-actions":
237
+ console.print("[cyan]Info:[/cyan] Using GITHUB_TOKEN for platform-specific authentication")
238
+ elif ci_info.platform == "gitlab-ci":
239
+ console.print("[cyan]Info:[/cyan] Using CI_JOB_TOKEN for platform-specific authentication")
240
+
241
+ upload_with_platform_apis(console, token, ci_info, manifest_path, catalog_path, adapter_type, target_path)
242
+
243
+
244
+ if __name__ == "__main__":
245
+ cloud_cli()
recce_cloud/upload.py ADDED
@@ -0,0 +1,214 @@
1
+ """
2
+ Upload helper functions for recce-cloud CLI.
3
+ """
4
+
5
+ import os
6
+ import sys
7
+
8
+ import requests
9
+
10
+ from recce_cloud.api.client import RecceCloudClient
11
+ from recce_cloud.api.exceptions import RecceCloudException
12
+ from recce_cloud.api.factory import create_platform_client
13
+
14
+
15
+ def upload_to_existing_session(
16
+ console, token: str, session_id: str, manifest_path: str, catalog_path: str, adapter_type: str, target_path: str
17
+ ):
18
+ """
19
+ Upload artifacts to an existing Recce Cloud session using session ID.
20
+
21
+ This is the generic workflow that requires a pre-existing session ID.
22
+ """
23
+ try:
24
+ client = RecceCloudClient(token)
25
+ except Exception as e:
26
+ console.print("[red]Error:[/red] Failed to initialize API client")
27
+ console.print(f"Reason: {e}")
28
+ sys.exit(2)
29
+
30
+ # Get session info (org_id, project_id)
31
+ console.print(f'Uploading artifacts for session ID "{session_id}"')
32
+ try:
33
+ session = client.get_session(session_id)
34
+ if session.get("status") == "error":
35
+ console.print(f"[red]Error:[/red] {session.get('message')}")
36
+ sys.exit(2)
37
+
38
+ org_id = session.get("org_id")
39
+ if org_id is None:
40
+ console.print(f"[red]Error:[/red] Session ID {session_id} does not belong to any organization.")
41
+ sys.exit(2)
42
+
43
+ project_id = session.get("project_id")
44
+ if project_id is None:
45
+ console.print(f"[red]Error:[/red] Session ID {session_id} does not belong to any project.")
46
+ sys.exit(2)
47
+
48
+ except RecceCloudException as e:
49
+ console.print("[red]Error:[/red] Failed to get session info")
50
+ console.print(f"Reason: {e.reason}")
51
+ sys.exit(2)
52
+ except Exception as e:
53
+ console.print("[red]Error:[/red] Failed to get session info")
54
+ console.print(f"Reason: {e}")
55
+ sys.exit(2)
56
+
57
+ # Get presigned URLs
58
+ try:
59
+ presigned_urls = client.get_upload_urls_by_session_id(org_id, project_id, session_id)
60
+ except RecceCloudException as e:
61
+ console.print("[red]Error:[/red] Failed to get upload URLs")
62
+ console.print(f"Reason: {e.reason}")
63
+ sys.exit(4)
64
+ except Exception as e:
65
+ console.print("[red]Error:[/red] Failed to get upload URLs")
66
+ console.print(f"Reason: {e}")
67
+ sys.exit(4)
68
+
69
+ # Upload manifest.json
70
+ console.print(f'Uploading manifest from path "{manifest_path}"')
71
+ try:
72
+ with open(manifest_path, "rb") as f:
73
+ response = requests.put(presigned_urls["manifest_url"], data=f.read())
74
+ if response.status_code not in [200, 204]:
75
+ raise Exception(f"Upload failed with status {response.status_code}: {response.text}")
76
+ except Exception as e:
77
+ console.print("[red]Error:[/red] Failed to upload manifest.json")
78
+ console.print(f"Reason: {e}")
79
+ sys.exit(4)
80
+
81
+ # Upload catalog.json
82
+ console.print(f'Uploading catalog from path "{catalog_path}"')
83
+ try:
84
+ with open(catalog_path, "rb") as f:
85
+ response = requests.put(presigned_urls["catalog_url"], data=f.read())
86
+ if response.status_code not in [200, 204]:
87
+ raise Exception(f"Upload failed with status {response.status_code}: {response.text}")
88
+ except Exception as e:
89
+ console.print("[red]Error:[/red] Failed to upload catalog.json")
90
+ console.print(f"Reason: {e}")
91
+ sys.exit(4)
92
+
93
+ # Update session metadata
94
+ try:
95
+ client.update_session(org_id, project_id, session_id, adapter_type)
96
+ except RecceCloudException as e:
97
+ console.print("[red]Error:[/red] Failed to update session metadata")
98
+ console.print(f"Reason: {e.reason}")
99
+ sys.exit(4)
100
+ except Exception as e:
101
+ console.print("[red]Error:[/red] Failed to update session metadata")
102
+ console.print(f"Reason: {e}")
103
+ sys.exit(4)
104
+
105
+ # Success!
106
+ console.rule("Uploaded Successfully", style="green")
107
+ console.print(
108
+ f'Uploaded dbt artifacts to Recce Cloud for session ID "{session_id}" from "{os.path.abspath(target_path)}"'
109
+ )
110
+ sys.exit(0)
111
+
112
+
113
+ def upload_with_platform_apis(
114
+ console, token: str, ci_info, manifest_path: str, catalog_path: str, adapter_type: str, target_path: str
115
+ ):
116
+ """
117
+ Upload artifacts using platform-specific APIs (GitHub Actions or GitLab CI).
118
+
119
+ This workflow uses touch-recce-session to create a session automatically.
120
+ """
121
+ # Validate platform support
122
+ if ci_info.platform not in ["github-actions", "gitlab-ci"]:
123
+ console.print("[red]Error:[/red] Platform-specific upload requires GitHub Actions or GitLab CI environment")
124
+ console.print(f"Detected platform: {ci_info.platform or 'unknown'}")
125
+ console.print(
126
+ "Either run this command in a supported CI environment or provide --session-id for generic upload"
127
+ )
128
+ sys.exit(1)
129
+
130
+ # Create platform-specific client
131
+ try:
132
+ client = create_platform_client(token, ci_info)
133
+ except ValueError as e:
134
+ console.print("[red]Error:[/red] Failed to create platform client")
135
+ console.print(f"Reason: {e}")
136
+ sys.exit(2)
137
+
138
+ # Touch session to create or get session ID
139
+ console.rule("Creating/touching session", style="blue")
140
+ try:
141
+ session_response = client.touch_recce_session(
142
+ branch=ci_info.source_branch or ci_info.base_branch or "main",
143
+ adapter_type=adapter_type,
144
+ cr_number=ci_info.cr_number,
145
+ commit_sha=ci_info.commit_sha,
146
+ session_type=ci_info.session_type,
147
+ )
148
+
149
+ session_id = session_response.get("session_id")
150
+ manifest_upload_url = session_response.get("manifest_upload_url")
151
+ catalog_upload_url = session_response.get("catalog_upload_url")
152
+
153
+ if not session_id or not manifest_upload_url or not catalog_upload_url:
154
+ console.print("[red]Error:[/red] Incomplete response from touch-recce-session API")
155
+ console.print(f"Response: {session_response}")
156
+ sys.exit(4)
157
+
158
+ console.print(f"[green]Session ID:[/green] {session_id}")
159
+
160
+ except RecceCloudException as e:
161
+ console.print("[red]Error:[/red] Failed to create/touch session")
162
+ console.print(f"Reason: {e.reason}")
163
+ sys.exit(4)
164
+ except Exception as e:
165
+ console.print("[red]Error:[/red] Failed to create/touch session")
166
+ console.print(f"Reason: {e}")
167
+ sys.exit(4)
168
+
169
+ # Upload manifest.json
170
+ console.print(f'Uploading manifest from path "{manifest_path}"')
171
+ try:
172
+ with open(manifest_path, "rb") as f:
173
+ response = requests.put(manifest_upload_url, data=f.read())
174
+ if response.status_code not in [200, 204]:
175
+ raise Exception(f"Upload failed with status {response.status_code}: {response.text}")
176
+ except Exception as e:
177
+ console.print("[red]Error:[/red] Failed to upload manifest.json")
178
+ console.print(f"Reason: {e}")
179
+ sys.exit(4)
180
+
181
+ # Upload catalog.json
182
+ console.print(f'Uploading catalog from path "{catalog_path}"')
183
+ try:
184
+ with open(catalog_path, "rb") as f:
185
+ response = requests.put(catalog_upload_url, data=f.read())
186
+ if response.status_code not in [200, 204]:
187
+ raise Exception(f"Upload failed with status {response.status_code}: {response.text}")
188
+ except Exception as e:
189
+ console.print("[red]Error:[/red] Failed to upload catalog.json")
190
+ console.print(f"Reason: {e}")
191
+ sys.exit(4)
192
+
193
+ # Notify upload completion
194
+ console.print("Notifying upload completion...")
195
+ try:
196
+ client.upload_completed(session_id=session_id, commit_sha=ci_info.commit_sha)
197
+ except RecceCloudException as e:
198
+ console.print("[yellow]Warning:[/yellow] Failed to notify upload completion")
199
+ console.print(f"Reason: {e.reason}")
200
+ # Non-fatal, continue
201
+ except Exception as e:
202
+ console.print("[yellow]Warning:[/yellow] Failed to notify upload completion")
203
+ console.print(f"Reason: {e}")
204
+ # Non-fatal, continue
205
+
206
+ # Success!
207
+ console.rule("Uploaded Successfully", style="green")
208
+ console.print(f'Uploaded dbt artifacts to Recce Cloud for session ID "{session_id}"')
209
+ console.print(f'Artifacts from: "{os.path.abspath(target_path)}"')
210
+
211
+ if ci_info.cr_url:
212
+ console.print(f"Change request: {ci_info.cr_url}")
213
+
214
+ sys.exit(0)