Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
trym-b committed Mar 9, 2024
1 parent 0c54e8c commit bbda224
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Main

on: push

jobs:
yamllint:
name: Lint localization/ with yamllint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install requirements
run: pip install --requirement scripts/lint/requirements.txt
- name: Lint
run: python scripts/lint/yaml.py --directory localization/ \
--paths-to-ignore \
"localization/korean/ib_l_korean .yml" \
"localization/english/romaioi_events_l_english.yml" \
"localization/english/br_hippodrome_l_english.yml" \
"localization/english/romaioi_names_l_english.yml" \
"localization/english/romaioi_misc_l_english.yml" \
"localization/english/addons/warispolitics_l_english.yml" \
"localization/english/addons/ib_l_english.yml" \
"localization/english/replace/country_flavor_text_l_english.yml" \
"localization/english/replace/cultures_l_english.yml" \
"localization/english/replace/misc_l_english.yml" \
"localization/english/replace/countries_l_english.yml" \
"localization/english/replace/hub_names_l_english.yml" \
"localization/english/replace/inventions_l_english.yml"
32 changes: 32 additions & 0 deletions scripts/lint/.yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---

yaml-files:
- '*.yaml'
- '*.yml'
- '.yamllint'

rules:
anchors: enable
braces: enable
brackets: enable
colons: enable
commas: enable
comments: disable
comments-indentation: disable
document-end: disable
document-start: disable
empty-lines: disable
empty-values: disable
float-values: disable
hyphens: enable
indentation: disable
key-duplicates: enable
key-ordering: disable
line-length: disable
new-line-at-end-of-file: disable
new-lines: enable
octal-values: disable
quoted-strings: disable
trailing-spaces: disable
truthy:
level: warning
1 change: 1 addition & 0 deletions scripts/lint/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yamllint
12 changes: 12 additions & 0 deletions scripts/lint/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile scripts/lint/requirements.in
#
pathspec==0.12.1
# via yamllint
pyyaml==6.0.1
# via yamllint
yamllint==1.35.1
# via -r scripts/lint/requirements.in
55 changes: 55 additions & 0 deletions scripts/lint/yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from argparse import ArgumentParser, Namespace
from pathlib import Path
from subprocess import run
from sys import exit


def _args() -> Namespace:
parser = ArgumentParser()
parser.add_argument(
"--directory", required=True, type=Path, help="Directory to check"
)
parser.add_argument(
"--paths-to-ignore", type=Path, nargs="*", help="Paths to ignore"
)
return parser.parse_args()


def _main() -> None:
args = _args()
all_files = list(args.directory.rglob("*.yaml")) + list(
args.directory.rglob("*.yml")
)

paths_to_lint = []

if args.paths_to_ignore is None:
paths_to_lint = all_files
else:
for path in all_files:
if path not in args.paths_to_ignore:
paths_to_lint.append(path)

config_file = (Path(__file__).parent / ".yamllint.yml").relative_to(Path.cwd())

for file in paths_to_lint:
print(f"Linting {file}")
command = [
"yamllint",
file,
"--config-file",
config_file,
]
result = run(command, text=True)
if result.returncode != 0:
print("Linting errors found, see the error above for more details")
print(
f"To run this test locally, run the following command:\n{' '.join(map(str, command))}"
)
exit(result.returncode)

print("YAML linting complete")


if __name__ == "__main__":
_main()

0 comments on commit bbda224

Please sign in to comment.