Skip to content

Commit

Permalink
Add support for "status --verify"
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 14, 2022
1 parent e56fed5 commit 44798fb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
10 changes: 9 additions & 1 deletion dev/archery/archery/crossbow/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from pathlib import Path
import time
import sys

import click

Expand Down Expand Up @@ -273,8 +274,10 @@ def highlight(code):
help='Fetch references (branches and tags) from the remote')
@click.option('--task-filter', '-f', 'task_filters', multiple=True,
help='Glob pattern for filtering relevant tasks')
@click.option('--validate/--no-validate', default=False,
help='Return non-zero exit code if there is any non-success task')
@click.pass_obj
def status(obj, job_name, fetch, task_filters):
def status(obj, job_name, fetch, task_filters, validate):
output = obj['output']
queue = obj['queue']
if fetch:
Expand All @@ -284,6 +287,11 @@ def status(obj, job_name, fetch, task_filters):
report = ConsoleReport(job, task_filters=task_filters)
report.show(output)

if validate:
states = [task.status().combined_state for task in report.tasks.values()]
if set(states) != {'success'}:
sys.exit(1)


@crossbow.command()
@click.option('--arrow-remote', '-r', default=None,
Expand Down
10 changes: 6 additions & 4 deletions dev/archery/archery/crossbow/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ class Task(Serializable):
submitting the job to a queue.
"""

def __init__(self, ci, template, artifacts=None, params=None):
def __init__(self, name, ci, template, artifacts=None, params=None):
assert ci in {
'circle',
'travis',
Expand All @@ -800,6 +800,7 @@ def __init__(self, ci, template, artifacts=None, params=None):
'github',
'drone',
}
self.name = name
self.ci = ci
self.template = template
self.artifacts = artifacts or []
Expand Down Expand Up @@ -1083,9 +1084,10 @@ def from_config(cls, config, target, tasks=None, groups=None, params=None):
'no_rc_version': target.no_rc_version,
'no_rc_semver_version': target.no_rc_semver_version}
for task_name, task in task_definitions.items():
task = task.copy()
artifacts = task.pop('artifacts', None) or [] # because of yaml
artifacts = [fn.format(**versions) for fn in artifacts]
tasks[task_name] = Task(artifacts=artifacts, **task)
tasks[task_name] = Task(task_name, artifacts=artifacts, **task)

return cls(target=target, tasks=tasks, params=params,
template_searchpath=config.template_searchpath)
Expand Down Expand Up @@ -1221,7 +1223,7 @@ def validate(self):
# validate that the tasks are constructible
for task_name, task in self['tasks'].items():
try:
Task(**task)
Task(task_name, **task)
except Exception as e:
raise CrossbowError(
'Unable to construct a task object from the '
Expand All @@ -1245,7 +1247,7 @@ def validate(self):
params={})

for task_name, task in self['tasks'].items():
task = Task(**task)
task = Task(task_name, **task)
files = task.render_files(
self.template_searchpath,
params=dict(
Expand Down
18 changes: 14 additions & 4 deletions dev/tasks/macros.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,19 @@ on:
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Checkout Crossbow
uses: actions/checkout@v3
with:
path: crossbow
ref: {{ job.branch }}
- name: Setup Crossbow
shell: bash
run: pip install -e arrow/dev/archery[crossbow]
- name: Upload artifacts
shell: bash
run: |
archery crossbow \
--queue-path $(pwd) \
--queue-path $(pwd)/crossbow \
--queue-remote {{ queue_remote_url }} \
upload-artifacts \
--sha {{ task.branch }} \
Expand All @@ -94,10 +99,12 @@ on:
shell: bash
run: |
archery crossbow \
--queue-path $(pwd) \
--queue-path $(pwd)/crossbow \
--queue-remote {{ queue_remote_url }} \
download-artifacts \
status \
--task-filter '{{ task.name }}' \
--no-fetch \
--validate \
{{ job.branch }}
env:
CROSSBOW_GITHUB_TOKEN: {{ '${{ secrets.CROSSBOW_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}' }}
Expand Down Expand Up @@ -196,12 +203,15 @@ on:
"{{ p }}" {{ "\\" if not loop.last else "" }}
{% endfor %}
{% endif %}
- git fetch origin {{ job.branch }}
- |
archery crossbow \
--queue-path $(pwd) \
--queue-remote {{ queue_remote_url }} \
download-artifacts \
status \
--task-filter '{{ task.name }}' \
--no-fetch \
--validate \
{{ job.branch }}
{% endmacro %}

Expand Down

0 comments on commit 44798fb

Please sign in to comment.