Skip to content

Commit

Permalink
chore(ci): add script for checking for unreleased changes on release …
Browse files Browse the repository at this point in the history
…branches (#9624)

## Checklist

- [x] Change(s) are motivated and described in the PR description
- [x] Testing strategy is described if automated tests are not included
in the PR
- [x] Risks are described (performance impact, potential for breakage,
maintainability)
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed or label `changelog/no-changelog` is set
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/))
- [x] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))
- [x] If this PR changes the public interface, I've notified
`@DataDog/apm-tees`.

## Reviewer Checklist

- [x] Title is accurate
- [x] All changes are related to the pull request's stated goal
- [ ] Description motivates each change
- [ ] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- [ ] Testing strategy adequately addresses listed risks
- [ ] Change is maintainable (easy to change, telemetry, documentation)
- [ ] Release note makes sense to a user of the library
- [ ] Author has acknowledged and discussed the performance implications
of this PR as reported in the benchmarks PR comment
- [ ] Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
  • Loading branch information
brettlangdon authored Jun 25, 2024
1 parent 7527e61 commit 3010fa1
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions scripts/unreleased-changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env python
"""
Shell script to help find unreleased changes on release branches.
Loops through each release branch from current branch to 1.0 and prints out
the changes that have not been released yet in json format as:
{"branch": "1.1","changes": ["..."]}
{"branch": "1.0","changes": ["..."]}
"""
import json
import packaging.version
import subprocess
import sys


def get_release_branches() -> list[str]:
# get list of all git release tags
tags = subprocess.check_output(["git", "tag", "--list", "v*"]).splitlines()
# get list of all release branches
branches = sorted(
{".".join(tag.decode("utf-8")[1:].split(".")[:2]) for tag in tags},
key=lambda x: packaging.version.Version(x),
reverse=True,
)

return [branch for branch in branches if float(branch) >= 1.0]


def get_unreleased_changes(branch: str) -> list[str]:
# get list of reno changes for the branch
results = subprocess.check_output(
["reno", "--quiet", "list", "--branch", branch, "--stop-at-branch-base"], stderr=subprocess.PIPE
).decode("utf-8")

changes = []

unreleased_version = None
# The output from reno list will be:
#
# v1.2.3-13
# releasenotes/unreleased-change
# v1.2.3
# releasenotes/released-change ...
# v1.2.2
# releasenotes/released-change ...
#
# We want to collect all the lines between the first version with a `vx.y.z-#` until
# the next version
for line in results.splitlines():
if line.startswith("v") and "-" in line:
unreleased_version = line.strip()
elif line.startswith("\t") and unreleased_version:
changes.append(line.strip())
elif unreleased_version and line.startswith("v"):
break

return changes


def main():
# Make sure we have the latest tags
subprocess.check_output(["git", "fetch", "--tags", "--force"], stderr=subprocess.PIPE)

branches = get_release_branches()
for branch in branches:
changes = get_unreleased_changes(branch)
if changes:
json.dump({"branch": branch, "changes": changes}, sys.stdout, indent=None, separators=(",", ":"))
sys.stdout.write("\n")
sys.stdout.flush()


if __name__ == "__main__":
main()

0 comments on commit 3010fa1

Please sign in to comment.