-
Notifications
You must be signed in to change notification settings - Fork 529
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
Introduce additional checks for dhall (deps, dirtyWhen) #16168
Merged
Merged
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e5c129d
Introduce checker for dhall (deps, dirtyWhen)
dkijania 300f270
Fix usage of checker
dkijania 752a7c6
Fix jobs (dirtyWhen & dependency)
dkijania 3f17bcb
Revert "Auxiliary commit to revert individual files from e5c129d578ca…
dkijania 2de0853
remove comment from checker.py
dkijania 416becb
Revert "Auxiliary commit to revert individual files from e5c129d578ca…
dkijania 4608a8a
use toolchain for python check + format & lints
dkijania bcbb84c
do not use inner docker when calling deps and dirtyWhen checks
dkijania aaf80c6
Using dhall-to-yaml in toolchain base while python script in toolchai…
dkijania ec996e2
run dump pipelines in docker
dkijania 16157b4
fix path to checker.py for dirtyWhen
dkijania 4bc2436
fix RosettaIntegration tests dependencies from daemon to rosetta docker
dkijania d8bbd27
remove additional empty line
dkijania ff53bd8
Merge branch 'master' into dkijania/dhall_checks
dkijania 09b0eab
Merge branch 'master' into dkijania/dhall_checks
dkijania 0a2e9ef
Merge branch 'master' into dkijania/dhall_checks
dkijania c05cf06
Merge branch 'master' into dkijania/dhall_checks
dkijania 7f7b010
Merge branch 'master' into dkijania/dhall_checks
dkijania File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,206 @@ | ||
""" | ||
Runs dhall checks like: | ||
|
||
- validate if all dependencies in jobs are covered | ||
|
||
python3 buildkite/scripts/dhall/checker.py --root ./buildkite/src/Jobs deps | ||
|
||
- all dirtyWhen entries relates to existing files | ||
|
||
python3 buildkite/scripts/dhall/checker.py --root ./buildkite/src/Jobs dirty-when | ||
|
||
- print commands for given job | ||
|
||
python3 buildkite/scripts/dhall/checker.py --root ./buildkite/src/Jobs print-cmd --job SingleNodeTest | ||
""" | ||
|
||
|
||
import argparse | ||
import subprocess | ||
import os | ||
from glob import glob | ||
import tempfile | ||
from pathlib import Path | ||
import yaml | ||
|
||
|
||
class CmdColors: | ||
HEADER = '\033[95m' | ||
OKBLUE = '\033[94m' | ||
OKCYAN = '\033[96m' | ||
OKGREEN = '\033[92m' | ||
WARNING = '\033[93m' | ||
FAIL = '\033[91m' | ||
ENDC = '\033[0m' | ||
BOLD = '\033[1m' | ||
UNDERLINE = '\033[4m' | ||
|
||
|
||
class PipelineInfoBuilder: | ||
|
||
def __init__(self, temp, file): | ||
with open(f"{temp}/{file}") as stream: | ||
try: | ||
self.pipeline = yaml.safe_load(stream) | ||
self.file = file | ||
except yaml.YAMLError as exc: | ||
print(f"cannot parse correctly {temp}/{file}, due to {exc}") | ||
exit(1) | ||
|
||
def get_steps(self): | ||
steps = [] | ||
for step in self.pipeline["pipeline"]["steps"]: | ||
key = step["key"] | ||
deps = [] | ||
if "depends_on" in step: | ||
for dependsOn in step["depends_on"]: | ||
deps.append(dependsOn["step"]) | ||
commands = step["commands"] | ||
steps.append(Step(key, deps, commands)) | ||
return steps | ||
|
||
def get_dirty(self): | ||
dirty = [] | ||
for dirtyWhen in self.pipeline["spec"]["dirtyWhen"]: | ||
path = dirtyWhen["dir"][0] if "dir" in dirtyWhen else "" | ||
exts = dirtyWhen["exts"][0] if "exts" in dirtyWhen else "" | ||
strictEnd = bool(dirtyWhen["strictEnd"]) if ( | ||
"strictEnd" in dirtyWhen) else False | ||
strictStart = bool(dirtyWhen["strictStart"]) if ( | ||
"strictStart" in dirtyWhen) else False | ||
dirty.append(DirtyWhen(path=path, strictStart=strictStart, | ||
strictEnd=strictEnd, extension=exts)) | ||
return dirty | ||
|
||
def build(self): | ||
steps = self.get_steps() | ||
dirty = self.get_dirty() | ||
return PipelineInfo(self.file, self.pipeline, steps, dirty) | ||
|
||
|
||
class DirtyWhen: | ||
|
||
def __init__(self, path, extension, strictStart, strictEnd): | ||
self.path = path | ||
self.extension = extension | ||
self.strictStart = strictStart | ||
self.strictEnd = strictEnd | ||
|
||
def calculate_path(self,repo): | ||
if not self.path: | ||
return glob(os.path.join(repo,f'**/*{self.extension}')) | ||
if not self.extension: | ||
if self.strictEnd and self.strictStart: | ||
return glob(os.path.join(repo, f'{self.path}')) | ||
if not self.strictEnd and self.strictStart: | ||
return glob(os.path.join(repo, f'{self.path}*')) | ||
if not self.strictStart and self.strictEnd: | ||
return glob(os.path.join(repo, f'**/{self.path}'), recursive= True) | ||
if not self.strictStart and not self.strictEnd: | ||
return glob(os.path.join(repo, f'*{self.path}*')) | ||
return glob(os.path.join(repo, f'{self.path}.{self.extension}')) | ||
|
||
def __str__(self): | ||
return f"path: '{self.path}', exts: '{self.extension}', startStrict:{self.strictStart}, startEnd:{self.strictEnd}" | ||
|
||
|
||
class Step: | ||
|
||
def __init__(self, key, deps, commands): | ||
self.key = key | ||
self.deps = deps | ||
self.commands = commands | ||
|
||
|
||
class PipelineInfo: | ||
|
||
def __init__(self, file, pipeline, steps, dirty): | ||
self.file = file | ||
self.pipeline = pipeline | ||
self.steps = steps | ||
self.dirty = dirty | ||
|
||
def keys(self): | ||
return [step.key for step in self.steps] | ||
|
||
|
||
parser = argparse.ArgumentParser(description='Executes mina benchmarks') | ||
parser.add_argument("--root", required=True, | ||
help="root folder where all dhall files resides") | ||
|
||
subparsers = parser.add_subparsers(dest="cmd") | ||
dirty_when = subparsers.add_parser('dirty-when') | ||
dirty_when.add_argument("--repo", required=True, | ||
help="root folder for mina repo") | ||
|
||
subparsers.add_parser('deps') | ||
|
||
|
||
run = subparsers.add_parser('print-cmd') | ||
run.add_argument("--job", required=True, help="job to run") | ||
run.add_argument("--step", required=False, help="job to run") | ||
|
||
|
||
args = parser.parse_args() | ||
|
||
pipelinesInfo = [PipelineInfoBuilder(args.root, file).build() | ||
for file in os.listdir(path=args.root)] | ||
|
||
if args.cmd == "deps": | ||
|
||
keys = [] | ||
for pipeline in pipelinesInfo: | ||
keys.extend(pipeline.keys()) | ||
|
||
failedSteps = [] | ||
|
||
for pipeline in pipelinesInfo: | ||
for step in pipeline.steps: | ||
for dep in step.deps: | ||
if not dep in keys: | ||
failedSteps.append((pipeline, step, dep)) | ||
|
||
if any(failedSteps): | ||
print("Fatal: Missing dependency resolution found:") | ||
for (pipeline, step, dep) in failedSteps: | ||
file = str.replace(pipeline.file, ".yml", ".dhall") | ||
print( | ||
f"\t{CmdColors.FAIL}[FATAL] Unresolved dependency for step '{step.key}' in '{file}' depends on non existing job '{dep}'{CmdColors.ENDC}") | ||
exit(1) | ||
else: | ||
print('Pipelines definitions correct') | ||
|
||
if args.cmd == "print-cmd": | ||
pipeline = next(filter(lambda x: args.job in x.file, pipelinesInfo)) | ||
|
||
def get_steps(): | ||
if args.step: | ||
return [next(filter(lambda x: args.step in x.key, pipeline.steps))] | ||
else: | ||
return pipeline.steps | ||
|
||
steps = get_steps() | ||
|
||
for step in steps: | ||
for command in step.commands: | ||
if not command.startswith("echo"): | ||
print(command) | ||
|
||
if args.cmd == "dirty-when": | ||
|
||
failedSteps = [] | ||
|
||
for pipeline in pipelinesInfo: | ||
for dirty in pipeline.dirty: | ||
if not bool(dirty.calculate_path(args.repo)): | ||
failedSteps.append((pipeline, dirty)) | ||
|
||
if any(failedSteps): | ||
print("Fatal: Non existing dirtyWhen path detected:") | ||
for (pipeline, dirty) in failedSteps: | ||
file = str.replace(pipeline.file, ".yml", ".dhall") | ||
print( | ||
f"\t{CmdColors.FAIL}[FATAL] Unresolved dirtyWhen path in '{file}' ('{str(dirty)}'){CmdColors.ENDC}") | ||
exit(1) | ||
else: | ||
print('Pipelines definitions correct') |
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,24 @@ | ||
#!/bin/bash | ||
|
||
ROOT=$1 | ||
OUTPUT=$2 | ||
|
||
mkdir -p "$OUTPUT" | ||
|
||
shopt -s globstar nullglob | ||
|
||
echo "Dumping pipelines from '$ROOT' to '$OUTPUT'" | ||
|
||
COUNTER=0 | ||
|
||
for file in "$ROOT"/**/*.dhall | ||
do | ||
filename=$(basename "$file") | ||
filename="${filename%.*}" | ||
|
||
dhall-to-yaml --quoted --file "$file" > "$OUTPUT"/"$filename".yml | ||
|
||
COUNTER=$((COUNTER+1)) | ||
done | ||
|
||
echo "Done. $COUNTER jobs exported" |
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
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
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
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
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This white space is killing my OCD-eyes.