mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-16 17:42:02 +00:00
style: add changelog checks
This commit is contained in:
parent
2c8e5f527b
commit
91da49266c
10
Makefile
10
Makefile
@ -9,9 +9,9 @@ PY_FILES = $(shell find . -type f -name '*.py' | grep -f ./tools/style.py.incl
|
|||||||
C_FILES = $(shell find . -type f -name '*.[ch]' | grep -f ./tools/style.c.include | grep -v -f ./tools/style.c.exclude )
|
C_FILES = $(shell find . -type f -name '*.[ch]' | grep -f ./tools/style.c.include | grep -v -f ./tools/style.c.exclude )
|
||||||
|
|
||||||
|
|
||||||
style_check: pystyle_check cstyle_check ## run all style checks (C+Py)
|
style_check: pystyle_check cstyle_check changelog_check ## run all style checks (C+Py)
|
||||||
|
|
||||||
style: pystyle cstyle ## apply all code styles (C+Py)
|
style: pystyle cstyle changelog ## apply all code styles (C+Py)
|
||||||
|
|
||||||
pystyle_check: ## run code style check on application sources and tests
|
pystyle_check: ## run code style check on application sources and tests
|
||||||
flake8 --version
|
flake8 --version
|
||||||
@ -39,6 +39,12 @@ pystyle: ## apply code style on application sources and tests
|
|||||||
@flake8 $(PY_FILES)
|
@flake8 $(PY_FILES)
|
||||||
make -C python style
|
make -C python style
|
||||||
|
|
||||||
|
changelog_check: # check changelog format
|
||||||
|
./tools/linkify-changelogs.py --check
|
||||||
|
|
||||||
|
changelog: # fill out issue links in changelog
|
||||||
|
./tools/linkify-changelogs.py
|
||||||
|
|
||||||
cstyle_check: ## run code style check on low-level C code
|
cstyle_check: ## run code style check on low-level C code
|
||||||
clang-format --version
|
clang-format --version
|
||||||
@echo [CLANG-FORMAT]
|
@echo [CLANG-FORMAT]
|
||||||
|
@ -19,8 +19,9 @@ DEFAULT_CHANGELOGS = ( # TODO replace with a wildcard?
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def process_changelog(changelog_file):
|
def process_changelog(changelog_file, only_check=False):
|
||||||
links = {}
|
links = {}
|
||||||
|
orig_links = {}
|
||||||
result_lines = []
|
result_lines = []
|
||||||
|
|
||||||
with open(changelog_file, "r+") as changelog:
|
with open(changelog_file, "r+") as changelog:
|
||||||
@ -28,12 +29,22 @@ def process_changelog(changelog_file):
|
|||||||
m = LINK_RE.match(line)
|
m = LINK_RE.match(line)
|
||||||
if m: # line *starts with* issue identifier
|
if m: # line *starts with* issue identifier
|
||||||
# keep existing links as-is
|
# keep existing links as-is
|
||||||
links[int(m[1])] = line.replace(m[0] + ": ", "").strip()
|
orig_links[int(m[1])] = line.replace(m[0] + ": ", "").strip()
|
||||||
else:
|
else:
|
||||||
for issue in LINK_RE.findall(line):
|
for issue in LINK_RE.findall(line):
|
||||||
links[int(issue)] = ISSUE_URL.format(issue=issue)
|
links[int(issue)] = ISSUE_URL.format(issue=issue)
|
||||||
result_lines.append(line)
|
result_lines.append(line)
|
||||||
|
|
||||||
|
if only_check:
|
||||||
|
missing_links = set(links.keys()) - set(orig_links.keys())
|
||||||
|
if missing_links:
|
||||||
|
click.echo(f"missing links: {missing_links}")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
links.update(orig_links)
|
||||||
|
|
||||||
changelog.seek(0)
|
changelog.seek(0)
|
||||||
changelog.truncate(0)
|
changelog.truncate(0)
|
||||||
for line in result_lines:
|
for line in result_lines:
|
||||||
@ -41,6 +52,8 @@ def process_changelog(changelog_file):
|
|||||||
for marker, url in sorted(links.items()):
|
for marker, url in sorted(links.items()):
|
||||||
changelog.write(f"[#{marker}]: {url}\n")
|
changelog.write(f"[#{marker}]: {url}\n")
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.argument(
|
@click.argument(
|
||||||
@ -48,7 +61,8 @@ def process_changelog(changelog_file):
|
|||||||
nargs=-1,
|
nargs=-1,
|
||||||
type=click.Path(exists=True, dir_okay=False, writable=True),
|
type=click.Path(exists=True, dir_okay=False, writable=True),
|
||||||
)
|
)
|
||||||
def cli(changelogs):
|
@click.option("--check", is_flag=True, help="Check for missing links, do not modify.")
|
||||||
|
def cli(changelogs, check):
|
||||||
"""Linkify changelog.
|
"""Linkify changelog.
|
||||||
|
|
||||||
Find all occurences of "[#123]" in text, and add a Markdown link to the referenced
|
Find all occurences of "[#123]" in text, and add a Markdown link to the referenced
|
||||||
@ -59,9 +73,14 @@ def cli(changelogs):
|
|||||||
if not changelogs:
|
if not changelogs:
|
||||||
changelogs = DEFAULT_CHANGELOGS
|
changelogs = DEFAULT_CHANGELOGS
|
||||||
|
|
||||||
|
all_ok = True
|
||||||
for changelog in changelogs:
|
for changelog in changelogs:
|
||||||
click.echo(f"Linkifying {changelog}...")
|
click.echo(changelog)
|
||||||
process_changelog(changelog)
|
if not process_changelog(changelog, check):
|
||||||
|
all_ok = False
|
||||||
|
|
||||||
|
if not all_ok:
|
||||||
|
raise click.ClickException("Some links are missing. Run `make style` to fix.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user