Skip to content

Commit

Permalink
Merge pull request #16299 from MinaProtocol/merge-back-to-develop-202…
Browse files Browse the repository at this point in the history
…4-10-28

Merge back to develop
  • Loading branch information
mrmr1993 authored Oct 28, 2024
2 parents 0231d33 + 2cdc48a commit 5e79220
Show file tree
Hide file tree
Showing 74 changed files with 2,553 additions and 2,362 deletions.
14 changes: 13 additions & 1 deletion buildkite/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ lint:
find ./src/ -name "*.dhall" -print0 | xargs -I{} -0 -n1 bash -c 'echo "{}" && dhall --ascii lint --inplace {} || exit 255'

format:
find ./src/ -name "*.dhall" -print0 | xargs -I{} -0 -n1 bash -c 'echo "{}" && dhall --ascii format --inplace {} || exit 255'
find ./src/ -name "*.dhall" -print0 | xargs -I{} -0 -n1 bash -c 'echo "{}" && dhall --ascii format --inplace {} || exit 255'

check_deps:
$(eval TMP := $(shell mktemp -d))
scripts/dhall/dump_dhall_to_pipelines.sh src/Jobs "$(TMP)"
python3 scripts/dhall/checker.py --root "$(TMP)" deps

check_dirty:
$(eval TMP := $(shell mktemp -d))
scripts/dhall/dump_dhall_to_pipelines.sh src/Jobs "$(TMP)"
python3 scripts/dhall/checker.py --root "$(TMP)" dirty-when --repo "$(PWD)/../"

all: check_syntax lint format check_deps check_dirty
206 changes: 206 additions & 0 deletions buildkite/scripts/dhall/checker.py
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')
24 changes: 24 additions & 0 deletions buildkite/scripts/dhall/dump_dhall_to_pipelines.sh
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"
2 changes: 1 addition & 1 deletion buildkite/scripts/run_verify_promoted_build_job.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ if [[ "${REMOVE_PROFILE_FROM_NAME}" -eq 0 ]]; then
else
REMOVE_PROFILE_FROM_NAME="True"
fi
echo $PROMOTE_PACKAGE_DHALL_DEF'.verify_artifacts '"$DHALL_DEBIANS"' '"$DHALL_DOCKERS"' "'"${NEW_VERSION}"'" '$PROFILES_DHALL_DEF'.Type.'"${PROFILE}"' '$NETWORK_DHALL_DEF'.Type.'"${NETWORK}"' '"${DHALL_CODENAMES}"' '$DEBIAN_CHANNEL_DHALL_DEF'.Type.'"${TO_CHANNEL}"' "'"${TAG}"'" '${REMOVE_PROFILE_FROM_NAME}' '${DHALL_PUBLISH}' ' | dhall-to-yaml --quoted
echo $PROMOTE_PACKAGE_DHALL_DEF'.verify_artifacts '"$DHALL_DEBIANS"' '"$DHALL_DOCKERS"' "'"${NEW_VERSION}"'" '$PROFILES_DHALL_DEF'.Type.'"${PROFILE}"' '$NETWORK_DHALL_DEF'.Type.'"${NETWORK}"' '"${DHALL_CODENAMES}"' '$DEBIAN_CHANNEL_DHALL_DEF'.Type.'"${TO_CHANNEL}"' "'"${NEW_VERSION}"'" '${REMOVE_PROFILE_FROM_NAME}' '${DHALL_PUBLISH}' ' | dhall-to-yaml --quoted
2 changes: 1 addition & 1 deletion buildkite/src/Constants/DebianVersions.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ let bullseyeDirtyWhen =
[ S.strictlyStart (S.contains "src")
, S.strictlyStart (S.contains "automation")
, S.strictly (S.contains "Makefile")
, S.exactly "buildkite/scripts/connect-to-berkeley" "sh"
, S.exactly "buildkite/scripts/connect-to-testnet" "sh"
, S.exactly "buildkite/scripts/connect-to-mainnet-on-compatible" "sh"
, S.exactly "buildkite/scripts/rosetta-integration-tests" "sh"
, S.exactly "buildkite/scripts/rosetta-integration-tests-full" "sh"
Expand Down
33 changes: 33 additions & 0 deletions buildkite/src/Jobs/Lint/Dhall.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ let Docker = ../../Command/Docker/Type.dhall

let Size = ../../Command/Size.dhall

let RunInToolchain = ../../Command/RunInToolchain.dhall

let dump_pipelines_cmd =
Cmd.runInDocker
Cmd.Docker::{
, image = (../../Constants/ContainerImages.dhall).toolchainBase
}
"buildkite/scripts/dhall/dump_dhall_to_pipelines.sh buildkite/src/Jobs _pipelines"

in Pipeline.build
Pipeline.Config::{
, spec = JobSpec::{
Expand Down Expand Up @@ -58,5 +67,29 @@ in Pipeline.build
, image = (../../Constants/ContainerImages.dhall).toolchainBase
}
}
, Command.build
Command.Config::{
, commands =
[ dump_pipelines_cmd ]
# RunInToolchain.runInToolchainBullseye
([] : List Text)
"python3 ./buildkite/scripts/dhall/checker.py --root _pipelines deps"
, label = "Dhall: deps"
, key = "check-dhall-deps"
, target = Size.Multi
, docker = None Docker.Type
}
, Command.build
Command.Config::{
, commands =
[ dump_pipelines_cmd ]
# RunInToolchain.runInToolchainBullseye
([] : List Text)
"python3 ./buildkite/scripts/dhall/checker.py --root _pipelines dirty-when --repo ."
, label = "Dhall: dirtyWhen"
, key = "check-dhall-dirty"
, target = Size.Multi
, docker = None Docker.Type
}
]
}
5 changes: 1 addition & 4 deletions buildkite/src/Jobs/Lint/ValidationService.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ in Pipeline.build
(S.contains "buildkite/src/Jobs/Lint/ValidationService")

in JobSpec::{
, dirtyWhen =
[ dirtyDhallDir
, S.strictlyStart (S.contains ValidationService.rootPath)
]
, dirtyWhen = [ dirtyDhallDir ]
, path = "Lint"
, name = "ValidationService"
, tags =
Expand Down
2 changes: 1 addition & 1 deletion buildkite/src/Jobs/Test/PatchArchiveTest.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ in Pipeline.build
, spec = JobSpec::{
, dirtyWhen =
[ S.strictlyStart (S.contains "src")
, S.exactly "scripts/path-archive-test" "sh"
, S.exactly "scripts/patch-archive-test" "sh"
, S.exactly "buildkite/src/Jobs/Test/PatchArchiveTest" "dhall"
, S.exactly "buildkite/src/Command/PatchArchiveTest" "dhall"
]
Expand Down
4 changes: 2 additions & 2 deletions buildkite/src/Jobs/Test/TerraformNetworkTest.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ in Pipeline.build
Pipeline.Config::{
, spec =
let unitDirtyWhen =
[ S.strictlyStart (S.contains "src/automation/terraform")
, S.strictlyStart (S.contains "src/helm")
[ S.strictlyStart (S.contains "automation/terraform")
, S.strictlyStart (S.contains "helm")
, S.strictlyStart
(S.contains "buildkite/src/Jobs/Test/TerraformNetworkTest")
, S.strictlyStart
Expand Down
11 changes: 3 additions & 8 deletions buildkite/src/Jobs/Test/TestnetIntegrationTests.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,15 @@ in Pipeline.build
, S.strictlyStart (S.contains "dockerfiles")
, S.strictlyStart
(S.contains "buildkite/src/Jobs/Test/TestnetIntegrationTest")
, S.strictlyStart
(S.contains "buildkite/src/Jobs/Command/TestExecutive")
, S.strictlyStart (S.contains "buildkite/src/Command/TestExecutive")
, S.strictlyStart
(S.contains "automation/terraform/modules/o1-integration")
, S.strictlyStart
(S.contains "automation/terraform/modules/kubernetes/testnet")
, S.strictlyStart
( S.contains
"automation/buildkite/script/run-test-executive-cloud"
)
(S.contains "buildkite/scripts/run-test-executive-cloud")
, S.strictlyStart
( S.contains
"automation/buildkite/script/run-test-executive-local"
)
(S.contains "buildkite/scripts/run-test-executive-local")
]
, path = "Test"
, name = "TestnetIntegrationTests"
Expand Down
3 changes: 1 addition & 2 deletions buildkite/src/Jobs/Test/TestnetIntegrationTestsLong.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ in Pipeline.build
, S.strictlyStart (S.contains "dockerfiles")
, S.strictlyStart
(S.contains "buildkite/src/Jobs/Test/TestnetIntegrationTest")
, S.strictlyStart
(S.contains "buildkite/src/Jobs/Command/TestExecutive")
, S.strictlyStart (S.contains "buildkite/src/Command/TestExecutive")
, S.strictlyStart
(S.contains "automation/terraform/modules/o1-integration")
, S.strictlyStart
Expand Down
2 changes: 1 addition & 1 deletion src/app/libp2p_helper/src/libp2p_helper/bitswap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func TestBitswapSmoke(t *testing.T) {
}

func TestBitswapSmall(t *testing.T) {
testBitswap(t, 20, 100, 5, 1<<16, false)
testBitswap(t, 20, 10, 5, 1<<16, false)
}

func TestBitswapQC(t *testing.T) {
Expand Down
Loading

0 comments on commit 5e79220

Please sign in to comment.