Skip to content

Commit 6a4ac75

Browse files
author
Taniya Mathur
committed
publish script improvements
1 parent 6997084 commit 6a4ac75

File tree

3 files changed

+191
-568
lines changed

3 files changed

+191
-568
lines changed

lib/idp_common_pkg/tests/unit/test_publish.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,7 @@ def test_run_minimal_success_flow(self):
10441044
patch.object(publisher, "check_parameters") as mock_check_params,
10451045
patch.object(publisher, "setup_environment") as mock_setup_env,
10461046
patch.object(publisher, "check_prerequisites") as mock_check_prereq,
1047+
patch.object(publisher, "ensure_aws_sam_directory") as mock_ensure_sam,
10471048
patch.object(publisher, "setup_artifacts_bucket") as mock_setup_bucket,
10481049
patch.object(publisher, "clean_temp_files"),
10491050
patch.object(publisher, "clean_lib"),
@@ -1072,6 +1073,7 @@ def test_run_minimal_success_flow(self):
10721073
mock_check_params.assert_called_once()
10731074
mock_setup_env.assert_called_once()
10741075
mock_check_prereq.assert_called_once()
1076+
mock_ensure_sam.assert_called_once()
10751077
mock_setup_bucket.assert_called_once()
10761078
mock_build_patterns.assert_called_once()
10771079
mock_build_options.assert_called_once()
@@ -1121,6 +1123,7 @@ def test_run_pattern_build_failure(self):
11211123
patch.object(publisher, "check_parameters"),
11221124
patch.object(publisher, "setup_environment"),
11231125
patch.object(publisher, "check_prerequisites"),
1126+
patch.object(publisher, "ensure_aws_sam_directory"),
11241127
patch.object(publisher, "setup_artifacts_bucket"),
11251128
patch.object(publisher, "clean_temp_files"),
11261129
patch.object(publisher, "clean_lib"),

publish.py

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
TextColumn,
3636
TimeElapsedColumn,
3737
)
38-
from rich.table import Table
3938

4039

4140
class IDPPublisher:
@@ -269,6 +268,22 @@ def check_prerequisites(self):
269268
)
270269
sys.exit(1)
271270

271+
def ensure_aws_sam_directory(self):
272+
"""Ensure .aws-sam directory exists"""
273+
aws_sam_dir = ".aws-sam"
274+
275+
if not os.path.exists(aws_sam_dir):
276+
self.console.print(
277+
"[yellow].aws-sam directory not found. Creating it...[/yellow]"
278+
)
279+
os.makedirs(aws_sam_dir, exist_ok=True)
280+
self.console.print(
281+
"[green]✅ Successfully created .aws-sam directory[/green]"
282+
)
283+
else:
284+
if self.verbose:
285+
self.console.print("[dim].aws-sam directory already exists[/dim]")
286+
272287
def version_compare(self, version1, version2):
273288
"""Compare two version strings. Returns -1 if v1 < v2, 0 if equal, 1 if v1 > v2"""
274289

@@ -480,6 +495,17 @@ def get_stored_checksum(self, directory):
480495

481496
def needs_rebuild(self, *paths):
482497
"""Check if any of the paths have changed since last build"""
498+
# Special case for ./lib directory - use .lib_checksum in root and get_directory_checksum
499+
if len(paths) == 1 and paths[0] == "./lib":
500+
current_checksum = self.get_directory_checksum("./lib")
501+
checksum_file = ".lib_checksum"
502+
if os.path.exists(checksum_file):
503+
with open(checksum_file, "r") as f:
504+
stored_checksum = f.read().strip()
505+
return current_checksum != stored_checksum
506+
return True
507+
508+
# For all other cases, use get_checksum
483509
current_checksum = self.get_checksum(*paths)
484510

485511
# For single directory, check its stored checksum
@@ -1186,30 +1212,7 @@ def print_outputs(self):
11861212
encoded_template_url = quote(template_url, safe=":/?#[]@!$&'()*+,;=")
11871213
launch_url = f"https://{self.region}.console.aws.amazon.com/cloudformation/home?region={self.region}#/stacks/create/review?templateURL={encoded_template_url}&stackName=IDP"
11881214

1189-
# First, display URLs in plain text to avoid Rich formatting issues
1190-
self.console.print("\n[bold green]Deployment Outputs[/bold green]")
1191-
self.console.print("[cyan]Template URL (use to update existing stack):[/cyan]")
1192-
self.console.print(f"{template_url}")
1193-
self.console.print(
1194-
"\n[cyan]1-Click Launch URL (use to launch new stack):[/cyan]"
1195-
)
1196-
self.console.print(f"{launch_url}")
1197-
1198-
# Also display in a table with clickable links
1199-
table = Table(title="[bold green]Quick Links[/bold green]", show_lines=True)
1200-
table.add_column("Link", style="cyan", no_wrap=False, width=60)
1201-
table.add_column("Description", style="yellow", width=40)
1202-
1203-
# Create clickable links using Rich's link syntax
1204-
template_link = f"[link={template_url}]Template URL[/link]"
1205-
launch_link = f"[link={launch_url}]1-Click Launch[/link]"
1206-
1207-
table.add_row(template_link, "Go to cloudformation and update existing stack")
1208-
table.add_row(launch_link, "Use to launch new stack")
1209-
1210-
self.console.print(table)
1211-
1212-
# Additional information for troubleshooting
1215+
# Display deployment information first
12131216
self.console.print("\n[bold cyan]Deployment Information:[/bold cyan]")
12141217
self.console.print(f" • Region: [yellow]{self.region}[/yellow]")
12151218
self.console.print(f" • Bucket: [yellow]{self.bucket}[/yellow]")
@@ -1220,6 +1223,15 @@ def print_outputs(self):
12201223
f" • Public Access: [yellow]{'Yes' if self.public else 'No'}[/yellow]"
12211224
)
12221225

1226+
# Then display URLs
1227+
self.console.print("\n[bold green]Deployment Outputs[/bold green]")
1228+
self.console.print("[cyan]Template URL (use to update existing stack):[/cyan]")
1229+
self.console.print(f"{template_url}")
1230+
self.console.print(
1231+
"\n[cyan]1-Click Launch URL (use to launch new stack):[/cyan]"
1232+
)
1233+
self.console.print(f"{launch_url}")
1234+
12231235
def run(self, args):
12241236
"""Main execution method"""
12251237
try:
@@ -1232,6 +1244,9 @@ def run(self, args):
12321244
# Check prerequisites
12331245
self.check_prerequisites()
12341246

1247+
# Ensure .aws-sam directory exists
1248+
self.ensure_aws_sam_directory()
1249+
12351250
# Set up S3 bucket
12361251
self.setup_artifacts_bucket()
12371252

0 commit comments

Comments
 (0)