diff --git a/scripts/generate_changelog.py b/scripts/generate_changelog.py new file mode 100755 index 0000000000..24e92947d8 --- /dev/null +++ b/scripts/generate_changelog.py @@ -0,0 +1,40 @@ +#!/bin/env python3 +import argparse + +from utils import run_command + +# Usage: +# scripts/generate_changelog.py --start --end --project +GIT_CLIFF_VERSION = "2.4.0" +PROJECT_TO_PATHS = {"blockifier": ["crates/blockifier/"], "all": []} + +def prepare_git_cliff(version: str): + """ + Install git-cliff if missing. + """ + run_command( + command=f'cargo install --list | grep -q "git-cliff v{version}" || cargo install git-cliff@{version}' + ) + + +def build_command(project_name: str, start_tag: str, end_tag: str) -> str: + paths = PROJECT_TO_PATHS[project_name] + include_paths = " ".join((f"--include-path {path}" for path in paths)) + return ( + f'git-cliff {start_tag}..{end_tag} -o changelog_{start_tag}_{end_tag}.md --ignore-tags ".*-dev.[0-9]+" {include_paths}' + ) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Generate a changelog file for a given project.") + parser.add_argument( + "--start", type=str, help="The commit/tag that changelog's history starts from." + ) + parser.add_argument("--end", type=str, help="The commit/tag that changelog's history ends at.") + parser.add_argument( + "--project", choices=PROJECT_TO_PATHS.keys(), help="The project that the changelog is generated for." + ) + args = parser.parse_args() + prepare_git_cliff(version=GIT_CLIFF_VERSION) + command = build_command(project_name=args.project, start_tag=args.start, end_tag=args.end) + run_command(command=command) diff --git a/scripts/generate_changelog.sh b/scripts/generate_changelog.sh deleted file mode 100755 index 5d9337ff6c..0000000000 --- a/scripts/generate_changelog.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -e - -# Usage: -# scripts/generate_changelog.sh - -# Install git-cliff if missing. -GIT_CLIFF_VERSION="2.4.0" -cargo install --list | grep -q "git-cliff v${GIT_CLIFF_VERSION}" || cargo install git-cliff@${GIT_CLIFF_VERSION} - -# Combine dev tags into the next RC / stable tag. -git-cliff $1..$2 -o changelog_$1_$2.md --ignore-tags ".*-dev.[0-9]+" diff --git a/scripts/merge_branches.py b/scripts/merge_branches.py index 6ae3c49338..d7dd4a18ca 100755 --- a/scripts/merge_branches.py +++ b/scripts/merge_branches.py @@ -10,9 +10,9 @@ import argparse import json import os -import subprocess import time from typing import Dict, List, Optional +from utils import run_command FINAL_BRANCH = "main" MERGE_PATHS_FILE = "scripts/merge_paths.json" @@ -22,26 +22,6 @@ def load_merge_paths() -> Dict[str, str]: return json.load(open(MERGE_PATHS_FILE)) -def run_command(command: str, allow_error: bool = False) -> List[str]: - """ - Runs a bash command and returns the output as a list of lines. - """ - try: - command_output = ( - subprocess.check_output(command, shell=True, cwd=os.getcwd()) - .decode("utf-8") - .splitlines() - ) - output_lines = "\n".join(command_output) - print(f"Command '{command}' output:\n{output_lines}") - return command_output - except subprocess.CalledProcessError as error: - if not allow_error: - raise - print(f"Command '{command}' hit error: {error=}.") - return str(error).splitlines() - - def get_dst_branch(src_branch: str, dst_branch_override: Optional[str]) -> str: if dst_branch_override is not None: return dst_branch_override diff --git a/scripts/utils.py b/scripts/utils.py new file mode 100644 index 0000000000..3559dac338 --- /dev/null +++ b/scripts/utils.py @@ -0,0 +1,22 @@ +import os +import subprocess +from typing import List + +def run_command(command: str, allow_error: bool = False) -> List[str]: + """ + Runs a bash command and returns the output as a list of lines. + """ + try: + command_output = ( + subprocess.check_output(command, shell=True, cwd=os.getcwd()) + .decode("utf-8") + .splitlines() + ) + output_lines = "\n".join(command_output) + print(f"Command '{command}' output:\n{output_lines}") + return command_output + except subprocess.CalledProcessError as error: + if not allow_error: + raise + print(f"Command '{command}' hit error: {error=}.") + return str(error).splitlines()