superset-showtime 0.5.9__tar.gz → 0.5.11__tar.gz

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 superset-showtime might be problematic. Click here for more details.

Files changed (35) hide show
  1. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/.claude/settings.local.json +4 -2
  2. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/CLAUDE.md +65 -0
  3. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/PKG-INFO +1 -1
  4. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/showtime/__init__.py +1 -1
  5. superset_showtime-0.5.11/showtime/core/git_validation.py +201 -0
  6. superset_showtime-0.5.9/showtime/core/git_validation.py +0 -127
  7. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/.gitignore +0 -0
  8. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/.pre-commit-config.yaml +0 -0
  9. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/Makefile +0 -0
  10. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/README.md +0 -0
  11. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/dev-setup.sh +0 -0
  12. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/pypi-push.sh +0 -0
  13. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/pyproject.toml +0 -0
  14. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/requirements-dev.txt +0 -0
  15. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/requirements.txt +0 -0
  16. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/showtime/__main__.py +0 -0
  17. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/showtime/cli.py +0 -0
  18. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/showtime/core/__init__.py +0 -0
  19. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/showtime/core/aws.py +0 -0
  20. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/showtime/core/emojis.py +0 -0
  21. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/showtime/core/github.py +0 -0
  22. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/showtime/core/github_messages.py +0 -0
  23. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/showtime/core/label_colors.py +0 -0
  24. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/showtime/core/pull_request.py +0 -0
  25. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/showtime/core/show.py +0 -0
  26. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/showtime/data/ecs-task-definition.json +0 -0
  27. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/tests/__init__.py +0 -0
  28. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/tests/unit/__init__.py +0 -0
  29. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/tests/unit/test_label_transitions.py +0 -0
  30. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/tests/unit/test_pull_request.py +0 -0
  31. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/tests/unit/test_sha_specific_logic.py +0 -0
  32. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/tests/unit/test_show.py +0 -0
  33. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/uv.lock +0 -0
  34. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/workflows-reference/showtime-cleanup.yml +0 -0
  35. {superset_showtime-0.5.9 → superset_showtime-0.5.11}/workflows-reference/showtime-trigger.yml +0 -0
@@ -43,12 +43,14 @@
43
43
  "Bash(showtime sync:*)",
44
44
  "Bash(AWS_PROFILE=\"\" showtime sync 34831 --dry-run-aws --dry-run-github)",
45
45
  "Bash(git stash:*)",
46
- "Bash(showtime list:*)"
46
+ "Bash(showtime list:*)",
47
+ "Bash(showtime git-check)"
47
48
  ],
48
49
  "deny": [],
49
50
  "ask": [],
50
51
  "additionalDirectories": [
51
- "/private/tmp"
52
+ "/private/tmp",
53
+ "/Users/max/code/superset"
52
54
  ]
53
55
  }
54
56
  }
@@ -164,3 +164,68 @@ showtime list --status running
164
164
  showtime start 1234 --sha abc123f
165
165
  showtime stop 1234 --force
166
166
  ```
167
+
168
+ ## Race Condition Handling
169
+
170
+ ### Problem Description
171
+
172
+ Double triggers can create race conditions in two scenarios:
173
+
174
+ 1. **Same SHA conflicts**: User pushes commit abc123f twice, creating 2 workflows for identical SHA
175
+ 2. **Stale locks**: Jobs crash or get killed, leaving environments stuck in "building/deploying" state indefinitely
176
+
177
+ ### Current Atomic Claim Mechanism
178
+
179
+ The `PullRequest._atomic_claim()` method handles basic conflicts by:
180
+ 1. Checking if target SHA is already in progress states (`building`, `built`, `deploying`)
181
+ 2. Removing trigger labels atomically
182
+ 3. Setting building state immediately
183
+
184
+ **Limitations**:
185
+ - No distinction between valid locks and stale locks (>1 hour old)
186
+ - `refresh_labels()` is expensive (~500ms) but called on every claim attempt
187
+ - Crashed jobs can leave permanent locks that block future deployments
188
+
189
+ ### Proposed Smart Lock Detection Strategy
190
+
191
+ **Two-phase approach optimizing for the common case**:
192
+
193
+ #### Phase 1: Fast Path (95% of calls, ~5ms)
194
+ ```python
195
+ def can_start_job(self, target_sha: str, action: str, use_cached: bool = True) -> tuple[bool, str]:
196
+ """Fast check using cached self.labels"""
197
+ # Check cached labels for basic conflicts
198
+ # Returns (can_start, reason)
199
+ ```
200
+
201
+ #### Phase 2: Recovery Path (5% of calls, ~500ms)
202
+ ```python
203
+ def double_check_and_cleanup_stale_locks(self, target_sha: str, stale_hours: int = 1, dry_run: bool = False) -> bool:
204
+ """Expensive: refresh labels, detect stale locks (>1h), clean them up"""
205
+ # Only called when fast path detects potential conflict
206
+ # Refreshes labels, checks timestamps, cleans stale AWS resources + GitHub labels
207
+ ```
208
+
209
+ #### Enhanced Atomic Claim Logic
210
+ ```python
211
+ def _atomic_claim(self, target_sha: str, action: str, dry_run: bool = False) -> bool:
212
+ # 1. Fast check with cached labels
213
+ can_start, reason = self.can_start_job(target_sha, action, use_cached=True)
214
+
215
+ if not can_start:
216
+ # 2. Expensive double-check and cleanup
217
+ can_start = self.double_check_and_cleanup_stale_locks(target_sha, stale_hours=1, dry_run=dry_run)
218
+
219
+ # 3. Continue with existing trigger removal + building setup
220
+ ```
221
+
222
+ ### Key Benefits
223
+
224
+ - **Performance**: 95% fast path using cached labels (~5ms vs ~500ms)
225
+ - **Reliability**: Automatic recovery from stale locks (crashed/killed jobs)
226
+ - **Clarity**: Clear distinction between valid conflicts and recoverable states
227
+ - **Safety**: Only cleans locks older than configurable threshold (default: 1 hour)
228
+
229
+ ### Implementation Notes
230
+
231
+ This enhancement can be implemented when race conditions become problematic in practice. The current trigger removal mechanism already handles most same-SHA conflicts effectively due to the speed of GitHub label operations.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: superset-showtime
3
- Version: 0.5.9
3
+ Version: 0.5.11
4
4
  Summary: 🎪 Apache Superset ephemeral environment management with circus tent emoji state tracking
5
5
  Project-URL: Homepage, https://github.com/apache/superset-showtime
6
6
  Project-URL: Documentation, https://superset-showtime.readthedocs.io/
@@ -4,7 +4,7 @@
4
4
  Circus tent emoji state tracking for Apache Superset ephemeral environments.
5
5
  """
6
6
 
7
- __version__ = "0.5.9"
7
+ __version__ = "0.5.11"
8
8
  __author__ = "Maxime Beauchemin"
9
9
  __email__ = "maximebeauchemin@gmail.com"
10
10
 
@@ -0,0 +1,201 @@
1
+ """
2
+ 🎪 Git SHA Validation for Superset Showtime
3
+
4
+ Validates that the current Git repository contains required commit SHA to prevent
5
+ usage with outdated releases.
6
+ """
7
+
8
+ from typing import Optional, Tuple
9
+
10
+ try:
11
+ from git import InvalidGitRepositoryError, Repo
12
+ except ImportError:
13
+ # Fallback if GitPython is not available
14
+ Repo = None
15
+ InvalidGitRepositoryError = Exception
16
+
17
+
18
+ # Hard-coded required SHA - update this when needed
19
+ # https://github.com/apache/superset/commit/47414e18d4c2980d0cc4718b3e704845f7dfd356
20
+ REQUIRED_SHA = "47414e18d4c2980d0cc4718b3e704845f7dfd356"
21
+
22
+
23
+ class GitValidationError(Exception):
24
+ """Raised when Git validation fails"""
25
+
26
+ pass
27
+
28
+
29
+ def is_git_repository(path: str = ".") -> bool:
30
+ """
31
+ Check if the current directory (or specified path) is a Git repository.
32
+
33
+ Args:
34
+ path: Path to check (default: current directory)
35
+
36
+ Returns:
37
+ True if it's a Git repository, False otherwise
38
+ """
39
+ if Repo is None:
40
+ # GitPython not available, assume not a git repo
41
+ return False
42
+
43
+ try:
44
+ Repo(path)
45
+ return True
46
+ except (InvalidGitRepositoryError, Exception):
47
+ return False
48
+
49
+
50
+ def validate_required_sha(required_sha: Optional[str] = None) -> Tuple[bool, Optional[str]]:
51
+ """
52
+ Validate that the required SHA exists in the current Git repository.
53
+ Uses GitHub API for reliable validation in shallow clone environments.
54
+
55
+ Args:
56
+ required_sha: SHA to validate (default: REQUIRED_SHA constant)
57
+
58
+ Returns:
59
+ Tuple of (is_valid, error_message)
60
+ - (True, None) if validation passes
61
+ - (False, error_message) if validation fails
62
+ """
63
+ sha_to_check = required_sha or REQUIRED_SHA
64
+ if not sha_to_check:
65
+ return True, None # No requirement set
66
+
67
+ # Try GitHub API validation first (works in shallow clones)
68
+ try:
69
+ return _validate_sha_via_github_api(sha_to_check)
70
+ except Exception as e:
71
+ print(f"⚠️ GitHub API validation failed: {e}")
72
+
73
+ # Fallback to Git validation for non-GitHub origins
74
+ if Repo is None:
75
+ print("⚠️ GitPython not available, skipping SHA validation")
76
+ return True, None
77
+
78
+ try:
79
+ repo = Repo(".")
80
+ is_valid, error = _validate_sha_in_log(repo, sha_to_check)
81
+ if is_valid:
82
+ return True, None
83
+ else:
84
+ print(f"⚠️ Git validation failed: {error}")
85
+ return True, None # Allow operation to continue
86
+
87
+ except InvalidGitRepositoryError:
88
+ print("⚠️ Not a Git repository, skipping SHA validation")
89
+ return True, None
90
+ except Exception as e:
91
+ print(f"⚠️ Git validation error: {e}")
92
+ return True, None
93
+
94
+
95
+ def _validate_sha_via_github_api(required_sha: str) -> Tuple[bool, Optional[str]]:
96
+ """Validate SHA using GitHub API - works reliably in shallow clones"""
97
+ try:
98
+ import httpx
99
+ from git import Repo
100
+
101
+ from .github import GitHubInterface
102
+
103
+ # Get current SHA from Git
104
+ repo = Repo(".")
105
+ current_sha = repo.head.commit.hexsha
106
+
107
+ # Use existing GitHubInterface (handles all the setup/token detection)
108
+ github = GitHubInterface()
109
+
110
+ # 1. Check if required SHA exists
111
+ commit_url = f"{github.base_url}/repos/{github.org}/{github.repo}/commits/{required_sha}"
112
+
113
+ with httpx.Client() as client:
114
+ response = client.get(commit_url, headers=github.headers)
115
+ if response.status_code == 404:
116
+ return False, f"Required SHA {required_sha[:7]} not found in repository"
117
+ response.raise_for_status()
118
+
119
+ # 2. Compare SHAs to verify ancestry
120
+ compare_url = f"{github.base_url}/repos/{github.org}/{github.repo}/compare/{required_sha}...{current_sha}"
121
+
122
+ with httpx.Client() as client:
123
+ response = client.get(compare_url, headers=github.headers)
124
+ if response.status_code == 404:
125
+ return (
126
+ False,
127
+ f"Current branch does not include required SHA {required_sha[:7]}. Please rebase onto main.",
128
+ )
129
+ response.raise_for_status()
130
+
131
+ data = response.json()
132
+ status = data.get("status")
133
+
134
+ # If status is 'ahead' or 'identical', required SHA is ancestor (good)
135
+ # If status is 'behind', current is behind required (bad)
136
+ if status in ["ahead", "identical"]:
137
+ return True, None
138
+ else:
139
+ return (
140
+ False,
141
+ f"Current branch does not include required SHA {required_sha[:7]}. Please rebase onto main.",
142
+ )
143
+
144
+ except Exception as e:
145
+ # Re-raise to be caught by the caller for proper fallback handling
146
+ raise Exception(f"GitHub API validation error: {e}") from e
147
+
148
+
149
+ def _validate_sha_in_log(repo: "Repo", sha_to_check: str) -> Tuple[bool, Optional[str]]:
150
+ """Helper function to validate SHA exists in git log output."""
151
+ try:
152
+ log_output = repo.git.log("--oneline", "--all")
153
+ if sha_to_check in log_output or sha_to_check[:7] in log_output:
154
+ return True, None
155
+ else:
156
+ return False, (
157
+ f"Required commit {sha_to_check} not found in Git history. "
158
+ f"Please update to a branch that includes this commit."
159
+ )
160
+ except Exception as e:
161
+ return False, f"Git log search failed: {e}"
162
+
163
+
164
+ def get_validation_error_message(required_sha: Optional[str] = None) -> str:
165
+ """
166
+ Get a user-friendly error message for SHA validation failure.
167
+
168
+ Args:
169
+ required_sha: SHA that was required (default: REQUIRED_SHA)
170
+
171
+ Returns:
172
+ Formatted error message with resolution steps
173
+ """
174
+ sha_to_check = required_sha or REQUIRED_SHA
175
+
176
+ return f"""
177
+ 🎪 [bold red]Git SHA Validation Failed[/bold red]
178
+
179
+ This branch requires commit {sha_to_check} to be present in your Git history.
180
+
181
+ [bold yellow]To resolve this:[/bold yellow]
182
+ 1. Ensure you're on the correct branch (usually main)
183
+ 2. Pull the latest changes: [cyan]git pull origin main[/cyan]
184
+ 3. Verify the commit exists: [cyan]git log --oneline | grep {sha_to_check[:7]}[/cyan]
185
+ 4. If needed, switch to main branch: [cyan]git checkout main[/cyan]
186
+
187
+ [dim]This check prevents Showtime from running on outdated releases.[/dim]
188
+ """.strip()
189
+
190
+
191
+ def should_skip_validation() -> bool:
192
+ """
193
+ Determine if Git validation should be skipped.
194
+
195
+ Currently skips validation when not in a Git repository,
196
+ allowing --check-only to work in non-Git environments.
197
+
198
+ Returns:
199
+ True if validation should be skipped
200
+ """
201
+ return not is_git_repository()
@@ -1,127 +0,0 @@
1
- """
2
- 🎪 Git SHA Validation for Superset Showtime
3
-
4
- Validates that the current Git repository contains required commit SHA to prevent
5
- usage with outdated releases.
6
- """
7
-
8
- from typing import Optional, Tuple
9
-
10
- try:
11
- from git import InvalidGitRepositoryError, Repo
12
- except ImportError:
13
- # Fallback if GitPython is not available
14
- Repo = None
15
- InvalidGitRepositoryError = Exception
16
-
17
-
18
- # Hard-coded required SHA - update this when needed
19
- REQUIRED_SHA = "277f03c2075a74fbafb55531054fb5083debe5cc" # Placeholder SHA for testing
20
-
21
-
22
- class GitValidationError(Exception):
23
- """Raised when Git validation fails"""
24
-
25
- pass
26
-
27
-
28
- def is_git_repository(path: str = ".") -> bool:
29
- """
30
- Check if the current directory (or specified path) is a Git repository.
31
-
32
- Args:
33
- path: Path to check (default: current directory)
34
-
35
- Returns:
36
- True if it's a Git repository, False otherwise
37
- """
38
- if Repo is None:
39
- # GitPython not available, assume not a git repo
40
- return False
41
-
42
- try:
43
- Repo(path)
44
- return True
45
- except (InvalidGitRepositoryError, Exception):
46
- return False
47
-
48
-
49
- def validate_required_sha(required_sha: Optional[str] = None) -> Tuple[bool, Optional[str]]:
50
- """
51
- Validate that the required SHA exists in the current Git repository.
52
-
53
- Args:
54
- required_sha: SHA to validate (default: REQUIRED_SHA constant)
55
-
56
- Returns:
57
- Tuple of (is_valid, error_message)
58
- - (True, None) if validation passes
59
- - (False, error_message) if validation fails
60
- """
61
- if Repo is None:
62
- return False, "GitPython not available for SHA validation"
63
-
64
- sha_to_check = required_sha or REQUIRED_SHA
65
- if not sha_to_check:
66
- return True, None # No requirement set
67
-
68
- try:
69
- repo = Repo(".")
70
-
71
- # Search for SHA in git log (has to work in shallow clones where merge_base fails)
72
- try:
73
- log_output = repo.git.log("--oneline", "--all")
74
- if sha_to_check in log_output or sha_to_check[:7] in log_output:
75
- return True, None
76
- else:
77
- return False, (
78
- f"Required commit {sha_to_check} not found in Git history. "
79
- f"Please update to a branch that includes this commit."
80
- )
81
- except Exception as e:
82
- return False, f"Git log search failed: {e}"
83
-
84
- except InvalidGitRepositoryError:
85
- return False, "Current directory is not a Git repository"
86
- except Exception as e:
87
- return False, f"Git validation error: {e}"
88
-
89
-
90
- def get_validation_error_message(required_sha: Optional[str] = None) -> str:
91
- """
92
- Get a user-friendly error message for SHA validation failure.
93
-
94
- Args:
95
- required_sha: SHA that was required (default: REQUIRED_SHA)
96
-
97
- Returns:
98
- Formatted error message with resolution steps
99
- """
100
- sha_to_check = required_sha or REQUIRED_SHA
101
-
102
- return f"""
103
- 🎪 [bold red]Git SHA Validation Failed[/bold red]
104
-
105
- This branch requires commit {sha_to_check} to be present in your Git history.
106
-
107
- [bold yellow]To resolve this:[/bold yellow]
108
- 1. Ensure you're on the correct branch (usually main)
109
- 2. Pull the latest changes: [cyan]git pull origin main[/cyan]
110
- 3. Verify the commit exists: [cyan]git log --oneline | grep {sha_to_check[:7]}[/cyan]
111
- 4. If needed, switch to main branch: [cyan]git checkout main[/cyan]
112
-
113
- [dim]This check prevents Showtime from running on outdated releases.[/dim]
114
- """.strip()
115
-
116
-
117
- def should_skip_validation() -> bool:
118
- """
119
- Determine if Git validation should be skipped.
120
-
121
- Currently skips validation when not in a Git repository,
122
- allowing --check-only to work in non-Git environments.
123
-
124
- Returns:
125
- True if validation should be skipped
126
- """
127
- return not is_git_repository()