Skip to content

Commit

Permalink
ci: update more pages
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Jul 3, 2023
1 parent bdd3d34 commit 4019c7c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
5 changes: 3 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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-)
60 changes: 37 additions & 23 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)")
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions {{cookiecutter.project_name}}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 4019c7c

Please sign in to comment.