1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add safety check for Shippable "Rebuild with SSH" (#28857)

* Add safety check for Shippable "Rebuild with SSH".
* Run shippable.py for the `other` test.
This commit is contained in:
Matt Clay 2017-08-31 17:44:33 -07:00 committed by GitHub
parent 79dcb3a3fa
commit e513ec10da
2 changed files with 105 additions and 0 deletions

103
test/runner/shippable.py Executable file
View file

@ -0,0 +1,103 @@
#!/usr/bin/env python
# PYTHON_ARGCOMPLETE_OK
"""Verify the current Shippable run has the required number of jobs."""
from __future__ import absolute_import, print_function
# noinspection PyCompatibility
import argparse
import errno
import os
import sys
from lib.http import (
HttpClient,
)
from lib.util import (
display,
ApplicationError,
ApplicationWarning,
MissingEnvironmentVariable,
)
try:
import argcomplete
except ImportError:
argcomplete = None
def main():
"""Main program function."""
try:
args = parse_args()
display.verbosity = args.verbosity
display.color = args.color
try:
run_id = os.environ['SHIPPABLE_BUILD_ID']
except KeyError as ex:
raise MissingEnvironmentVariable(ex.args[0])
client = HttpClient(args)
response = client.get('https://api.shippable.com/jobs?runIds=%s' % run_id)
jobs = response.json()
if len(jobs) == 1:
raise ApplicationError('Shippable run %s has only one job. Did you use the "Rebuild with SSH" option?' % run_id)
except ApplicationWarning as ex:
display.warning(str(ex))
exit(0)
except ApplicationError as ex:
display.error(str(ex))
exit(1)
except KeyboardInterrupt:
exit(2)
except IOError as ex:
if ex.errno == errno.EPIPE:
exit(3)
raise
def parse_args():
"""Parse command line arguments."""
parser = argparse.ArgumentParser()
parser.add_argument('-e', '--explain',
action='store_true',
help='explain commands that would be executed')
parser.add_argument('-v', '--verbose',
dest='verbosity',
action='count',
default=0,
help='display more output')
parser.add_argument('--color',
metavar='COLOR',
nargs='?',
help='generate color output: %(choices)s',
choices=('yes', 'no', 'auto'),
const='yes',
default='auto')
if argcomplete:
argcomplete.autocomplete(parser)
args = parser.parse_args()
if args.color == 'yes':
args.color = True
elif args.color == 'no':
args.color = False
elif 'SHIPPABLE' in os.environ:
args.color = True
else:
args.color = sys.stdout.isatty()
return args
if __name__ == '__main__':
main()

View file

@ -2,6 +2,8 @@
set -o pipefail set -o pipefail
shippable.py
retry.py apt-get update -qq retry.py apt-get update -qq
retry.py apt-get install -qq \ retry.py apt-get install -qq \
shellcheck \ shellcheck \