Skip to content

Commit

Permalink
force user to follow release note rule
Browse files Browse the repository at this point in the history
  • Loading branch information
tkxkd0159 committed May 28, 2024
1 parent ad0f79d commit f5f50f2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
2 changes: 2 additions & 0 deletions RELEASE_DESCR.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ This version based on finschia-sdk v0.46.0-rc2

## [v0.1.0] - 2021-11-01
This is the first release of the Finschia blockchain. It is based on [gaia v4.0.4](https://github.com/cosmos/gaia/releases/tag/v4.0.4).

<!-- Release links -->
60 changes: 35 additions & 25 deletions scripts/release-note.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ def get_prev_gittag(target_tag: str) -> str:
)


def extract_package_version(document: str, package_name: str):
pattern = rf"{re.escape(package_name)} (v[^\s]+)"
def extract_package_version(
document: str, package_name: str, version_suffix: bool
) -> str:
suffix_pattern = r"\/v\d+" if version_suffix else ""
pattern = rf"{re.escape(package_name)}{suffix_pattern} (v[^\s]+)"

match = re.search(pattern, document)
if match:
return match.group(1)
else:
raise ValueError(f"Package {package_name} not found in the document.")


def extract_go_version(document: str):
def extract_go_version(document: str) -> str:
pattern = r"go ([^\s]+)"
match = re.search(pattern, document)
if match:
Expand All @@ -52,25 +56,29 @@ def extract_release_contents(target: str, cur_tag: str, prev_tag: str) -> str:

with open(target, "r") as f:
document = f.read()
start_marker = f"## [{cur_tag}]"
start_pos = document.find(start_marker) + len(start_marker) + len(" - YYYY-MM-DD")
if start_pos != -1:
if prev_tag is None:
end_pos = document.find("<!-- Release links -->")
if end_pos == -1:
match = re.search(r"## \[v\d+\.\d+\.\d+] - \d{4}-\d{2}-\d{2}", document[start_pos:])
if match is None:
end_pos = -1
else:
end_pos = start_pos + match.start() - 1
else:
end_marker = f"## [{prev_tag}]"
end_pos = document.find(end_marker)
if end_pos == -1:
match = re.search(r"## \[v\d+\.\d+\.\d+] - \d{4}-\d{2}-\d{2}", document[start_pos:])
end_pos = start_pos + match.start() - 1

start_marker = f"## [{cur_tag}] - "
start_pos = document.find(start_marker)

if start_pos == -1:
raise ValueError(f"Start marker for tag '{cur_tag}' not found in the document.")

start_pos += len(start_marker) + len("YYYY-MM-DD")

if prev_tag:
end_marker = f"## [{prev_tag}]"
end_pos = document.find(end_marker, start_pos)
if end_pos == -1:
raise ValueError(
f"End marker for previous tag '{prev_tag}' not found in the document."
)
else:
raise ValueError("Content not found between the specified markers.")
end_pos = document.find("<!-- Release links -->", start_pos)
if end_pos == -1:
raise ValueError(
"End marker '<!-- Release links -->' not found in the document."
)

return document[start_pos:end_pos].strip()


Expand All @@ -85,10 +93,12 @@ def extract_release_contents(target: str, cur_tag: str, prev_tag: str) -> str:
TAG = args[0]
PREV_TAG = get_prev_gittag(TAG)
GO_VERSION = extract_go_version(gomod)
OSTRACON_VERSION = extract_package_version(gomod, "github.com/Finschia/ostracon")
FNSASDK_VERSION = extract_package_version(gomod, "github.com/Finschia/finschia-sdk")
WASMD_VERSION = extract_package_version(gomod, "github.com/Finschia/wasmd")
IBC_VERSION = extract_package_version(gomod, "github.com/cosmos/ibc-go/v4")
OSTRACON_VERSION = extract_package_version(gomod, "github.com/Finschia/ostracon", False)
FNSASDK_VERSION = extract_package_version(
gomod, "github.com/Finschia/finschia-sdk", False
)
WASMD_VERSION = extract_package_version(gomod, "github.com/Finschia/wasmd", False)
IBC_VERSION = extract_package_version(gomod, "github.com/cosmos/ibc-go", True)

release_note = f"""# Finschia {TAG} Release Note
Expand Down

0 comments on commit f5f50f2

Please sign in to comment.