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

DX: lint PRs with @compwa/commitlint-config #186

Merged
merged 5 commits into from
Oct 5, 2023
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
11 changes: 6 additions & 5 deletions .github/workflows/pr-linting.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# cspell:ignore agilepathway commitlint kode

name: PR linting
on:
pull_request:
Expand All @@ -16,7 +14,7 @@ jobs:
name: Check labels
runs-on: ubuntu-20.04
steps:
- uses: docker://agilepathway/pull-request-label-checker:latest
- uses: docker://agilepathway/pull-request-label-checker:latest # cspell:ignore agilepathway
with:
any_of: >-
🐛 Bug,✨ Feature,⚙️ Enhancement,⚠️ Interface,❗ Behavior,📝 Docs,🔨 Maintenance,🖱️ DX
Expand All @@ -28,5 +26,8 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- run: npm install @commitlint/config-conventional
- uses: JulienKode/[email protected]
- run: npm install @compwa/commitlint-config
- name: Create commitlint config
run: |
echo "module.exports = {extends: ['@compwa/commitlint-config']}" > commitlint.config.js
- uses: JulienKode/[email protected] # cspell:ignore kode
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*.xml
*.yaml
*.yml
commitlint.config.js

# Build files
*.egg-info/
Expand Down
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
"src/repoma/.template/.cspell.json": true,
"src/repoma/.template/.gitpod.yml": true,
"src/repoma/.template/.prettierrc": true,
"src/repoma/.template/.taplo.toml": true,
"src/repoma/.template/commitlint.config.js": true
"src/repoma/.template/.taplo.toml": true
},
"yaml.schemas": {
"https://citation-file-format.github.io/1.2.0/schema.json": "CITATION.cff",
Expand Down
11 changes: 0 additions & 11 deletions commitlint.config.js

This file was deleted.

1 change: 1 addition & 0 deletions src/repoma/.github/workflows/pr-linting.yml
1 change: 0 additions & 1 deletion src/repoma/.template/commitlint.config.js

This file was deleted.

16 changes: 13 additions & 3 deletions src/repoma/check_dev_files/commitlint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
"""Check :file:`commitlint.config.js` config file."""
from repoma.utilities import CONFIG_PATH, update_file
"""Remove :file:`commitlint.config.js` config file.
See https://github.com/ComPWA/repo-maintenance/issues/177.
"""
import os

from repoma.errors import PrecommitError


def main() -> None:
update_file(CONFIG_PATH.commitlint, in_template_folder=True)
path = "commitlint.config.js"

Check warning on line 11 in src/repoma/check_dev_files/commitlint.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/commitlint.py#L11

Added line #L11 was not covered by tests
if not os.path.exists(path):
return
os.remove(path)
msg = f"Remove outdated {path}"
raise PrecommitError(msg)

Check warning on line 16 in src/repoma/check_dev_files/commitlint.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/commitlint.py#L13-L16

Added lines #L13 - L16 were not covered by tests
15 changes: 14 additions & 1 deletion src/repoma/check_dev_files/github_workflows.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Check :file:`.github/workflows` folder content."""
import os
import re
import shutil
from pathlib import Path
from typing import List, Tuple

Expand All @@ -9,7 +10,7 @@
from ruamel.yaml.scalarstring import DoubleQuotedScalarString

from repoma.errors import PrecommitError
from repoma.utilities import CONFIG_PATH, REPOMA_DIR, write
from repoma.utilities import CONFIG_PATH, REPOMA_DIR, hash_file, write
from repoma.utilities.executor import Executor
from repoma.utilities.precommit import PrecommitConfig
from repoma.utilities.project_info import get_pypi_name
Expand Down Expand Up @@ -42,6 +43,7 @@
skip_tests,
test_extras,
)
executor(_update_pr_linting)

Check warning on line 46 in src/repoma/check_dev_files/github_workflows.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/github_workflows.py#L46

Added line #L46 was not covered by tests
executor(_recommend_vscode_extension)
executor.finalize()

Expand Down Expand Up @@ -70,6 +72,17 @@
executor.finalize()


def _update_pr_linting() -> None:
filename = "pr-linting.yml"
input_path = REPOMA_DIR / CONFIG_PATH.github_workflow_dir / filename
output_path = CONFIG_PATH.github_workflow_dir / filename
output_path.parent.mkdir(exist_ok=True)

Check warning on line 79 in src/repoma/check_dev_files/github_workflows.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/github_workflows.py#L76-L79

Added lines #L76 - L79 were not covered by tests
if not output_path.exists() or hash_file(input_path) != hash_file(output_path):
shutil.copyfile(input_path, output_path)
msg = f'Updated "{output_path}" workflow'
raise PrecommitError(msg)

Check warning on line 83 in src/repoma/check_dev_files/github_workflows.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/github_workflows.py#L81-L83

Added lines #L81 - L83 were not covered by tests


def _update_ci_workflow(
allow_deprecated: bool,
doc_apt_packages: List[str],
Expand Down
2 changes: 1 addition & 1 deletion src/repoma/check_dev_files/release_drafter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Check :file:`commitlint.config.js` config file."""
"""Update Release Drafter Action."""
import os
from typing import Any, Dict

Expand Down
15 changes: 14 additions & 1 deletion src/repoma/utilities/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Collection of helper functions that are shared by all sub-hooks."""

import hashlib
import io
import os
import re
Expand All @@ -14,7 +15,6 @@
class _ConfigFilePaths(NamedTuple):
citation: Path = Path("CITATION.cff")
codecov: Path = Path("codecov.yml")
commitlint: Path = Path("commitlint.config.js")
cspell: Path = Path(".cspell.json")
editorconfig: Path = Path(".editorconfig")
github_workflow_dir: Path = Path(".github/workflows")
Expand All @@ -40,6 +40,19 @@
REPOMA_DIR = Path(repoma.__file__).parent.absolute()


def hash_file(path: Union[Path, str]) -> str:
# https://stackoverflow.com/a/22058673
buffer_size = 65_536
sha256 = hashlib.sha256()
with open(path, "rb") as f:

Check warning on line 47 in src/repoma/utilities/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/utilities/__init__.py#L45-L47

Added lines #L45 - L47 were not covered by tests
while True:
data = f.read(buffer_size)

Check warning on line 49 in src/repoma/utilities/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/utilities/__init__.py#L49

Added line #L49 was not covered by tests
if not data:
break
sha256.update(data)
return sha256.hexdigest()

Check warning on line 53 in src/repoma/utilities/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/utilities/__init__.py#L51-L53

Added lines #L51 - L53 were not covered by tests


def read(input: Union[Path, io.TextIOBase, str]) -> str: # noqa: A002
if isinstance(input, (Path, str)):
with open(input) as input_stream:
Expand Down
Loading