summaryrefslogtreecommitdiffstats
path: root/utils/agl-publish.py
blob: 3bbf8e6be65d4596a7dff8df630bb88be3a950e2 (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

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highl
#!/usr/bin/env python3

import argparse
import requests
from urllib.parse import urljoin
import os
import json
import urllib

parser = argparse.ArgumentParser(description="AGL create bmeta", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--arch', action='store', help="arch of the build", required=
, action='store', help="commit of the build", required=True) parser.add_argument('--build_version', action='store', help="build_version of the build", required=True) parser.add_argument('--kernel_version', action='store', help="kernel_version of the build", default=None) parser.add_argument('--machine', action='store', help="machine of the build", required=True) parser.add_argument('--api', action='store', help="URL to kernelci backend API", required=True) args = parser.parse_args() KCI_PUSH_TOKEN = "AGL_KCIAPI_TOKEN" KCI_UPLOAD_TOKEN = "AGL_KCIAPI_TOKEN" if args.api == 'http://kernelci.dev.baylibre.com:8081/': KCI_PUSH_TOKEN = "BAY_KCIAPI_TOKEN" KCI_UPLOAD_TOKEN = "BAY_KCIAPI_TOKEN" if not KCI_PUSH_TOKEN in os.environ: print("Missing env variable %s" % KCI_PUSH_TOKEN) ptoken=None else: ptoken=os.environ[KCI_PUSH_TOKEN] if not KCI_UPLOAD_TOKEN in os.environ: print("Missing env variable %s" % KCI_UPLOAD_TOKEN) utoken=None else: utoken=os.environ[KCI_UPLOAD_TOKEN] bmeta = {} bmeta["arch"] = args.arch bmeta["build_log"] = "build.log" bmeta["build_environment"] = "AGL-yocto" bmeta["defconfig"] = "defconfig" bmeta["defconfig_full"] = "defconfig+CONFIG_AGL=y" bmeta["git_branch"] = args.branch bmeta["git_commit"] = args.commit if args.kernel_version: bmeta["git_describe"] = args.kernel_version else: bmeta["git_describe"] = args.branch bmeta["job"] = "AGL-yocto" fsr = "AGL-yocto/%s/%s/%s/" % (args.branch, args.build_version, args.machine) bmeta["file_server_resource"] = fsr print(bmeta) DIR_META="agl-build-meta" # create directory with artifacts to be uploaded (bmeta.json) if not os.path.exists(DIR_META): os.mkdir(DIR_META) # write bmeta in it with open(os.path.join(DIR_META, 'bmeta.json'), 'w') as json_file: json.dump(bmeta, json_file, indent=4, sort_keys=True) def upload(): path = bmeta["file_server_resource"] data = { 'path': path, } artifacts = {} for root, _, files in os.walk(DIR_META): for f in files: px = os.path.relpath(root, DIR_META) artifacts[os.path.join(px, f)] = open(os.path.join(root, f), "rb") files = { 'file{}'.format(i): (name, fobj) for i, (name, fobj) in enumerate(artifacts.items()) } url = urljoin(args.api, 'upload') print("DATA====================") print(data) if utoken is None: print("No upload token, skipping upload") return 0 headers = { 'Authorization': utoken, } resp = requests.post(url, headers=headers, data=data, files=files) resp.raise_for_status() print(resp.reason) print(resp.text) def publish_kernel(): data = {k: bmeta[v] for k, v in { 'file_server_resource': 'file_server_resource', 'job': 'job', 'git_branch': 'git_branch', 'arch': 'arch', 'kernel': 'git_describe', 'build_environment': 'build_environment', 'defconfig': 'defconfig', 'defconfig_full': 'defconfig_full', }.items()} print("DATA====================") print(data) if ptoken is None: print("No publish token, skipping publish") return 0 headers = { 'Authorization': ptoken, 'Content-Type': 'application/json', } url = urllib.parse.urljoin(args.api, '/build') data_json = json.dumps(data) resp = requests.post(url, headers=headers, data=data_json) resp.raise_for_status() print(resp.reason) print(resp.text) print("============== UPLOAD") upload() print("============== PUBLISH") publish_kernel()