-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,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" |
This file contains 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,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 |
This file contains 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 @@ | ||
yamllint |
This file contains 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,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 |
This file contains 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,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() |