Skip to content

Commit a239677

Browse files
author
Taniya Mathur
committed
Fix missing idp-main.yaml in S3 when cache exists
1 parent a82d80d commit a239677

File tree

1 file changed

+43
-26
lines changed

1 file changed

+43
-26
lines changed

publish.py

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,31 +1625,6 @@ def build_main_template(self, webui_zipfile):
16251625
finally:
16261626
os.chdir(original_cwd)
16271627

1628-
# Upload the final template
1629-
final_template_key = f"{self.prefix}/{self.main_template}"
1630-
packaged_template_path = ".aws-sam/packaged.yaml"
1631-
1632-
try:
1633-
self.s3_client.upload_file(
1634-
packaged_template_path,
1635-
self.bucket,
1636-
final_template_key,
1637-
ExtraArgs={"ACL": self.acl},
1638-
)
1639-
except ClientError as e:
1640-
self.console.print(f"[red]Error uploading main template: {e}[/red]")
1641-
sys.exit(1)
1642-
1643-
# Validate the template
1644-
template_url = f"https://s3.{self.region}.amazonaws.com/{self.bucket}/{final_template_key}"
1645-
self.console.print(f"[cyan]Validating template: {template_url}[/cyan]")
1646-
1647-
try:
1648-
self.cf_client.validate_template(TemplateURL=template_url)
1649-
except ClientError as e:
1650-
self.console.print(f"[red]Template validation failed: {e}[/red]")
1651-
sys.exit(1)
1652-
16531628
# Update checksums
16541629
checksum = self.get_checksum(
16551630
"./src", "./options", "./patterns", "template.yaml"
@@ -1658,7 +1633,49 @@ def build_main_template(self, webui_zipfile):
16581633
f.write(checksum)
16591634

16601635
else:
1661-
self.console.print("[yellow]SKIPPING main (unchanged)[/yellow]")
1636+
self.console.print("[yellow]SKIPPING main build (unchanged)[/yellow]")
1637+
1638+
# Always upload the final template to S3, regardless of whether rebuild was needed
1639+
final_template_key = f"{self.prefix}/{self.main_template}"
1640+
packaged_template_path = ".aws-sam/packaged.yaml"
1641+
1642+
# Check if packaged template exists, if not we have a problem
1643+
if not os.path.exists(packaged_template_path):
1644+
self.console.print(
1645+
f"[red]Error: Packaged template not found at {packaged_template_path}[/red]"
1646+
)
1647+
self.console.print(
1648+
"[red]This suggests the template was never built. Try running without cache.[/red]"
1649+
)
1650+
sys.exit(1)
1651+
1652+
self.console.print(
1653+
f"[cyan]Uploading main template to S3: {final_template_key}[/cyan]"
1654+
)
1655+
try:
1656+
self.s3_client.upload_file(
1657+
packaged_template_path,
1658+
self.bucket,
1659+
final_template_key,
1660+
ExtraArgs={"ACL": self.acl},
1661+
)
1662+
self.console.print("[green]✅ Main template uploaded successfully[/green]")
1663+
except ClientError as e:
1664+
self.console.print(f"[red]Error uploading main template: {e}[/red]")
1665+
sys.exit(1)
1666+
1667+
# Validate the template
1668+
template_url = (
1669+
f"https://s3.{self.region}.amazonaws.com/{self.bucket}/{final_template_key}"
1670+
)
1671+
self.console.print(f"[cyan]Validating template: {template_url}[/cyan]")
1672+
1673+
try:
1674+
self.cf_client.validate_template(TemplateURL=template_url)
1675+
self.console.print("[green]✅ Template validation passed[/green]")
1676+
except ClientError as e:
1677+
self.console.print(f"[red]Template validation failed: {e}[/red]")
1678+
sys.exit(1)
16621679

16631680
def update_lib_checksum(self):
16641681
"""Update lib checksum file to track changes in the library directories"""

0 commit comments

Comments
 (0)