~nskaggs/juju-ci-tools/keystone3

« back to all changes in this revision

Viewing changes to make-buildvars

  • Committer: Aaron Bentley
  • Date: 2016-02-18 20:53:26 UTC
  • mto: This revision was merged to the branch mainline in revision 1284.
  • Revision ID: aaron.bentley@canonical.com-20160218205326-or6zfhqps5tl5saa
make-buildvars writes revision even if no version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        commit, ref = ls_remote(repo_url, revision_spec, tag=True)
60
60
    if commit is None:
61
61
        commit = revision_spec
 
62
    return None, commit
 
63
 
 
64
 
 
65
def get_git_version(branch, commit):
 
66
    protocol, branch_name, repo_name = branch.split(':')
62
67
    domain, user, repo = repo_name.split('/')
63
68
    template = 'https://raw.githubusercontent.com/{}/{}/{}/version/version.go'
64
69
    file_url = template.format(user, repo, commit)
65
70
    response = urllib2.urlopen(file_url)
66
 
    version = parse_version(response.read())
67
 
    return None, commit, version
 
71
    return parse_version(response.read())
68
72
 
69
73
 
70
74
if __name__ == '__main__':
80
84
    if branch.startswith('lp:'):
81
85
        logging.error('Launchpad branches are no longer supported.')
82
86
        sys.exit(1)
83
 
    else:
84
 
        revno, revision_id, version = get_git_revision_info(
85
 
            branch, revision_spec)
86
 
    with open('buildvars.bash', 'w') as f:
87
 
        f.write(dedent("""\
88
 
            export BRANCH=%s
89
 
            export REVISION_ID='%s'
90
 
            export VERSION=%s
91
 
        """ % (branch, revision_id, version)))
92
 
        if revno is not None:
93
 
            f.write('export REVNO=%s\n' % revno)
94
 
    with open('buildvars.json', 'w') as f:
95
 
        json.dump({
96
 
            'branch': branch,
97
 
            'revision_id': revision_id,
98
 
            'version': version,
99
 
            'revision_build': args.revision_build,
100
 
            }, f, indent=2)
 
87
    revno, revision_id = get_git_revision_info(branch, revision_spec)
 
88
    version = None
 
89
    version_str = ''
 
90
    try:
 
91
        version = get_git_version(branch, revision_id)
 
92
        version_str = str(version)
 
93
    finally:
 
94
        with open('buildvars.bash', 'w') as f:
 
95
            f.write(dedent("""\
 
96
                export BRANCH=%s
 
97
                export REVISION_ID='%s'
 
98
                export VERSION=%s
 
99
            """ % (branch, revision_id, version_str)))
 
100
            if revno is not None:
 
101
                f.write('export REVNO=%s\n' % revno)
 
102
        with open('buildvars.json', 'w') as f:
 
103
            json.dump({
 
104
                'branch': branch,
 
105
                'revision_id': revision_id,
 
106
                'version': version,
 
107
                'revision_build': args.revision_build,
 
108
                }, f, indent=2)
 
109