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

Address a subset of ARROW-2676 PR comments #2

Merged
merged 3 commits into from
Jun 18, 2018
Merged
Changes from all commits
Commits
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
44 changes: 32 additions & 12 deletions dev/tasks/crossbow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# specific language governing permissions and limitations
# under the License.

import os
import re
import yaml
import time
Expand Down Expand Up @@ -110,11 +111,14 @@ def remote(self):
def origin(self):
return self.repo.remotes['origin']

@property
def email(self):
return next(self.repo.config.get_multivar('user.email'))

@property
def signature(self):
name = next(self.repo.config.get_multivar('user.name'))
email = next(self.repo.config.get_multivar('user.email'))
return pygit2.Signature(name, email, int(time.time()))
return pygit2.Signature(name, self.email, int(time.time()))

def parse_user_repo(self):
m = re.match('.*\/([^\/]+)\/([^\/\.]+)(\.git)?$', self.remote.url)
Expand Down Expand Up @@ -184,7 +188,7 @@ def put(self, job, prefix='build'):

# create job's branch
branch = self._create_branch(job.branch, files=job.files())
tag = self._create_tag(job.branch, branch.target)
self._create_tag(job.branch, branch.target)

return branch

Expand Down Expand Up @@ -286,10 +290,29 @@ def crossbow():
pass


def github_token_validation_callback(ctx, param, value):
if value 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.'
)
return value


github_token = click.option(
'--github-token',
default=None,
envvar='CROSSBOW_GITHUB_TOKEN',
help='OAuth token for Github authentication',
callback=github_token_validation_callback,
)


@crossbow.command()
@click.argument('task-names', nargs=-1, required=True)
@click.option('--job-prefix', default='build',
help='Arbitrary prefix for branch names, e.g. nightly')
help='Arbitrary prefix for branch names, e.g. nightly')
@click.option('--config-path', default=DEFAULT_CONFIG_PATH,
help='Task configuration yml. Defaults to tasks.yml')
@click.option('--dry-run/--push', default=False,
Expand All @@ -301,8 +324,7 @@ def crossbow():
@click.option('--queue-path', default=DEFAULT_QUEUE_PATH,
help='The repository path used for scheduling the tasks. '
'Defaults to crossbow directory placed next to arrow')
@click.option('--github-token', default=False, envvar='CROSSBOW_GITHUB_TOKEN',
help='Oauth token for Github authentication')
@github_token
def submit(task_names, job_prefix, config_path, dry_run, arrow_path,
queue_path, github_token):
target = Repo(arrow_path)
Expand All @@ -319,7 +341,7 @@ def submit(task_names, job_prefix, config_path, dry_run, arrow_path,
variables = {
# these should be renamed
'PLAT': 'x86_64',
'EMAIL': MESSAGE_EMAIL,
'EMAIL': os.environ.get('CROSSBOW_EMAIL', target.email),
'BUILD_TAG': job_id,
'BUILD_REF': str(target.head),
'ARROW_SHA': str(target.head),
Expand All @@ -346,7 +368,7 @@ def submit(task_names, job_prefix, config_path, dry_run, arrow_path,
job.branch = job_id

yaml_format = yaml.dump(job.to_dict(), default_flow_style=False)
click.echo(yaml_format)
click.echo(yaml_format.strip())

if not dry_run:
queue.put(job)
Expand All @@ -359,8 +381,7 @@ def submit(task_names, job_prefix, config_path, dry_run, arrow_path,
@click.option('--queue-path', default=DEFAULT_QUEUE_PATH,
help='The repository path used for scheduling the tasks. '
'Defaults to crossbow directory placed next to arrow')
@click.option('--github-token', default=False, envvar='CROSSBOW_GITHUB_TOKEN',
help='Oauth token for Github authentication')
@github_token
def status(job_name, queue_path, github_token):
queue = Queue(queue_path)
username, reponame = queue.parse_user_repo()
Expand Down Expand Up @@ -390,8 +411,7 @@ def status(job_name, queue_path, github_token):
@click.option('--queue-path', default=DEFAULT_QUEUE_PATH,
help='The repository path used for scheduling the tasks. '
'Defaults to crossbow directory placed next to arrow')
@click.option('--github-token', default=False, envvar='CROSSBOW_GITHUB_TOKEN',
help='Oauth token for Github authentication')
@github_token
def artifacts(job_name, target_dir, queue_path, github_token):
queue = Queue(queue_path)
username, reponame = queue.parse_user_repo()
Expand Down