Skip to content

Commit

Permalink
[misc] Explicitly specify base tag commit when running make_changelog…
Browse files Browse the repository at this point in the history
….py (#5632)

* [misc] Explicitly specify base tag commit when running make_changelog.py

* Update misc/make_changelog.py
  • Loading branch information
ailzhang authored Aug 5, 2022
1 parent 4c0b0ff commit 694bc3f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/scripts/unix_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ IN_DOCKER=$(check_in_docker)
[[ "$IN_DOCKER" == "true" ]] && cd taichi

build_taichi_wheel() {
git fetch origin master
git fetch origin master --tags
PROJECT_TAGS=""
EXTRA_ARGS=""
if [ "$PROJECT_NAME" = "taichi-nightly" ]; then
Expand All @@ -21,7 +21,7 @@ build_taichi_wheel() {
EXTRA_ARGS="-p manylinux_2_27_x86_64"
fi
fi
python3 misc/make_changelog.py origin/master ./ True
python3 misc/make_changelog.py --ver origin/master --repo_dir ./ --save

TAICHI_CMAKE_ARGS="${TAICHI_CMAKE_ARGS} -DTI_WITH_C_API=ON"
exec env TAICHI_CMAKE_ARGS="${TAICHI_CMAKE_ARGS}" python3 setup.py $PROJECT_TAGS bdist_wheel $EXTRA_ARGS
Expand Down
34 changes: 26 additions & 8 deletions misc/make_changelog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Usage: make_changelog.py [v0.x.y]
# Usage: make_changelog.py --ver origin/master --save

import argparse
import json
import os
import re
import sys

from git import Repo
Expand All @@ -17,9 +19,23 @@ def load_pr_tags():
return details


def find_latest_tag_commit(tags):
for tag in reversed(tags):
s = re.match(r'v\s*([\d.]+)', tag.name)
print(f'Latest version tag is: {tag.name}')
if s is not None:
return tag.commit


def main(ver=None, repo_dir='.'):
g = Repo(repo_dir)
commits_with_tags = set([tag.commit for tag in g.tags])
g.tags.sort(key=lambda x: x.commit.committed_date, reverse=True)

# We need to find out the latest common commit among base and ver,
# everything after this commit should be listed in the changelog.

base_commit = find_latest_tag_commit(g.tags)
commits_in_base_tag = list(g.iter_commits(base_commit, max_count=200))
commits = list(g.iter_commits(ver, max_count=200))
begin, end = -1, 0

Expand All @@ -33,7 +49,7 @@ def format(c):

for i, c in enumerate(commits):
s = format(c)
if c in commits_with_tags and i > 0:
if c in commits_in_base_tag and i > 0:
break

tags = []
Expand Down Expand Up @@ -75,11 +91,13 @@ def format(c):


if __name__ == '__main__':
ver = sys.argv[1] if len(sys.argv) > 1 else None
repo = sys.argv[2] if len(sys.argv) > 2 else '.'
save = sys.argv[3] if len(sys.argv) > 3 else False
res = main(ver, repo)
if save:
parser = argparse.ArgumentParser()
parser.add_argument("--ver")
parser.add_argument("--repo_dir", type=str, default='.')
parser.add_argument("--save", action="store_true", default=False)
args = parser.parse_args()
res = main(args.ver, args.repo_dir)
if args.save:
with open('./python/taichi/CHANGELOG.md', 'w', encoding='utf-8') as f:
f.write(res)
print(res)

0 comments on commit 694bc3f

Please sign in to comment.