Add a script to update the hook definition with the TAG during release (#507)

Fixes #501, fixed relanding of #491.
This commit is contained in:
Boris Feld 2019-06-06 18:11:59 +02:00 коммит произвёл Marco
Родитель 08e36a7d8a
Коммит 32f56a3962
2 изменённых файлов: 64 добавлений и 10 удалений

Просмотреть файл

@ -257,12 +257,15 @@ tasks:
env:
GIT_REPOSITORY: ${repository}
GIT_REVISION: ${head_rev}
VERSION: {$eval: 'head_branch[10:]'}
command:
- taskboot
- build-hook
- infra/taskcluster-hook-pipeline-start.json
- project-relman
- bugbug
- "/bin/sh"
- "-lcxe"
- "git clone ${repository} &&
cd bugbug &&
git checkout ${head_rev} &&
python infra/set_hook_env_var.py TAG $VERSION infra/taskcluster-hook-pipeline-start.json &&
taskboot --target . build-hook infra/taskcluster-hook-pipeline-start.json project-relman bugbug"
routes:
- project.relman.bugbug.deploy_ending
metadata:
@ -292,12 +295,15 @@ tasks:
env:
GIT_REPOSITORY: ${repository}
GIT_REVISION: ${head_rev}
VERSION: {$eval: 'head_branch[10:]'}
command:
- taskboot
- build-hook
- infra/taskcluster-hook-check-models-start.json
- project-relman
- bugbug-checks
- "/bin/sh"
- "-lcxe"
- "git clone ${repository} &&
cd bugbug &&
git checkout ${head_rev} &&
python infra/set_hook_env_var.py TAG $VERSION infra/taskcluster-hook-check-models-start.json &&
taskboot --target . build-hook infra/taskcluster-hook-check-models-start.json project-relman bugbug-checks"
metadata:
name: bugbug update check hook
description: bugbug update check hook

48
infra/set_hook_env_var.py Normal file
Просмотреть файл

@ -0,0 +1,48 @@
# -*- 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
def main(raw_args):
parser = argparse.ArgumentParser()
parser.add_argument(
"env_name",
metavar="env-name",
type=str,
help="The name of the environment variable to set",
)
parser.add_argument(
"env_value",
metavar="env-value",
type=str,
help="The value of the environment variable to set",
)
parser.add_argument(
"hook_file",
metavar="hook-file",
type=str,
help="The hook definition file to update in-place",
)
args = parser.parse_args(raw_args)
with open(args.hook_file, "r") as hook_file:
hook_data = json.load(hook_file)
# Insert or replace the environment variable
hook_env = hook_data["task"]["payload"]["env"]
hook_env[args.env_name] = args.env_value
with open(args.hook_file, "w") as hook_file:
json.dump(
hook_data, hook_file, sort_keys=True, indent=4, separators=(",", ": ")
)
if __name__ == "__main__":
main(sys.argv[1:])