-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ci): supporting git cliff for chosen projects
- Loading branch information
1 parent
13ae058
commit a4e1a65
Showing
4 changed files
with
63 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |