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

fix: update CHANGELOG and automate #1674

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Changes from 1 commit
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
Next Next commit
fix: update CHANGELOG and automate
thomasrockhu-codecov committed Nov 19, 2024
commit ee20575f70f4531ed47499624b4cff0586562b9b
850 changes: 748 additions & 102 deletions CHANGELOG.md

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import json
import re
import subprocess

def update_changelog():
with open('src/version', 'r') as f:
raw_version = f.read()
version = re.search('\"(.*)\"', raw_version).groups()[0]
changelog = [f"## v{version}"]
changelog.append("### What\'s Changed")

with open('CHANGELOG.md', 'r') as f:
previous = f.readline().replace("##", '').strip()

if previous == version:
print(f"No changes to version {version}")
return
print(f"Adding logs from {previous}..{version}")

raw_current_branch = subprocess.run([
"git",
"branch",
"--show-current",
], capture_output=True)
current_branch = raw_current_branch.stdout.decode('utf-8')

raw_commits = subprocess.run([
"git",
"log",
f"{previous}..{current_branch}",
"--oneline",
], capture_output=True)
commits = [line[:7] for line in raw_commits.stdout.decode('utf-8').split('\n')]

prs = set()
for commit in commits:
commit_output = subprocess.run([
'gh',
'pr',
'list',
'--json',
'author,number,title,url',
'--search',
f'"{commit}"',
], capture_output=True)
commit_details = json.loads(commit_output.stdout.decode('utf-8'))[0]
if not commit_details['number']:
continue
if commit_details['number'] in prs:
continue
prs.add(commit_details['number'])
changelog.append(f"* {commit_details['title']} by @{commit_details['author']['login']} in {commit_details['url']}")

changelog.append('\n')
changelog.append(f"**Full Changelog**: https://github.com/codecov/codecov-action/compare/{previous}..{version}\n")

with open('CHANGELOG.md', 'r') as f:
for line in f:
changelog.append(line.strip())

with open('CHANGELOG.md', 'w') as f:
f.write('\n'.join(changelog))


if __name__=="__main__":
update_changelog()
5 changes: 5 additions & 0 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -4,3 +4,8 @@ set -e

cp src/scripts/dist/codecov.sh dist/codecov.sh
git add dist/codecov.sh

git diff --cached --name-only | if grep --quiet "src/version"
then
python changelog.py
fi