summaryrefslogtreecommitdiffstats
path: root/testing/mozharness/scripts/release/postrelease_version_bump.py
blob: dfffa699ad3dc760bcbb19544c8f8d9330a396dd (plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python
# lint_ignore=E501
# ***** BEGIN LICENSE BLOCK *****
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
# ***** END LICENSE BLOCK *****
""" postrelease_version_bump.py

A script to increase in-tree version number after shipping a release.
"""

import os
import sys

sys.path.insert(1, os.path.dirname(os.path.dirname(sys.path[0])))
from mozharness.base.vcs.vcsbase import MercurialScript
from mozharness.mozilla.buildbot import BuildbotMixin
from mozharness.mozilla.repo_manupulation import MercurialRepoManipulationMixin


# PostReleaseVersionBump {{{1
class PostReleaseVersionBump(MercurialScript, BuildbotMixin,
                             MercurialRepoManipulationMixin):
    config_options = [
        [['--hg-user', ], {
            "action": "store",
            "dest": "hg_user",
            "type": "string",
            "default": "ffxbld <release@mozilla.com>",
            "help": "Specify what user to use to commit to hg.",
        }],
        [['--next-version', ], {
            "action": "store",
            "dest": "next_version",
            "type": "string",
            "help": "Next version used in version bump",
        }],
        [['--ssh-user', ], {
            "action": "store",
            "dest": "ssh_user",
            "type": "string",
            "help": "SSH username with hg.mozilla.org permissions",
        }],
        [['--ssh-key', ], {
            "action": "store",
            "dest": "ssh_key",
            "type": "string",
            "help": "Path to SSH key.",
        }],
        [['--product', ], {
            "action": "store",
            "dest": "product",
            "type": "string",
            "help": "Product name",
        }],
        [['--version', ], {
            "action": "store",
            "dest": "version",
            "type": "string",
            "help": "Version",
        }],
        [['--build-number', ], {
            "action": "store",
            "dest": "build_number",
            "type": "string",
            "help": "Build number",
        }],
        [['--revision', ], {
            "action": "store",
            "dest": "revision",
            "type": "string",
            "help": "HG revision to tag",
        }],
    ]

    def __init__(self, require_config_file=True):
        super(PostReleaseVersionBump, self).__init__(
            config_options=self.config_options,
            all_actions=[
                'clobber',
                'clean-repos',
                'pull',
                'bump_postrelease',
                'commit-changes',
                'tag',
                'push',
            ],
            default_actions=[
                'clean-repos',
                'pull',
                'bump_postrelease',
                'commit-changes',
                'tag',
                'push',
            ],
            config={
                'buildbot_json_path': 'buildprops.json',
            },
            require_config_file=require_config_file
        )

    def _pre_config_lock(self, rw_config):
        super(PostReleaseVersionBump, self)._pre_config_lock(rw_config)
        # override properties from buildbot properties here as defined by
        # taskcluster properties
        self.read_buildbot_config()
        if not self.buildbot_config:
            self.warning("Skipping buildbot properties overrides")
        else:
            props = self.buildbot_config["properties"]
            for prop in ['next_version', 'product', 'version', 'build_number',
                         'revision']:
                if props.get(prop):
                    self.info("Overriding %s with %s" % (prop, props[prop]))
                    self.config[prop] = props.get(prop)

        if not self.config.get("next_version"):
            self.fatal("Next version has to be set. Use --next-version or "
                       "pass `next_version' via buildbot properties.")

    def query_abs_dirs(self):
        """ Allow for abs_from_dir and abs_to_dir
            """
        if self.abs_dirs:
            return self.abs_dirs
        self.abs_dirs = super(PostReleaseVersionBump, self).query_abs_dirs()
        self.abs_dirs["abs_gecko_dir"] = os.path.join(
                self.abs_dirs['abs_work_dir'], self.config["repo"]["dest"])
        return self.abs_dirs

    def query_repos(self):
        """Build a list of repos to clone."""
        return [self.config["repo"]]

    def query_commit_dirs(self):
        return [self.query_abs_dirs()["abs_gecko_dir"]]

    def query_commit_message(self):
        return "Automatic version bump. CLOSED TREE NO BUG a=release"

    def query_push_dirs(self):
        return self.query_commit_dirs()

    def query_push_args(self, cwd):
        # cwd is not used here
        hg_ssh_opts = "ssh -l {user} -i {key}".format(
            user=self.config["ssh_user"],
            key=os.path.expanduser(self.config["ssh_key"])
        )
        return ["-e", hg_ssh_opts, "-r", "."]

    def pull(self):
        super(PostReleaseVersionBump, self).pull(
                repos=self.query_repos())

    def bump_postrelease(self, *args, **kwargs):
        """Bump version"""
        dirs = self.query_abs_dirs()
        for f in self.config["version_files"]:
            curr_version = ".".join(
                self.get_version(dirs['abs_gecko_dir'], f["file"]))
            self.replace(os.path.join(dirs['abs_gecko_dir'], f["file"]),
                         curr_version, self.config["next_version"])

    def tag(self):
        dirs = self.query_abs_dirs()
        tags = ["{product}_{version}_BUILD{build_number}",
                "{product}_{version}_RELEASE"]
        tags = [t.format(product=self.config["product"].upper(),
                         version=self.config["version"].replace(".", "_"),
                         build_number=self.config["build_number"])
                for t in tags]
        message = "No bug - Tagging {revision} with {tags} a=release CLOSED TREE"
        message = message.format(
            revision=self.config["revision"],
            tags=', '.join(tags))
        self.hg_tag(cwd=dirs["abs_gecko_dir"], tags=tags,
                    revision=self.config["revision"], message=message,
                    user=self.config["hg_user"], force=True)

# __main__ {{{1
if __name__ == '__main__':
    PostReleaseVersionBump().run_and_exit()