-
Notifications
You must be signed in to change notification settings - Fork 0
Continuous Integration Optimization #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ca8c579
quality-checks.yml: Employs the python-build-and-inspect-python-packa…
funkyfuture 4dfba1e
Adds a workflow to publish to the PyPI from the CI
funkyfuture 3269864
workflows/linkcheck.yml: Switches to installation with pipx
funkyfuture 2ce494b
workflows/quality-checks.yml: Adds a job to run unit tests from / aga…
funkyfuture f76650b
workflows: Updates setup-python's arguments
funkyfuture aeca5f3
workflows/quality-checks.yml: Passes wheel location to hatch as envir…
funkyfuture aa69e3f
ci: run changelog through pandoc && use as gh release notes
funkyfuture 90f3a2e
workflows/publish.yml: Separates publishing to PyPI & GitHub
funkyfuture 054a512
workflows/publish.yml: Adds building HTML docs
funkyfuture 7146c11
Adds linting of YAML files
funkyfuture File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
from pypandoc import convert_text, download_pandoc | ||
|
||
|
||
CWD = Path().cwd() | ||
|
||
|
||
date_pattern = r"\(\d\d\d\d-\d\d-\d\d\)" | ||
version_pattern = r"\d+\.\d+(\.\d+)?(rc\d+)?" | ||
|
||
matches_version_header = re.compile(rf"^{version_pattern} {date_pattern}$").match | ||
|
||
|
||
def extract_relevant_contents(expected_version: str) -> str: | ||
# This isn't solved with a pandoc filter as pandoc only recognizes the level 3 | ||
# headers as such. | ||
|
||
line_feed = iter((CWD / "CHANGES.rst").read_text().splitlines()) | ||
|
||
while True: | ||
line = next(line_feed) | ||
if matches_version_header(line) and line.startswith(expected_version): | ||
break | ||
|
||
assert next(line_feed)[0] == "-" | ||
assert next(line_feed) == "" | ||
|
||
lines: list[str] = [] | ||
while not matches_version_header(line := next(line_feed)): | ||
lines.append(line) | ||
|
||
while lines[-1] == "": | ||
lines.pop() | ||
|
||
return "\n".join(lines) | ||
|
||
|
||
def make_github_release(notes: str, version: str): | ||
options = [] | ||
options.extend(["--notes-file", "-"]) | ||
options.extend(["--title", f"delb {version}"]) | ||
options.append("--verify-tag") | ||
if "rc" in version: | ||
options.append("--prerelease") | ||
|
||
result = subprocess.run( | ||
[ | ||
"gh", | ||
"release", | ||
"create", | ||
] | ||
+ options | ||
+ [version], | ||
capture_output=True, | ||
encoding="utf-8", | ||
input=notes, | ||
) | ||
print(result.stdout) | ||
if result.returncode != 0: | ||
print(result.stdout) | ||
result.check_returncode() | ||
|
||
|
||
def make_release_notes(version: str) -> str: | ||
os.environ["DELB_DOCS_BASE_URL"] = f"https://delb.readthedocs.io/en/{version}/" | ||
return ( | ||
convert_text( | ||
extract_relevant_contents(version), | ||
format="rst", | ||
to="markdown_strict", | ||
extra_args=["--shift-heading-level-by=1", "--wrap=none"], | ||
filters=[".github/scripts/release-notes-pandoc-filter.py"], | ||
) | ||
+ "\n\n----\n\nThe package distributions are available at the " | ||
+ f"[Python Package Index](https://pypi.org/project/delb/)." | ||
) | ||
|
||
|
||
def main(version: str): | ||
download_pandoc() | ||
make_github_release(notes=make_release_notes(version), version=version) | ||
|
||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
import posixpath | ||
import sys | ||
from pathlib import Path | ||
|
||
from panflute import run_filter, Code, Link, Str | ||
from sphinx.util.inventory import InventoryFile | ||
|
||
|
||
BASE_URL = os.environ["DELB_DOCS_BASE_URL"] | ||
CWD = Path.cwd() | ||
ROLES_MAPPING = { | ||
"attr": "py:attribute", | ||
"class": "py:class", | ||
"doc": "std:doc", | ||
# ?"exception"?: "py:exception", | ||
"func": "py:function", | ||
"meth": "py:method", | ||
"mod": "py:module", | ||
# ???: "py:property", | ||
"term": "std:term", | ||
} | ||
|
||
|
||
def bend_links(elem, doc): | ||
if not (isinstance(elem, Code) and "interpreted-text" in elem.classes): | ||
return elem | ||
|
||
inventory_section = ROLES_MAPPING[elem.attributes["role"]] | ||
target = doc.inventory[inventory_section].get(elem.text) | ||
|
||
if target is None: | ||
# this is okay for non-existing entries such as :meth:`NodeBase.…` and | ||
# objects in other inventories like Python's docs | ||
print(f"WARNING: No inventory object for '{elem.text}' found.", file=sys.stderr) | ||
return Code(elem.text) | ||
|
||
if (label_text := target[3]) == "-": | ||
label_text = elem.text | ||
|
||
if inventory_section.startswith("py:"): | ||
label = Code(label_text) | ||
else: | ||
label = Str(f"„{label_text}”") | ||
|
||
return Link(label, url=target[2]) | ||
|
||
|
||
def prepare(doc): | ||
with (CWD / "docs" / "build" / "html" / "objects.inv").open("rb") as f: | ||
doc.inventory = InventoryFile.load(f, BASE_URL, posixpath.join) | ||
|
||
|
||
def main(doc=None): | ||
return run_filter(bend_links, prepare=prepare) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.