Skip to content

Commit

Permalink
feat: track changelog with stack update (#1043)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-reiff authored Sep 26, 2024
1 parent 21cc7c5 commit 51475f0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions stack-assets/stack-updater/update_stack_definition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import csv
import json
import logging
import os
Expand Down Expand Up @@ -142,6 +143,14 @@ def get_latest_valid_version(updates: List[Dict[str, Any]]):
help="Dry run mode, do not update stack definition",
required=False,
)
parser.add_argument(
"--output-file",
"-o",
action="store",
dest="output_file",
help="File to track all changes made",
required=False,
)

args = parser.parse_args()

Expand Down Expand Up @@ -189,6 +198,7 @@ def get_latest_valid_version(updates: List[Dict[str, Any]]):

catalogs = {} # Cache catalogs to avoid multiple requests
failures = [] # List to track failures
changelog = [] # list to track all updates

# read stack definition json
with open(args.stack, "r") as f:
Expand Down Expand Up @@ -264,6 +274,14 @@ def get_latest_valid_version(updates: List[Dict[str, Any]]):
)
# check if the version locator has changed
if member["version_locator"] != latest_version_locator:
# add change to changelog
changelog.append(
{
"name": member["name"],
"from": current_version,
"to": latest_version_name,
}
)
# update stack member with latest version locator
member["version_locator"] = latest_version_locator
# set flag to True
Expand All @@ -281,6 +299,14 @@ def get_latest_valid_version(updates: List[Dict[str, Any]]):
with open(args.stack, "w") as f:
f.write(json.dumps(stack, indent=2) + "\n")
logger.info(f"Stack definition updated: {args.stack}")
if args.output_file is not None:
with open(
args.output_file, "w", encoding="utf8", newline=""
) as output_file:
f = csv.DictWriter(output_file, fieldnames=changelog[0].keys())
f.writeheader()
f.writerows(changelog)
logger.info(f"Changelog saved to: {args.output_file}")
else:
logger.info("Already up to date. No updates were made.")

Expand Down

0 comments on commit 51475f0

Please sign in to comment.