From 6dbe2924e6558efaa078c4f6643da3b72e0bdbe7 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Thu, 5 Oct 2023 11:18:14 +0200 Subject: [PATCH 1/5] FIX: update `relkease_drafter` module description --- src/repoma/check_dev_files/release_drafter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/repoma/check_dev_files/release_drafter.py b/src/repoma/check_dev_files/release_drafter.py index 68d148f0..9a4fbc2f 100644 --- a/src/repoma/check_dev_files/release_drafter.py +++ b/src/repoma/check_dev_files/release_drafter.py @@ -1,4 +1,4 @@ -"""Check :file:`commitlint.config.js` config file.""" +"""Update Release Drafter Action.""" import os from typing import Any, Dict From ee95904d93cea9b70451af560a6a3128cd994fd1 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Thu, 5 Oct 2023 11:19:17 +0200 Subject: [PATCH 2/5] DX: lint PRs with `@compwa/commitlint-config` --- .github/workflows/pr-linting.yml | 10 ++++++---- .gitignore | 1 + .vscode/settings.json | 3 +-- commitlint.config.js | 11 ----------- src/repoma/check_dev_files/commitlint.py | 16 +++++++++++++--- src/repoma/utilities/__init__.py | 1 - 6 files changed, 21 insertions(+), 21 deletions(-) delete mode 100644 commitlint.config.js diff --git a/.github/workflows/pr-linting.yml b/.github/workflows/pr-linting.yml index 2dc8c43b..8f266f4b 100644 --- a/.github/workflows/pr-linting.yml +++ b/.github/workflows/pr-linting.yml @@ -1,5 +1,3 @@ -# cspell:ignore agilepathway commitlint kode - name: PR linting on: pull_request: @@ -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 @@ -29,4 +27,8 @@ jobs: steps: - uses: actions/checkout@v3 - run: npm install @commitlint/config-conventional - - uses: JulienKode/pull-request-name-linter-action@v0.5.0 + - run: npm install @compwa/commitlint-config + - name: Create commitlint config + run: | + echo "module.exports = {extends: ['@compwa/commitlint-config']}" > commitlint.config.js + - uses: JulienKode/pull-request-name-linter-action@v0.5.0 # cspell:ignore kode diff --git a/.gitignore b/.gitignore index fb10abe8..28e9d586 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ *.xml *.yaml *.yml +commitlint.config.js # Build files *.egg-info/ diff --git a/.vscode/settings.json b/.vscode/settings.json index 0622e029..9a40f67b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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", diff --git a/commitlint.config.js b/commitlint.config.js deleted file mode 100644 index d8b6bdcd..00000000 --- a/commitlint.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - extends: ["@commitlint/config-conventional"], - rules: { - "type-case": [2, "always", ["upper-case"]], - "type-enum": [ - 2, - "always", - ["BEHAVIOR", "BREAK", "DOC", "DX", "ENH", "FEAT", "FIX", "MAINT"], - ], - }, -}; diff --git a/src/repoma/check_dev_files/commitlint.py b/src/repoma/check_dev_files/commitlint.py index 8eacf0c3..7f19c138 100644 --- a/src/repoma/check_dev_files/commitlint.py +++ b/src/repoma/check_dev_files/commitlint.py @@ -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" + if not os.path.exists(path): + return + os.remove(path) + msg = f"Remove outdated {path}" + raise PrecommitError(msg) diff --git a/src/repoma/utilities/__init__.py b/src/repoma/utilities/__init__.py index d766716d..170fc30e 100644 --- a/src/repoma/utilities/__init__.py +++ b/src/repoma/utilities/__init__.py @@ -14,7 +14,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") From dbf22a5cb57bc0c66defb948684fb0762d96764e Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Thu, 5 Oct 2023 11:57:39 +0200 Subject: [PATCH 3/5] FIX: remove broken symbolic link --- src/repoma/.template/commitlint.config.js | 1 - 1 file changed, 1 deletion(-) delete mode 120000 src/repoma/.template/commitlint.config.js diff --git a/src/repoma/.template/commitlint.config.js b/src/repoma/.template/commitlint.config.js deleted file mode 120000 index c7b0f3f3..00000000 --- a/src/repoma/.template/commitlint.config.js +++ /dev/null @@ -1 +0,0 @@ -../../../commitlint.config.js \ No newline at end of file From fa895d9ce465e07712bd4c0f4787c91695426467 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Thu, 5 Oct 2023 11:58:17 +0200 Subject: [PATCH 4/5] MAINT: remove redundant `npm install` statement See https://github.com/ComPWA/commitlint-config/commit/6ac48ba8b607cee540fba6077525aa867e8dd352 --- .github/workflows/pr-linting.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pr-linting.yml b/.github/workflows/pr-linting.yml index 8f266f4b..0396363c 100644 --- a/.github/workflows/pr-linting.yml +++ b/.github/workflows/pr-linting.yml @@ -26,7 +26,6 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - - run: npm install @commitlint/config-conventional - run: npm install @compwa/commitlint-config - name: Create commitlint config run: | From e5382aa327cdba823f54849d704a662fc63ee2f4 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Thu, 5 Oct 2023 12:12:53 +0200 Subject: [PATCH 5/5] FEAT: automatically update `pr-linting.yml` --- src/repoma/.github/workflows/pr-linting.yml | 1 + src/repoma/check_dev_files/github_workflows.py | 15 ++++++++++++++- src/repoma/utilities/__init__.py | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 120000 src/repoma/.github/workflows/pr-linting.yml diff --git a/src/repoma/.github/workflows/pr-linting.yml b/src/repoma/.github/workflows/pr-linting.yml new file mode 120000 index 00000000..50ca22bf --- /dev/null +++ b/src/repoma/.github/workflows/pr-linting.yml @@ -0,0 +1 @@ +../../../../.github/workflows/pr-linting.yml \ No newline at end of file diff --git a/src/repoma/check_dev_files/github_workflows.py b/src/repoma/check_dev_files/github_workflows.py index 85486c8b..d67394a3 100644 --- a/src/repoma/check_dev_files/github_workflows.py +++ b/src/repoma/check_dev_files/github_workflows.py @@ -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 @@ -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 @@ -42,6 +43,7 @@ def main( skip_tests, test_extras, ) + executor(_update_pr_linting) executor(_recommend_vscode_extension) executor.finalize() @@ -70,6 +72,17 @@ def update() -> None: 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) + 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) + + def _update_ci_workflow( allow_deprecated: bool, doc_apt_packages: List[str], diff --git a/src/repoma/utilities/__init__.py b/src/repoma/utilities/__init__.py index 170fc30e..3ce9643c 100644 --- a/src/repoma/utilities/__init__.py +++ b/src/repoma/utilities/__init__.py @@ -1,5 +1,6 @@ """Collection of helper functions that are shared by all sub-hooks.""" +import hashlib import io import os import re @@ -39,6 +40,19 @@ class _ConfigFilePaths(NamedTuple): 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: + while True: + data = f.read(buffer_size) + if not data: + break + sha256.update(data) + return sha256.hexdigest() + + def read(input: Union[Path, io.TextIOBase, str]) -> str: # noqa: A002 if isinstance(input, (Path, str)): with open(input) as input_stream: