forked from ocadotechnology/codeforlife-deploy-appengine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify_deployment.py
executable file
·49 lines (38 loc) · 1.33 KB
/
notify_deployment.py
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
#!/usr/bin/env python
import argparse
import logging
import os
from collections import defaultdict
import requests
logging.basicConfig()
MODULE_NAME = os.environ.get("MODULE_NAME")
PORTAL_BRANCH = os.environ.get("PORTAL_BRANCH")
RAPID_ROUTER_BRANCH = os.environ.get("RAPID_ROUTER_BRANCH")
success = True
parser = argparse.ArgumentParser()
parser.add_argument("success", nargs="?", default="true")
args = parser.parse_args()
if args.success.lower() in ["false", "0"]:
success = False
message = f"<https://github.com/ocadotechnology/codeforlife-deploy-appengine/deployments|Deployment to {MODULE_NAME}> "
if success:
versions = defaultdict(lambda: "error")
try:
versions = requests.get(
f"https://{MODULE_NAME}-dot-decent-digit-629.appspot.com/versions/"
).json()
except:
logging.exception("Error occurred while getting versions")
if PORTAL_BRANCH:
versions["codeforlife-portal"] = PORTAL_BRANCH
if RAPID_ROUTER_BRANCH:
versions["rapid-router"] = RAPID_ROUTER_BRANCH
message += (
f"completed successfully :tada:\n"
f"\n"
f"codeforlife-portal: `{versions['codeforlife-portal']}`\n"
f"rapid-router: `{versions['rapid-router']}`"
)
else:
message += "failed :boom:"
requests.post(os.environ["DEPLOY_NOTIFY_URL"], json={"text": message})