Skip to content
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

FEAT: add --github-pages option to check-dev-files #276

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/compwa_policy/check_dev_files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
github_workflows.main,
allow_deprecated=args.allow_deprecated_workflows,
doc_apt_packages=_to_list(args.doc_apt_packages),
github_pages=args.github_pages,
python_version=dev_python_version,
no_macos=args.no_macos,
no_pypi=args.no_pypi,
Expand All @@ -79,7 +80,12 @@
if is_python_repo:
executor(black.main, has_notebooks)
if not args.no_github_actions:
executor(release_drafter.main, args.repo_name, args.repo_title)
executor(

Check warning on line 83 in src/compwa_policy/check_dev_files/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/compwa_policy/check_dev_files/__init__.py#L83

Added line #L83 was not covered by tests
release_drafter.main,
args.repo_name,
args.repo_title,
github_pages=args.github_pages,
)
executor(mypy.main)
executor(pyright.main)
executor(pytest.main)
Expand Down Expand Up @@ -133,6 +139,12 @@
required=False,
type=str,
)
parser.add_argument(

Check warning on line 142 in src/compwa_policy/check_dev_files/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/compwa_policy/check_dev_files/__init__.py#L142

Added line #L142 was not covered by tests
"--github-pages",
action="store_true",
default=False,
help="Host documentation on GitHub Pages",
)
parser.add_argument(
"--keep-issue-templates",
help="Do not remove the .github/ISSUE_TEMPLATE directory",
Expand Down
14 changes: 11 additions & 3 deletions src/compwa_policy/check_dev_files/github_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
def main(
allow_deprecated: bool,
doc_apt_packages: list[str],
github_pages: bool,
no_macos: bool,
no_pypi: bool,
no_version_branches: bool,
Expand All @@ -46,6 +47,7 @@
_update_ci_workflow,
allow_deprecated,
doc_apt_packages,
github_pages,
no_macos,
python_version,
single_threaded,
Expand Down Expand Up @@ -95,6 +97,7 @@
def _update_ci_workflow(
allow_deprecated: bool,
doc_apt_packages: list[str],
github_pages: bool,
no_macos: bool,
python_version: PythonVersion,
single_threaded: bool,
Expand All @@ -105,6 +108,7 @@
yaml, expected_data = _get_ci_workflow(
COMPWA_POLICY_DIR / CONFIG_PATH.github_workflow_dir / "ci.yml",
doc_apt_packages,
github_pages,
no_macos,
python_version,
single_threaded,
Expand Down Expand Up @@ -139,6 +143,7 @@
def _get_ci_workflow(
path: Path,
doc_apt_packages: list[str],
github_pages: bool,
no_macos: bool,
python_version: PythonVersion,
single_threaded: bool,
Expand All @@ -147,14 +152,17 @@
) -> tuple[YAML, dict]:
yaml = create_prettier_round_trip_yaml()
config = yaml.load(path)
__update_doc_section(config, doc_apt_packages, python_version)
__update_doc_section(config, doc_apt_packages, python_version, github_pages)

Check warning on line 155 in src/compwa_policy/check_dev_files/github_workflows.py

View check run for this annotation

Codecov / codecov/patch

src/compwa_policy/check_dev_files/github_workflows.py#L155

Added line #L155 was not covered by tests
__update_pytest_section(config, no_macos, single_threaded, skip_tests, test_extras)
__update_style_section(config, python_version)
return yaml, config


def __update_doc_section(
config: CommentedMap, apt_packages: list[str], python_version: PythonVersion
config: CommentedMap,
apt_packages: list[str],
python_version: PythonVersion,
github_pages: bool,
) -> None:
if not os.path.exists("docs/"):
del config["jobs"]["doc"]
Expand All @@ -164,7 +172,7 @@
with_section["python-version"] = DoubleQuotedScalarString(python_version)
if apt_packages:
with_section["apt-packages"] = " ".join(apt_packages)
if not CONFIG_PATH.readthedocs.exists():
if not CONFIG_PATH.readthedocs.exists() or github_pages:
with_section["gh-pages"] = True
__update_with_section(config, job_name="doc")

Expand Down
14 changes: 8 additions & 6 deletions src/compwa_policy/check_dev_files/release_drafter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from compwa_policy.utilities.yaml import create_prettier_round_trip_yaml


def main(repo_name: str, repo_title: str) -> None:
def main(repo_name: str, repo_title: str, github_pages: bool) -> None:
update_file(CONFIG_PATH.release_drafter_workflow)
_update_draft(repo_name, repo_title)
_update_draft(repo_name, repo_title, github_pages)

Check warning on line 15 in src/compwa_policy/check_dev_files/release_drafter.py

View check run for this annotation

Codecov / codecov/patch

src/compwa_policy/check_dev_files/release_drafter.py#L15

Added line #L15 was not covered by tests


def _update_draft(repo_name: str, repo_title: str) -> None:
def _update_draft(repo_name: str, repo_title: str, github_pages: bool) -> None:
yaml = create_prettier_round_trip_yaml()
expected = _get_expected_config(repo_name, repo_title)
expected = _get_expected_config(repo_name, repo_title, github_pages)

Check warning on line 20 in src/compwa_policy/check_dev_files/release_drafter.py

View check run for this annotation

Codecov / codecov/patch

src/compwa_policy/check_dev_files/release_drafter.py#L20

Added line #L20 was not covered by tests
output_path = CONFIG_PATH.release_drafter_config
if not os.path.exists(output_path):
yaml.dump(expected, output_path)
Expand All @@ -30,14 +30,16 @@
raise PrecommitError(msg)


def _get_expected_config(repo_name: str, repo_title: str) -> dict[str, Any]:
def _get_expected_config(
repo_name: str, repo_title: str, github_pages: bool
) -> dict[str, Any]:
yaml = create_prettier_round_trip_yaml()
config = yaml.load(COMPWA_POLICY_DIR / CONFIG_PATH.release_drafter_config)
key = "name-template"
config[key] = config[key].replace("<<REPO_TITLE>>", repo_title)
key = "template"
lines = config[key].split("\n")
if not os.path.exists(CONFIG_PATH.readthedocs):
if not os.path.exists(CONFIG_PATH.readthedocs) or github_pages:
lines = lines[2:]
config[key] = "\n".join(lines).replace("<<REPO_NAME>>", repo_name)
return config
Expand Down
Loading