Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ci): supporting git cliff for chosen projects #431

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions scripts/generate_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/env python3
import argparse

from utils import run_command

# Usage:
# scripts/generate_changelog.py --start <FROM_TAG> --end <TO_TAG> --project <PROJECT_NAME>
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)
13 changes: 0 additions & 13 deletions scripts/generate_changelog.sh

This file was deleted.

22 changes: 1 addition & 21 deletions scripts/merge_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions scripts/utils.py
Original file line number Diff line number Diff line change
@@ -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()
Loading