-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.py
57 lines (46 loc) · 1.78 KB
/
entrypoint.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
#!/usr/bin/python3
import os, json
from action_src import call_algo
if __name__ == "__main__":
api_key = os.getenv("INPUT_API_KEY")
metric = os.getenv("INPUT_METRIC")
threshold = os.getenv("INPUT_THRESHOLD")
checkpoints = os.getenv("INPUT_CHECKPOINTS")
repo_name = os.getenv("INPUT_PATH")
algo_hash = os.getenv("GITHUB_SHA")
github_token = os.getenv("GITHUB_TOKEN")
github_repo = os.getenv("GITHUB_REPOSITORY")
repo_path = "/github/workspace/{}".format(repo_name)
if not api_key:
raise Exception("field 'api_key' not defined in workflow")
if not repo_name:
raise Exception("field 'repo_name' not defined in workflow")
if not metric:
raise Exception("field 'metric' not defined in workflow")
if not threshold:
raise Exception("field 'threshold' not defined in workflow")
if not checkpoints:
raise Exception("field 'checkpoints' not defined in workflow")
model_eval_data = {
"metric": metric,
"threshold": threshold,
"checkpoints": checkpoints,
}
if os.path.exists(repo_path):
with open("{}/{}".format(repo_path, "algorithmia.conf")) as f:
config_data = json.load(f)
algo_name = "{}/{}".format(config_data["username"], config_data["algoname"])
algo_input_dict = {
"github_params": {
"github_token": github_token,
"github_repo": github_repo,
"commit_sha": algo_hash,
},
"eval_params": model_eval_data,
}
algo_input = json.dumps(algo_input_dict)
call_algo(api_key, algo_name, algo_hash, algo_input)
else:
raise Exception(
"actions/checkout on the local repo must be run before this action can be completed"
)