Skip to content

Commit

Permalink
ci: update more pages
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii authored Jul 3, 2023
1 parent bdd3d34 commit 9ff97c0
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,34 +307,37 @@ def compare_cruft(session):

GHA_VERS = re.compile(r"[\s\-]+uses: (.*?)@([^\s]+)")


@nox.session(reuse_venv=True)
def pc_bump(session: nox.Session) -> None:
"""
Bump the pre-commit versions mentioned in the pages.
"""
session.install("lastversion")
versions = {}
pages = [Path("docs/pages/guides/style.md"), Path("{{cookiecutter.project_name}}/.pre-commit-config.yaml")]

style = Path("docs/pages/guides/style.md")
txt = style.read_text()
old_versions = {m[1]: m[2].strip('"') for m in PC_VERS.finditer(txt)}
for page in pages:
txt = page.read_text()
old_versions = {m[1]: m[2].strip('"') for m in PC_VERS.finditer(txt)}

for proj, old_version in old_versions.items():
new_version = session.run("lastversion", proj, silent=True).strip()
for proj, old_version in old_versions.items():
if proj not in versions:
versions[proj] = session.run("lastversion", proj, silent=True).strip()
new_version = versions[proj]

if old_version.lstrip("v") == new_version:
continue
if old_version.lstrip("v") == new_version:
continue

if old_version.startswith("v"):
new_version = f"v{new_version}"
if old_version.startswith("v"):
new_version = f"v{new_version}"

before = PC_REPL_LINE.format(proj, old_version)
after = PC_REPL_LINE.format(proj, new_version)
before = PC_REPL_LINE.format(proj, old_version)
after = PC_REPL_LINE.format(proj, new_version)

session.log(f"Bump: {old_version} -> {new_version}")
txt = txt.replace(before, after)
session.log(f"Bump: {old_version} -> {new_version} ({page})")
txt = txt.replace(before, after)

style.write_text(txt)
page.write_text(txt)


@nox.session(venv_backend="none")
Expand All @@ -343,18 +346,21 @@ def gha_bump(session: nox.Session) -> None:
Bump the GitHub Actions mentioned in the pages.
"""
pages = list(Path("docs/pages/guides").glob("gha_*.md"))
pages.extend(Path("{{cookiecutter.project_name}}/.github/workflows").glob("*.yml")
pages.append(Path("docs/pages/guides/style.md"))
full_txt = "\n".join(page.read_text() for page in pages)

# This assumes there is a single version per action
old_versions = {m[1]: m[2] for m in GHA_VERS.finditer(full_txt)}
versions = {}

for repo, old_version in old_versions.items():
session.log(f"{repo}: {old_version}")
response = urllib.request.urlopen(f"https://api.github.com/repos/{repo}/tags")
tags_js = json.loads(response.read())
if repo not in versions:
response = urllib.request.urlopen(f"https://api.github.com/repos/{repo}/tags")
versions[repo] = json.loads(response.read())
tags = [
x["name"] for x in tags_js if x["name"].count(".") == old_version.count(".")
x["name"] for x in versions[repo] if x["name"].count(".") == old_version.count(".")
]
if not tags:
continue
Expand Down

0 comments on commit 9ff97c0

Please sign in to comment.