-
Notifications
You must be signed in to change notification settings - Fork 20
/
do-release-tags
executable file
·96 lines (88 loc) · 3.75 KB
/
do-release-tags
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
#
# Ensure that the specified refs match a releases.yml file
# that is stored in git.
#
# Copyright 2016 Colin Walters <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
import gi
gi.require_version('OSTree', '1.0')
from gi.repository import GLib, Gio, OSTree
import argparse
import yaml
import sys
def fatal(msg):
print >>sys.stderr, msg
sys.exit(1)
parser = argparse.ArgumentParser(prog=sys.argv[0])
parser.add_argument("--autocreate", help="Create refs that don't already exist",
action='store_true')
parser.add_argument("--ignore-no-previous-promotion", help="Releases file",
action='store_true')
parser.add_argument("--repo", help="Repo path",
action='store', required=True)
parser.add_argument("--releases", help="Releases file",
action='store', required=True)
args = parser.parse_args()
r = OSTree.Repo.new(Gio.File.new_for_path(args.repo))
r.open(None)
releasedata = yaml.load(open(args.releases))
baseref = releasedata['baseref']
changed = False
for (name,newcommit) in releasedata['releases'].iteritems():
ref = baseref + name
[_, current] = r.resolve_rev(ref, True)
if current is None:
if args.autocreate:
print("Creating new ref {}.".format(ref))
newparent = None
else:
fatal("error: Ref {} does not currently exist".format(ref))
else:
_,currentcommitdata,_ = r.load_commit(current)
currentcommitmeta = currentcommitdata.get_child_value(0)
currentpromotedv = currentcommitmeta.lookup_value("promotion-of", GLib.VariantType.new("s"))
if currentpromotedv is None:
msg = "Missing promotion-of metadata key in {}".format(current)
if args.ignore_no_previous_promotion:
print("warning: " + msg)
currentpromoted = '(missing)'
newparent = None
else:
fatal(msg)
else:
currentpromoted = currentpromotedv.get_string()
newparent = current
if currentpromoted == newcommit:
print("No changes in {} = {}, promoted from {}".format(ref, current, currentpromoted))
continue
print("Previously: {} = {}, promoted from {}".format(ref, current, currentpromoted))
_,newcommitdata,_ = r.load_commit(newcommit)
_,newcommitroot,_ = r.read_commit(newcommit, None)
newcommitmeta = newcommitdata.get_child_value(0)
versionv = newcommitmeta.lookup_value("version", GLib.VariantType.new("s"))
if versionv:
version = versionv.get_string()
promotedmetadict = GLib.VariantDict.new(newcommitmeta)
promotedmetadict.insert_value("promotion-of", GLib.Variant.new_string(newcommit))
body = 'PromotionOf: {}'.format(newcommit)
mtree = OSTree.MutableTree.new()
_,promotedcommit = r.write_commit(newparent, '', body, promotedmetadict.end(), newcommitroot, None)
r.set_ref_immediate(None, ref, promotedcommit)
if version:
print "Promoted commit {} (version {}) => {}".format(newcommit, version, promotedcommit)
changed = True
if not changed:
print("Processed {}: No changes".format(args.releases))