From 60fb423adff1cc24e645d162c45ee26881ba8d29 Mon Sep 17 00:00:00 2001 From: Tony Breeds Date: Wed, 5 Sep 2018 12:55:06 +1000 Subject: [PATCH] Add a tox environment for flexible candidate checking By default ci_check_all_candidate_files.py, does as it implies and checks all candidates for the current election. Add new operation modes for: 1. Checking all files for the current git commit '--HEAD' 2. Checking all files specified on the command line We also add a voting job on the check pipeline only for validating the current review. Local users are encouraged to use this as: tox -e ci-checks-review ; or tox -e ci-checks-review -- path/to/file Change-Id: I0c82c59409bb58169840de42c02072aeae182b2b Co-authored-by: Doug Hellmann --- .zuul.d/jobs.yaml | 17 ++++++++-- .zuul.d/project.yaml | 5 +-- .../cmds/ci_check_all_candidate_files.py | 31 ++++++++++++++++++- tox.ini | 5 ++- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/.zuul.d/jobs.yaml b/.zuul.d/jobs.yaml index 40a2538f..e4d8dfab 100644 --- a/.zuul.d/jobs.yaml +++ b/.zuul.d/jobs.yaml @@ -1,10 +1,21 @@ - job: - name: election-tox-ci-checks + name: election-tox-ci-checks-election parent: openstack-tox description: | - Run the ci-checks tox environment + Run the ci-checks-election tox environment This environment runs the easy, for a machine, to validate election checks. vars: - tox_envlist: ci-checks + tox_envlist: ci-checks-election + +- job: + name: election-tox-ci-checks-review + parent: openstack-tox + description: | + Run the ci-checks-review tox environment + + This environment runs the easy, for a machine, to validate election + checks against only files modified in the current review. + vars: + tox_envlist: ci-checks-review diff --git a/.zuul.d/project.yaml b/.zuul.d/project.yaml index e77c584e..841faad4 100644 --- a/.zuul.d/project.yaml +++ b/.zuul.d/project.yaml @@ -7,12 +7,13 @@ jobs: - openstack-tox-py27 - openstack-tox-linters - - election-tox-ci-checks + - election-tox-ci-checks-review + - election-tox-ci-checks-election gate: jobs: - openstack-tox-py27 - openstack-tox-linters - - election-tox-ci-checks + - election-tox-ci-checks-election post: jobs: - publish-tox-docs-static diff --git a/openstack_election/cmds/ci_check_all_candidate_files.py b/openstack_election/cmds/ci_check_all_candidate_files.py index 2aab2b28..bf7fdffc 100755 --- a/openstack_election/cmds/ci_check_all_candidate_files.py +++ b/openstack_election/cmds/ci_check_all_candidate_files.py @@ -16,6 +16,7 @@ from __future__ import unicode_literals import argparse import os +import subprocess from openstack_election import check_candidacy from openstack_election import utils @@ -75,6 +76,19 @@ def check_for_changes(projects, filepath, limit): return bool(changes_found) +def find_modified_candidate_files(): + "Return a list of files modified by the most recent commit." + results = subprocess.check_output( + ['git', 'diff', '--name-only', '--pretty=format:', 'HEAD^'] + ).decode('utf-8') + filenames = [ + l.strip() + for l in results.splitlines() + if l.startswith(utils.CANDIDATE_PATH + '/') + ] + return filenames + + def main(): description = ('Check all files under the current open election are valid') parser = argparse.ArgumentParser(description) @@ -90,6 +104,14 @@ def main(): default=utils.conf['release'], help=('The relase to validate candidates against. ' 'Default: %(default)s')) + parser.add_argument('--HEAD', + dest='head_only', + action='store_true', + default=False, + help='Validate all candidates.') + parser.add_argument('files', + nargs='*', + help='Candidate files to validate.') args = parser.parse_args() errors = False @@ -99,7 +121,14 @@ def main(): projects = utils.get_projects(tag=args.tag, fallback_to_master=True) - for filepath in utils.find_candidate_files(election=args.release): + if args.files: + to_process = args.files + elif args.head_only: + to_process = find_modified_candidate_files() + else: + to_process = utils.find_candidate_files(election=args.release) + + for filepath in to_process: candidate_ok = True candidate_ok &= validate_filename(filepath) diff --git a/tox.ini b/tox.ini index 53a8bd74..c03a324b 100644 --- a/tox.ini +++ b/tox.ini @@ -29,7 +29,10 @@ commands = {posargs} [testenv:docs] commands = sphinx-build -v -W -b html -d doc/build/doctrees doc/source doc/build/html -[testenv:ci-checks] +[testenv:ci-checks-review] +commands = ci-check-all-candidate-files {posargs:--HEAD} + +[testenv:ci-checks-election] commands = ci-check-all-candidate-files [flake8]