Apache DataFusion SQL Query Engine
ARROW-8371: [Crossbow] Implement and exercise sanity checks for tasks.yml
Krisztián Szűcsb6832a1eb5c7
diff --git a/.github/workflows/archery.yml b/.github/workflows/archery.ymlindex 1542eb60d9..19430615a6 100644--- a/.github/workflows/archery.yml+++ b/.github/workflows/archery.yml@@ -15,23 +15,25 @@# specific language governing permissions and limitations# under the License.-name: Archery+name: Archery & Crossbowon:push:paths:- '.github/workflows/archery.yml'- 'dev/archery/**'+ - 'dev/tasks/**'pull_request:paths:- '.github/workflows/archery.yml'- 'dev/archery/**'+ - 'dev/tasks/**'jobs:- archery:+ test:if: ${{ !contains(github.event.pull_request.title, 'WIP') }}- name: Archery Unittests+ name: Archery Unittests and Crossbow Check Configruns-on: ubuntu-lateststeps:- name: Checkout Arrow@@ -47,7 +49,10 @@ jobs:python-version: '3.7'- name: Installworking-directory: dev/archery- run: pip install pytest responses ruamel.yaml -e .- - name: Test+ run: pip install pytest responses ruamel.yaml toolz jinja2 -e .+ - name: Archery Unittestsworking-directory: dev/archeryrun: pytest -v archery+ - name: Crossbow Check Config+ working-directory: dev/tasks+ run: python crossbow.py check-configdiff --git a/dev/tasks/conda-recipes/azure.linux.yml b/dev/tasks/conda-recipes/azure.linux.ymlindex 4c1813d6ec..fc64e51545 100755--- a/dev/tasks/conda-recipes/azure.linux.yml+++ b/dev/tasks/conda-recipes/azure.linux.yml@@ -46,7 +46,7 @@ jobs:- script: |python arrow/dev/tasks/crossbow.py \--queue-path . \- --queue-remote {{ queue.remote_url }} \+ --queue-remote {{ queue_remote_url }} \upload-artifacts \--sha {{ task.branch }} \--tag {{ task.tag }} \diff --git a/dev/tasks/conda-recipes/azure.osx.yml b/dev/tasks/conda-recipes/azure.osx.ymlindex 52b6163974..0e2487d98d 100755--- a/dev/tasks/conda-recipes/azure.osx.yml+++ b/dev/tasks/conda-recipes/azure.osx.yml@@ -78,7 +78,7 @@ jobs:conda install -y click github3.py jinja2 jira pygit2 ruamel.yaml setuptools_scm toolzpython arrow/dev/tasks/crossbow.py \--queue-path . \- --queue-remote {{ queue.remote_url }} \+ --queue-remote {{ queue_remote_url }} \upload-artifacts \--sha {{ task.branch }} \--tag {{ task.tag }} \diff --git a/dev/tasks/conda-recipes/azure.win.yml b/dev/tasks/conda-recipes/azure.win.ymlindex 749400ea40..d13bef48f1 100755--- a/dev/tasks/conda-recipes/azure.win.yml+++ b/dev/tasks/conda-recipes/azure.win.yml@@ -93,7 +93,7 @@ jobs:- script: |python arrow/dev/tasks/crossbow.py ^--queue-path . ^- --queue-remote {{ queue.remote_url }} ^+ --queue-remote {{ queue_remote_url }} ^upload-artifacts ^--sha {{ task.branch }} ^--tag {{ task.tag }} ^diff --git a/dev/tasks/crossbow.py b/dev/tasks/crossbow.pyindex 132c413e5a..e7821ac7b2 100755--- a/dev/tasks/crossbow.py+++ b/dev/tasks/crossbow.py@@ -36,8 +36,7 @@ from collections import namedtupleimport clickimport toolz-from setuptools_scm.git import parse as parse_git_version-from setuptools_scm.version import guess_next_version+from ruamel.yaml import YAMLtry:@@ -340,6 +339,12 @@ class Repo:def push(self, refs=None, github_token=None):github_token = github_token or self.github_token+ if github_token is None:+ raise click.ClickException(+ 'Could not determine GitHub token. Please set the '+ 'CROSSBOW_GITHUB_TOKEN environment variable to a '+ 'valid GitHub access token or pass one to --github-token.'+ )callbacks = GitRemoteCallbacks(github_token)refs = refs or []try:@@ -745,7 +750,8 @@ class Queue(Repo):# adding CI's name to the end of the branch in order to use skip# patterns on travis and circlecitask.branch = '{}-{}-{}'.format(job.branch, task.ci, task_name)- files = task.render_files(job=job, arrow=job.target, queue=self)+ files = task.render_files(arrow=job.target,+ queue_remote_url=self.remote_url)branch = self.create_branch(task.branch, files=files)self.create_tag(task.tag, branch.target)task.commit = str(branch.target)@@ -759,8 +765,12 @@ def get_version(root, **kwargs):Parse function for setuptools_scm that ignores tags for non-C++subprojects, e.g. apache-arrow-js-XXX tags."""- kwargs['describe_command'] =\+ from setuptools_scm.git import parse as parse_git_version+ from setuptools_scm.version import guess_next_version++ kwargs['describe_command'] = ('git describe --dirty --tags --long --match "apache-arrow-[0-9].*"'+ )version = parse_git_version(root, **kwargs)return version.format_next_version(guess_next_version)@@ -840,10 +850,20 @@ class Task(Serializable):def render_files(self, **extra_params):from jinja2 import Template, StrictUndefined+ from jinja2.exceptions import TemplateError+path = CWD / self.templateparams = toolz.merge(self.params, extra_params)template = Template(path.read_text(), undefined=StrictUndefined)- rendered = template.render(task=self, **params)+ try:+ rendered = template.render(task=self, **params)+ except TemplateError as e:+ raise RuntimeError(+ 'Failed to render template `{}` with {}: {}'.format(+ path, e.__class__.__name__, str(e)+ )+ )+tree = toolz.merge(_default_tree, {self.filename: rendered})return unflatten_tree(tree)@@ -962,47 +982,13 @@ class Job(Serializable):click.ClickExceptionIf invalid groups or tasks has been passed."""- config_groups = dict(config['groups'])- config_tasks = dict(config['tasks'])- valid_groups = set(config_groups.keys())- valid_tasks = set(config_tasks.keys())- group_whitelist = list(groups or [])- task_whitelist = list(tasks or [])-- # validate that the passed groups are defined in the config- requested_groups = set(group_whitelist)- invalid_groups = requested_groups - valid_groups- if invalid_groups:- msg = 'Invalid group(s) {!r}. Must be one of {!r}'.format(- invalid_groups, valid_groups- )- raise click.ClickException(msg)-- # merge the tasks defined in the selected groups- task_patterns = [list(config_groups[name]) for name in group_whitelist]- task_patterns = set(sum(task_patterns, task_whitelist))-- # treat the task names as glob patterns to select tasks more easily- requested_tasks = set(- toolz.concat(- fnmatch.filter(valid_tasks, p) for p in task_patterns- )- )-- # validate that the passed and matched tasks are defined in the config- invalid_tasks = requested_tasks - valid_tasks- if invalid_tasks:- msg = 'Invalid task(s) {!r}. Must be one of {!r}'.format(- invalid_tasks, valid_tasks- )- raise click.ClickException(msg)+ task_definitions = config.select(tasks, groups=groups)# instantiate the taskstasks = {}versions = {'version': target.version,'no_rc_version': target.no_rc_version}- for task_name in requested_tasks:- task = config_tasks[task_name]+ for task_name, task in task_definitions.items():artifacts = task.pop('artifacts', None) or [] # because of yamlartifacts = [fn.format(**versions) for fn in artifacts]tasks[task_name] = Task(artifacts=artifacts, **task)@@ -1059,6 +1045,96 @@ class Job(Serializable):yield (task_name, task, status.result(), assets.result())+class Config(dict):++ @classmethod+ def load_yaml(cls, path):+ with Path(path).open() as fp:+ return cls(yaml.load(fp))++ def select(self, tasks=None, groups=None):+ config_groups = dict(self['groups'])+ config_tasks = dict(self['tasks'])+ valid_groups = set(config_groups.keys())+ valid_tasks = set(config_tasks.keys())+ group_whitelist = list(groups or [])+ task_whitelist = list(tasks or [])++ # validate that the passed groups are defined in the config+ requested_groups = set(group_whitelist)+ invalid_groups = requested_groups - valid_groups+ if invalid_groups:+ msg = 'Invalid group(s) {!r}. Must be one of {!r}'.format(+ invalid_groups, valid_groups+ )+ raise ValueError(msg)++ # merge the tasks defined in the selected groups+ task_patterns = [list(config_groups[name]) for name in group_whitelist]+ task_patterns = set(sum(task_patterns, task_whitelist))++ # treat the task names as glob patterns to select tasks more easily+ requested_tasks = set(+ toolz.concat(+ fnmatch.filter(valid_tasks, p) for p in task_patterns+ )+ )++ # validate that the passed and matched tasks are defined in the config+ invalid_tasks = requested_tasks - valid_tasks+ if invalid_tasks:+ msg = 'Invalid task(s) {!r}. Must be one of {!r}'.format(+ invalid_tasks, valid_tasks+ )+ raise ValueError(msg)++ return {+ task_name: config_tasks[task_name] for task_name in requested_tasks+ }++ def validate(self):+ # validate that the task groups are properly referening the tasks+ for group in self['groups']:+ tasks = self.select(groups=[group])+ if not tasks:+ raise ValueError(+ "The patterns defined for task group `{}` are not "+ "matching any of the tasks defined in the configuration "+ "file.".format(group)+ )++ # validate that the tasks are constructible+ for task_name, task in self['tasks'].items():+ try:+ Task(**task)+ except Exception as e:+ raise ValueError(+ 'Unable to construct a task object from the '+ 'definition of task `{}`. The original error message '+ 'is: `{}`'.format(task_name, str(e))+ )++ # validate that the defined tasks are renderable, in order to to that+ # define the required object with dummy data+ target = Target(+ head='e279a7e06e61c14868ca7d71dea795420aea6539',+ branch='master',+ remote='https://github.com/apache/arrow',+ version='1.0.0dev123',+ email='[email protected]'+ )++ for task_name, task in self['tasks'].items():+ task = Task(**task)+ files = task.render_files(+ arrow=target,+ queue_remote_url='https://github.com/org/crossbow'+ )+ if not files:+ raise ValueError('No files have been rendered for task `{}`'+ .format(task_name))++class Report:def __init__(self, job):@@ -1355,11 +1431,11 @@ DEFAULT_QUEUE_PATH = CWD.parents[2] / 'crossbow'@click.option('--github-token', '-t', default=None,help='OAuth token for GitHub authentication')@click.option('--arrow-path', '-a',- type=click.Path(exists=True), default=str(DEFAULT_ARROW_PATH),+ type=click.Path(), default=str(DEFAULT_ARROW_PATH),help='Arrow\'s repository path. Defaults to the repository of ''this script')@click.option('--queue-path', '-q',- type=click.Path(exists=True), default=str(DEFAULT_QUEUE_PATH),+ type=click.Path(), default=str(DEFAULT_QUEUE_PATH),help='The repository path used for scheduling the tasks. ''Defaults to crossbow directory placed next to arrow')@click.option('--queue-remote', '-qr', default=None,@@ -1370,13 +1446,6 @@ DEFAULT_QUEUE_PATH = CWD.parents[2] / 'crossbow'@click.pass_contextdef crossbow(ctx, github_token, arrow_path, queue_path, queue_remote,output_file):- if github_token is None:- raise click.ClickException(- 'Could not determine GitHub token. Please set the '- 'CROSSBOW_GITHUB_TOKEN environment variable to a '- 'valid GitHub access token or pass one to --github-token.'- )-ctx.ensure_object(dict)ctx.obj['output'] = output_filectx.obj['arrow'] = Repo(arrow_path)@@ -1416,6 +1485,16 @@ def changelog(obj, changelog_path, arrow_version, is_website, jira_username,'changes')[email protected]('--config-path', '-c',+ type=click.Path(exists=True), default=DEFAULT_CONFIG_PATH,+ help='Task configuration yml. Defaults to tasks.yml')+def check_config(config_path):+ # load available tasks configuration and groups from yaml+ config = Config.load_yaml(config_path)+ config.validate()++@crossbow.command()@click.argument('tasks', nargs=-1, required=False)@click.option('--group', '-g', 'groups', multiple=True,@@ -1447,8 +1526,8 @@ def submit(obj, tasks, groups, job_prefix, config_path, arrow_version,queue, arrow = obj['queue'], obj['arrow']# load available tasks configuration and groups from yaml- with Path(config_path).open() as fp:- config = yaml.load(fp)+ config = Config.load_yaml(config_path)+ config.validate()# Override the detected repo url / remote, branch and sha - this aims to# make release procedure a bit simpler.@@ -1461,7 +1540,8 @@ def submit(obj, tasks, groups, job_prefix, config_path, arrow_version,head=arrow_sha, version=arrow_version)# instantiate the job object- job = Job.from_config(config, target=target, tasks=tasks, groups=groups)+ job = Job.from_config(config=config, target=target, tasks=tasks,+ groups=groups)if dry_run:yaml.dump(job, output)diff --git a/dev/tasks/gandiva-jars/travis.linux.yml b/dev/tasks/gandiva-jars/travis.linux.ymlindex 843dd99ccc..67102319dd 100644--- a/dev/tasks/gandiva-jars/travis.linux.yml+++ b/dev/tasks/gandiva-jars/travis.linux.yml@@ -62,7 +62,3 @@ deploy:skip_cleanup: trueon:tags: true--notifications:- email:- - {{ job.email }}diff --git a/dev/tasks/gandiva-jars/travis.osx.yml b/dev/tasks/gandiva-jars/travis.osx.ymlindex 439d7afbea..f1e9cfddac 100644--- a/dev/tasks/gandiva-jars/travis.osx.yml+++ b/dev/tasks/gandiva-jars/travis.osx.yml@@ -62,12 +62,8 @@ script:- >python3 dev/tasks/crossbow.py--queue-path $TRAVIS_BUILD_DIR- --queue-remote {{ queue.remote_url }}+ --queue-remote {{ queue_remote_url }}upload-artifacts--sha {{ task.branch }}--tag {{ task.tag }}--pattern "dist/*.jar"--notifications:- email:- - {{ job.email }}diff --git a/dev/tasks/homebrew-formulae/travis.osx.r.yml b/dev/tasks/homebrew-formulae/travis.osx.r.ymlindex ea22f69a60..a9aa3611f1 100644--- a/dev/tasks/homebrew-formulae/travis.osx.r.yml+++ b/dev/tasks/homebrew-formulae/travis.osx.r.yml@@ -53,7 +53,3 @@ script:after_failure:# If there's a build failure, it's probably in this log- cat arrow.Rcheck/00install.out--notifications:- email:- - {{ job.email }}diff --git a/dev/tasks/homebrew-formulae/travis.osx.yml b/dev/tasks/homebrew-formulae/travis.osx.ymlindex 4d189a6c49..b93d1812cc 100644--- a/dev/tasks/homebrew-formulae/travis.osx.yml+++ b/dev/tasks/homebrew-formulae/travis.osx.yml@@ -39,7 +39,3 @@ before_script:script:- brew install -v --build-from-source --HEAD $ARROW_FORMULA- brew test $ARROW_FORMULA--notifications:- email:- - {{ job.email }}diff --git a/dev/tasks/linux-packages/github.linux.arm64.yml b/dev/tasks/linux-packages/github.linux.arm64.ymlindex f6eadbd6c5..f2fc32dda6 100644--- a/dev/tasks/linux-packages/github.linux.arm64.yml+++ b/dev/tasks/linux-packages/github.linux.arm64.yml@@ -83,7 +83,7 @@ jobs:run: |python arrow/dev/tasks/crossbow.py \--queue-path . \- --queue-remote {{ queue.remote_url }} \+ --queue-remote {{ queue_remote_url }} \upload-artifacts \{%- for extension in upload_extensions %}--pattern "**/*{{ extension }}" \diff --git a/dev/tasks/linux-packages/github.linux.yml b/dev/tasks/linux-packages/github.linux.ymlindex 319a4dc1b4..a6b401f54d 100644--- a/dev/tasks/linux-packages/github.linux.yml+++ b/dev/tasks/linux-packages/github.linux.yml@@ -68,7 +68,7 @@ jobs:run: |python arrow/dev/tasks/crossbow.py \--queue-path . \- --queue-remote {{ queue.remote_url }} \+ --queue-remote {{ queue_remote_url }} \upload-artifacts \{%- for extension in upload_extensions %}--pattern "**/*{{ extension }}" \diff --git a/dev/tasks/python-wheels/appveyor.yml b/dev/tasks/python-wheels/appveyor.ymlindex eca2ba5612..0782f2cbf8 100644--- a/dev/tasks/python-wheels/appveyor.yml+++ b/dev/tasks/python-wheels/appveyor.yml@@ -72,8 +72,3 @@ deploy:artifact: /.*\.whl/draft: falseprerelease: false--notifications:- - provider: Email- to:- - {{ job.email }}diff --git a/dev/tasks/python-wheels/azure.linux.yml b/dev/tasks/python-wheels/azure.linux.ymlindex b6b00f9d71..59b2767f6b 100644--- a/dev/tasks/python-wheels/azure.linux.yml+++ b/dev/tasks/python-wheels/azure.linux.yml@@ -82,7 +82,7 @@ jobs:set -expython arrow/dev/tasks/crossbow.py \--queue-path . \- --queue-remote {{ queue.remote_url }} \+ --queue-remote {{ queue_remote_url }} \upload-artifacts \--pattern "arrow/python/{{ wheel_dir }}/dist/*" \--sha {{ task.branch }} \diff --git a/dev/tasks/python-wheels/travis.osx.yml b/dev/tasks/python-wheels/travis.osx.ymlindex 0c87fded30..7e0d32ad2c 100644--- a/dev/tasks/python-wheels/travis.osx.yml+++ b/dev/tasks/python-wheels/travis.osx.yml@@ -80,7 +80,7 @@ install:- pip3 install click ruamel.yaml setuptools_scm github3.py toolz requests[security]- python3 arrow/dev/tasks/crossbow.py--queue-path $(pwd)- --queue-remote {{ queue.remote_url }}+ --queue-remote {{ queue_remote_url }}upload-artifacts--sha {{ task.branch }}--tag {{ task.tag }}@@ -91,7 +91,3 @@ install:- path=$(ls arrow/python/dist/*.whl)- curl -F "package=@${path}" https://${CROSSBOW_GEMFURY_TOKEN}@push.fury.io/${CROSSBOW_GEMFURY_ORG}/{% endif %}--notifications:- email:- - {{ job.email }}diff --git a/dev/tasks/tasks.yml b/dev/tasks/tasks.ymlindex 8f145ff54c..1a5b0f061d 100644--- a/dev/tasks/tasks.yml+++ b/dev/tasks/tasks.yml@@ -401,15 +401,6 @@ tasks:artifacts:- pyarrow-{no_rc_version}-cp37-cp37m-macosx_10_9_intel.whl- wheel-osx-cp37m-azure:- ci: azure- platform: osx- template: python-wheels/azure.osx.yml- params:- python_version: 3.7- artifacts:- - pyarrow-{no_rc_version}-cp37-cp37m-macosx_10_9_intel.whl-wheel-osx-cp38:ci: travisplatform: osx