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

Format fix tests #2294

Merged
merged 63 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
4682a7f
Add csharpier test files
bdovaz Jan 25, 2023
c559970
Allow csharpier to fix files
bdovaz Jan 25, 2023
06004d3
Add format_fix test code
bdovaz Jan 25, 2023
fde1611
Revert files
bdovaz Jan 25, 2023
bb8d9fc
Skip test for linters that does not format and cannot apply fixes
bdovaz Jan 25, 2023
67a2437
Add input test files
bdovaz Jan 26, 2023
ee728f3
Add input test files
bdovaz Jan 26, 2023
64d318c
Add config value
bdovaz Jan 26, 2023
c31d5ca
Add input files
bdovaz Jan 26, 2023
eb94ba0
Add input files
bdovaz Jan 26, 2023
9c5951e
Remove copy
bdovaz Jan 26, 2023
93ca9db
Fix linter activation
bdovaz Jan 26, 2023
fb8fe35
[MegaLinter] Apply linters fixes
bdovaz Jan 26, 2023
52fc988
Add input files
bdovaz Jan 27, 2023
ac1ef70
Add input files
bdovaz Jan 28, 2023
f9ae258
Fix xmllint autofix
bdovaz Jan 28, 2023
1275042
xmllint format fix test
bdovaz Jan 28, 2023
ac94cc0
Add input files
bdovaz Jan 28, 2023
a49d5d6
Fix powershell formatter autofix
bdovaz Jan 28, 2023
1b7784c
Add input files
bdovaz Jan 28, 2023
058fa32
Try to fix git error
bdovaz Jan 29, 2023
7d62197
Only use GitPython if repo exists
bdovaz Jan 29, 2023
edfcc00
Remove unused import
bdovaz Jan 29, 2023
60334ba
[MegaLinter] Apply linters fixes
bdovaz Jan 29, 2023
c54334a
Add input files
bdovaz Jan 29, 2023
a223adf
Add input files
bdovaz Jan 29, 2023
6cef2b0
Fix git error
bdovaz Jan 29, 2023
734a165
Add input files
bdovaz Jan 29, 2023
38a4f96
Fix linter error
bdovaz Jan 29, 2023
4a438b1
[MegaLinter] Apply linters fixes
bdovaz Jan 29, 2023
6231623
Add input files
bdovaz Jan 29, 2023
dce0985
Add input files
bdovaz Jan 29, 2023
aaaba6a
[MegaLinter] Apply linters fixes
bdovaz Jan 29, 2023
bf1a2b0
Fix npm-groovy-lint behaviour
bdovaz Jan 30, 2023
787780c
Add missing linters to workflows
bdovaz Jan 30, 2023
7fee71c
Add input files
bdovaz Jan 30, 2023
81a4cec
[MegaLinter] Apply linters fixes
bdovaz Jan 30, 2023
1e93c5b
Generate all linters Dockerfile
bdovaz Jan 31, 2023
1af19e0
Fixes
bdovaz Jan 31, 2023
7be3e04
Add input files
bdovaz Feb 5, 2023
43a18c6
Fix file filter logic
bdovaz Feb 5, 2023
169d249
Remove unused imports
bdovaz Feb 5, 2023
b9b5b90
[MegaLinter] Apply linters fixes
bdovaz Feb 5, 2023
7647989
Fix linter test generation
bdovaz Feb 6, 2023
2e50792
Fix bicep
bdovaz Feb 6, 2023
8e20e6f
Try to fix spell linter tests
bdovaz Feb 6, 2023
81db45f
[MegaLinter] Apply linters fixes
bdovaz Feb 6, 2023
58f4874
[MegaLinter] Apply linters fixes
bdovaz Feb 6, 2023
fff4155
Try to fix spell linter tests
bdovaz Feb 8, 2023
c1e821b
Remove commented code
bdovaz Feb 8, 2023
7ecc298
Minor changes
bdovaz Feb 8, 2023
99340ab
Update CHANGELOG.md
bdovaz Feb 8, 2023
6c5162b
Update the CONTRIBUTING.md file
bdovaz Feb 8, 2023
a6a08f8
Run build.sh --doc
bdovaz Feb 8, 2023
cd596b3
[MegaLinter] Apply linters fixes
bdovaz Feb 8, 2023
0528784
Try to fix test
bdovaz Feb 8, 2023
7831575
[MegaLinter] Apply linters fixes
bdovaz Feb 8, 2023
f279421
Decouple pre_test from core and move to linters
bdovaz Feb 13, 2023
025dcb8
Fix linter errors
bdovaz Feb 13, 2023
817a447
[MegaLinter] Apply linters fixes
bdovaz Feb 13, 2023
d9f82f1
Update Dockerfiles
bdovaz Feb 13, 2023
3c1a064
Rename input test files
bdovaz Feb 13, 2023
7f338af
Fix tests
bdovaz Feb 14, 2023
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
64 changes: 54 additions & 10 deletions .automation/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import os
import re
import shutil
import subprocess
import sys
from datetime import date, datetime
Expand Down Expand Up @@ -554,6 +555,9 @@ def match_flavor(item, flavor, flavor_info):

# Automatically generate Dockerfile for standalone linters
def generate_linter_dockerfiles():
# Remove all the contents of LINTERS_DIR beforehand so that the result is deterministic
shutil.rmtree(os.path.realpath(LINTERS_DIR))
os.makedirs(os.path.realpath(LINTERS_DIR))
# Browse descriptors
linters_md = "# Standalone linter docker images\n\n"
linters_md += "| Linter key | Docker image | Size |\n"
Expand All @@ -571,9 +575,6 @@ def generate_linter_dockerfiles():
)
# Browse descriptor linters
for linter in descriptor_linters:
# Do not build standalone linter if it does not manage SARIF
if linter.can_output_sarif is False:
bdovaz marked this conversation as resolved.
Show resolved Hide resolved
continue
# Unique linter dockerfile
linter_lower_name = linter.name.lower()
dockerfile = f"{LINTERS_DIR}/{linter_lower_name}/Dockerfile"
Expand Down Expand Up @@ -658,10 +659,21 @@ def generate_linter_dockerfiles():
# Automatically generate a test class for each linter class
# This could be done dynamically at runtime, but having a physical class is easier for developers in IDEs
def generate_linter_test_classes():
test_linters_root = f"{REPO_HOME}/megalinter/tests/test_megalinter/linters"

# Remove all the contents of test_linters_root beforehand so that the result is deterministic
shutil.rmtree(os.path.realpath(test_linters_root))
os.makedirs(os.path.realpath(test_linters_root))

linters = megalinter.linter_factory.list_all_linters()
for linter in linters:
lang_lower = linter.descriptor_id.lower()
linter_name_lower = linter.linter_name.lower().replace("-", "_")
if linter.name is not None:
linter_name = linter.name
else:
lang_lower = linter.descriptor_id.lower()
linter_name = f"{lang_lower}_{linter.linter_name}"

linter_name_lower = linter_name.lower().replace("-", "_")
test_class_code = f"""# !/usr/bin/env python3
\"\"\"
Unit tests for {linter.descriptor_id} linter {linter.linter_name}
Expand All @@ -673,14 +685,11 @@ def generate_linter_test_classes():
from megalinter.tests.test_megalinter.LinterTestRoot import LinterTestRoot


class {lang_lower}_{linter_name_lower}_test(TestCase, LinterTestRoot):
class {linter_name_lower}_test(TestCase, LinterTestRoot):
descriptor_id = "{linter.descriptor_id}"
linter_name = "{linter.linter_name}"
"""
test_class_file_name = (
f"{REPO_HOME}/megalinter/tests/test_megalinter/"
+ f"linters/{lang_lower}_{linter_name_lower}_test.py"
)
test_class_file_name = f"{test_linters_root}/{linter_name_lower}_test.py"
if not os.path.isfile(test_class_file_name):
file = open(
test_class_file_name,
Expand Down Expand Up @@ -3021,6 +3030,40 @@ def update_dependents_info():
os.system(" ".join(command))


def update_workflows_linters():
descriptors, _ = list_descriptors_for_build()

linters = ""

for descriptor in descriptors:
for linter in descriptor["linters"]:
if "name" in linter:
name = linter["name"].lower()
else:
lang_lower = descriptor["descriptor_id"].lower()
linter_name_lower = linter["linter_name"].lower().replace("-", "_")
name = f"{lang_lower}_{linter_name_lower}"

linters += f' "{name}",\n'

update_workflow_linters(".github/workflows/deploy-DEV-linters.yml", linters)
update_workflow_linters(".github/workflows/deploy-BETA-linters.yml", linters)
update_workflow_linters(".github/workflows/deploy-RELEASE-linters.yml", linters)


def update_workflow_linters(file_path, linters):
with open(file_path, "r", encoding="utf-8") as f:
file_content = f.read()
file_content = re.sub(
r"(linter:\s+\[\s*)([^\[\]]*?)(\s*\])",
rf"\1{re.escape(linters).replace(chr(92),'').strip()}\3",
file_content,
)

with open(file_path, "w") as f:
f.write(file_content)


if __name__ == "__main__":
try:
logging.basicConfig(
Expand All @@ -3045,6 +3088,7 @@ def update_dependents_info():
generate_all_flavors()
generate_linter_dockerfiles()
generate_linter_test_classes()
update_workflows_linters()
if UPDATE_DOC is True:
logging.info("Running documentation generators...")
# refresh_users_info() # deprecated since now we use github-dependents-info
Expand Down
Loading