aboutsummaryrefslogtreecommitdiffstats
path: root/utils/agl-publish.py
blob: a6b540bc3c4ac29fc5ba07b1472196ef3c42f281 (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
#!/usr/bin/env python3

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

ptoken=os.environ["KCI_PUSH_TOKEN"]
utoken=os.environ["KCI_UPLOAD_TOKEN"]

parser = argparse.ArgumentParser(description="AGL create bmeta", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--arch', action='store', help="arch of the build", required=True)
parser.add_argument('--branch', action='store', help="branch of the build", required=True)
parser.add_argument('--commit', 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('--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()

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
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"]

    headers = {
        'Authorization': utoken,
    }
    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)
    return 0
    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)
    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()