-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.py
executable file
·64 lines (52 loc) · 2.08 KB
/
upload.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
"upload.py -- maps action params to viam update + upload commands"
import argparse, subprocess, logging, platform
# map platform.uname.machine -> GOARCH
ARCH_LOOKUP = {
'x86_64': 'amd64',
'aarch64': 'arm64',
}
def main():
p = argparse.ArgumentParser(description='see action.yml for argument explanations')
g1 = p.add_mutually_exclusive_group(required=True)
g1.add_argument('--meta-path')
g1.add_argument('--name')
# todo: these are no longer required
g2 = p.add_mutually_exclusive_group()
g2.add_argument('--org-id')
g2.add_argument('--namespace')
p.add_argument('--module-path')
p.add_argument('--key-id', required=True)
p.add_argument('--key-value', required=True)
p.add_argument('--platform')
p.add_argument('--tags')
p.add_argument('--version')
p.add_argument('--do-update', action='store_true')
p.add_argument('--do-upload', action='store_true')
args, _ = p.parse_known_args()
logging.basicConfig(level=logging.INFO)
meta_args = ()
if args.meta_path:
meta_args = ('--module', args.meta_path)
elif args.name:
meta_args = ('--name', args.name)
org_args = ()
if args.org_id:
org_args = ('--org-id', args.org_id)
elif args.namespace:
org_args = ('--public-namespace', args.namespace)
tags = ()
if args.tags:
tags = ('--tags', args.tags)
command = f"viam-{ARCH_LOOKUP[platform.uname().machine]}"
logging.info('selected command %s based on arch %s', command, platform.uname().machine)
subprocess.check_call([command, 'version'])
subprocess.check_call([command, 'auth', 'api-key', '--key-id', args.key_id, '--key', args.key_value])
if args.do_update:
subprocess.check_call([command, 'module', 'update', *meta_args])
logging.info('ran update')
if args.do_upload:
subprocess.check_call([command, 'module', 'upload', *meta_args, *org_args, '--platform', args.platform, *tags, '--version', args.version, args.module_path])
logging.info('ran upload')
if __name__ == '__main__':
main()