59
59
commit, ref = ls_remote(repo_url, revision_spec, tag=True)
61
61
commit = revision_spec
65
def get_git_version(branch, commit):
66
protocol, branch_name, repo_name = branch.split(':')
67
62
domain, user, repo = repo_name.split('/')
68
63
template = 'https://raw.githubusercontent.com/{}/{}/{}/version/version.go'
69
64
file_url = template.format(user, repo, commit)
70
65
response = urllib2.urlopen(file_url)
71
return parse_version(response.read())
74
if __name__ == '__main__':
75
parser = ArgumentParser()
76
parser.add_argument('branch', help='The branch being built')
77
parser.add_argument('revision', nargs='?', default=None,
78
help='The revision being built')
79
parser.add_argument('--revision-build', default=None,
80
help='The build number.')
81
args = parser.parse_args()
83
revision_spec = args.revision
84
if branch.startswith('lp:'):
85
logging.error('Launchpad branches are no longer supported.')
87
revno, revision_id = get_git_revision_info(branch, revision_spec)
66
version = parse_version(response.read())
67
return None, commit, version
70
def get_bzr_revision_info(branch, revision_spec):
71
"""Find the revision_id, revno and juju-core version of a branch.
73
:param branch: The location of the branch.
74
:param revision_spec: a human-readable revision spec like '-1', 'revno:5'
76
:return: a tuple of revno, revision-id, version
78
candidate = Branch.open(branch)
91
version = get_git_version(branch, revision_id)
92
version_str = str(version)
81
info = RevisionSpec.from_string(revision_spec).in_history(candidate)
82
tree = candidate.repository.revision_tree(info.rev_id)
85
file_id = tree.path2id('version/version.go')
86
v_bytes = tree.get_file_text(file_id, path='version/version.go')
89
version = parse_version(v_bytes)
90
return info.revno, info.rev_id, version
94
with open('buildvars.bash', 'w') as f:
97
export REVISION_ID='%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:
105
'revision_id': revision_id,
107
'revision_build': args.revision_build,
95
if __name__ == '__main__':
98
if sys.argv[1].startswith('lp:'):
99
revision_spec = sys.argv[2] if len(sys.argv) > 2 else 'revno:-1'
100
revno, revision_id, version = get_bzr_revision_info(
101
branch, revision_spec)
103
revision_spec = sys.argv[2] if len(sys.argv) > 2 else None
104
revno, revision_id, version = get_git_revision_info(
105
branch, revision_spec)
106
with open('buildvars.bash', 'w') as f:
109
export REVISION_ID='%s'
111
""" % (branch, revision_id, version)))
112
if revno is not None:
113
f.write('export REVNO=%s\n' % revno)