-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.py
57 lines (44 loc) · 1.48 KB
/
action.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
import json
import os
from collections import OrderedDict
from os.path import isfile
from actions_toolkit import core
from easydict import EasyDict as edict
from action_context.providers.github import GithubProvider
from action_context.providers.project import ProjectProvider
from action_context.providers.python import PythonProvider
from action_context.providers.versioning import VersionProvider
def get_variables():
providers = [
ProjectProvider(),
VersionProvider(),
PythonProvider(),
GithubProvider(),
]
variables = edict(OrderedDict())
for provider in [p for p in providers if p.is_enabled()]:
variables.update(provider.dump(variables))
return variables
def main():
cache = core.get_input("cache")
export = core.get_input("export") == "true"
os.chdir(os.getcwd())
if cache and isfile(cache) and core.get_input("force") == "false":
core.info(f"Loading cache from: {cache}")
with open(cache) as f:
variables = json.load(f)
else:
core.info(f"Loading variables")
variables = get_variables()
if cache:
core.info(f"Dumping cache to: {cache}")
with open(cache, "w+") as f:
json.dump(variables, f)
for k, v in variables.items():
name = f"project_{k}"
core.set_output(name, v)
core.info(f"{name} -> {v}")
if export:
core.export_variable(name, v)
if __name__ == "__main__":
main()