From 4019c7cc1cf9545fc7897c5d4ccd9c0bbe08bafe Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 3 Jul 2023 01:34:22 -0400 Subject: [PATCH] ci: update more pages Signed-off-by: Henry Schreiner --- .readthedocs.yaml | 5 +- noxfile.py | 60 ++++++++++++------- .../.pre-commit-config.yaml | 4 +- 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 457ab4ae..5c152e1d 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -17,5 +17,6 @@ build: - bundle config set --local without development - bundle install - > - JEKYLL_ENV=production bundle exec jekyll build --destination _readthedocs/html - --baseurl $(echo -n "$READTHEDOCS_CANONICAL_URL" | cut -d '/' -f 4-) + JEKYLL_ENV=production bundle exec jekyll build --destination + _readthedocs/html --baseurl $(echo -n "$READTHEDOCS_CANONICAL_URL" | cut + -d '/' -f 4-) diff --git a/noxfile.py b/noxfile.py index 15e4cbca..dbd00456 100644 --- a/noxfile.py +++ b/noxfile.py @@ -295,14 +295,14 @@ def compare_cruft(session): PC_VERS = re.compile( r"""\ -^- repo: (.*?) - rev: (.*?)$""", +^( *)- repo: (.*?) + * rev: (.*?)$""", re.MULTILINE, ) PC_REPL_LINE = '''\ -- repo: {0} - rev: "{1}"''' +{2}- repo: {0} +{2} rev: "{1}"''' GHA_VERS = re.compile(r"[\s\-]+uses: (.*?)@([^\s]+)") @@ -311,50 +311,64 @@ def compare_cruft(session): @nox.session(reuse_venv=True) def pc_bump(session: nox.Session) -> None: """ - Bump the pre-commit versions mentioned in the pages. + Bump the pre-commit versions. """ 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[2]: (m[3].strip('"'), m[1]) 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, space) 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, space) + after = PC_REPL_LINE.format(proj, new_version, space) - 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") def gha_bump(session: nox.Session) -> None: """ - Bump the GitHub Actions mentioned in the pages. + Bump the GitHub Actions. """ pages = list(Path("docs/pages/guides").glob("gha_*.md")) + pages.extend(Path("{{cookiecutter.project_name}}/.github/workflows").iterdir()) 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 diff --git a/{{cookiecutter.project_name}}/.pre-commit-config.yaml b/{{cookiecutter.project_name}}/.pre-commit-config.yaml index c6d718b9..ceba212a 100644 --- a/{{cookiecutter.project_name}}/.pre-commit-config.yaml +++ b/{{cookiecutter.project_name}}/.pre-commit-config.yaml @@ -44,8 +44,8 @@ repos: - id: blacken-docs additional_dependencies: [black==23.3.0] - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.0.264" + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.0.275" hooks: - id: ruff args: ["--fix", "--show-fixes"]