示例#1
0
def tag_exists(repo, ref):
    """Return boolean specifying whether the reference exists in the repository.

    Uses a cgit query instead of looking locally to avoid cloning a
    repository or having Depends-On settings in a commit message allow
    someone to fool the check.
    """
    url = GIT_TAG_TEMPLATE % (repo, ref)
    return links.link_exists(url)
示例#2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--series', '-s',
        help='release series to scan',
    )
    parser.add_argument(
        '--artifacts',
        default=False,
        action='store_true',
        help='only scan the build artifacts',
    )
    parser.add_argument(
        '--all',
        default=False,
        action='store_true',
        help='scan all releases, not just most recent',
    )
    parser.add_argument(
        'input',
        nargs='*',
        help=('YAML files to validate, defaults to '
              'files changed in the latest commit'),
    )
    args = parser.parse_args()

    if args.input:
        filenames = args.input
    elif args.series:
        filenames = sorted(glob.glob('deliverables/%s/*.yaml' % args.series))
    else:
        filenames = sorted(gitutils.find_modified_deliverable_files())
    if not filenames:
        print('no modified deliverable files, validating all releases from %s'
              % defaults.RELEASE)
        filenames = glob.glob('deliverables/' + defaults.RELEASE + '/*.yaml')

    errors = []

    for filename in filenames:
        print('\nChecking %s' % filename)
        if not os.path.exists(filename):
            print("File was deleted, skipping.")
            continue
        with open(filename, 'r') as f:
            deliverable_info = yaml.load(f.read())

        link_mode = deliverable_info.get('artifact-link-mode', 'tarball')

        releases = deliverable_info.get('releases', [])
        if not args.all:
            releases = releases[-1:]

        for release in releases:

            for project in release['projects']:
                # Report if the version has already been
                # tagged. We expect it to not exist, but neither
                # case is an error because sometimes we want to
                # import history and sometimes we want to make new
                # releases.
                print('%s %s' % (project['repo'], release['version']), end=' ')

                if not args.artifacts:
                    version_exists = gitutils.tag_exists(
                        project['repo'], release['version'],
                    )
                    if version_exists:
                        print('tag:found', end=' ')
                    else:
                        print('tag:MISSING', end=' ')
                        errors.append('%s missing tag %s' %
                                      (project['repo'], release['version']))

                # Look for the tarball associated with the tag and
                # report if that exists.
                if link_mode == 'tarball':
                    tb_url = links.tarball_url(release['version'], project)
                    if links.link_exists(tb_url):
                        print('tarball:found', end=' ')
                    else:
                        print('tarball:MISSING\n%s' % tb_url)
                        errors.append('%s missing tarball %s' %
                                      (filename, tb_url))
                    sig_url = links.signature_url(release['version'], project)
                    if links.link_exists(sig_url):
                        print('signature:found', end=' ')
                    else:
                        print('signature:MISSING\n%s' % sig_url)
                        errors.append('%s missing signature %s' %
                                      (filename, sig_url))
                print()

    if errors:
        print('\n\n%s errors found' % len(errors))
        for e in errors:
            print(e)

    return 1 if errors else 0
示例#3
0
def check_url(type, url):
    if links.link_exists(url):
        print('  found {}'.format(type))
    else:
        print('  did not find {} {}'.format(type, url))
        yield 'missing {} {}'.format(type, url)