2019-06-06 19:11:59 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# 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/.
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
2019-07-02 21:27:36 +03:00
|
|
|
def set_hook(hook_path, version):
|
|
|
|
with open(hook_path, "r") as hook_file:
|
2019-06-06 19:11:59 +03:00
|
|
|
hook_data = json.load(hook_file)
|
|
|
|
|
2019-06-27 16:47:57 +03:00
|
|
|
task_payload = hook_data["task"]["payload"]
|
|
|
|
|
|
|
|
task_image = task_payload.get("image")
|
|
|
|
|
|
|
|
# 1) Insert or replace the environment variable
|
2019-07-02 21:27:36 +03:00
|
|
|
if task_payload["env"]:
|
2019-07-03 11:39:37 +03:00
|
|
|
if "$merge" not in task_payload["env"]:
|
|
|
|
task_payload["env"] = {"$merge": [task_payload["env"]]}
|
|
|
|
|
|
|
|
task_payload["env"]["$merge"].append({"TAG": version})
|
2019-07-02 21:27:36 +03:00
|
|
|
else:
|
|
|
|
task_payload["env"]["TAG"] = version
|
2019-06-27 16:47:57 +03:00
|
|
|
|
|
|
|
# 2) Set the version for the hook docker image
|
2019-07-02 21:35:01 +03:00
|
|
|
if task_image:
|
|
|
|
image_name = task_image.split(":", 1)[0]
|
|
|
|
if image_name.startswith("mozilla/bugbug-"):
|
|
|
|
task_payload["image"] = f"{image_name}:{version}"
|
2019-06-06 19:11:59 +03:00
|
|
|
|
2019-07-02 21:27:36 +03:00
|
|
|
with open(hook_path, "w") as hook_file:
|
2019-06-06 19:11:59 +03:00
|
|
|
json.dump(
|
|
|
|
hook_data, hook_file, sort_keys=True, indent=4, separators=(",", ": ")
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-07-02 21:27:36 +03:00
|
|
|
def parse_args(raw_args):
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
"version",
|
|
|
|
metavar="version",
|
|
|
|
type=str,
|
|
|
|
help="The version to set in the hook definition",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"hook_file",
|
|
|
|
metavar="hook-file",
|
|
|
|
type=str,
|
|
|
|
help="The hook definition file to update in-place",
|
|
|
|
)
|
|
|
|
|
|
|
|
return parser.parse_args(raw_args)
|
|
|
|
|
|
|
|
|
2019-06-06 19:11:59 +03:00
|
|
|
if __name__ == "__main__":
|
2019-07-02 21:27:36 +03:00
|
|
|
args = parse_args(sys.argv[1:])
|
|
|
|
set_hook(args.hook_file, args.version)
|