blob: 2a8b507b615b77ff2e87b2f647ad80dd1c4eee42 [file] [log] [blame]
Yigit Boyar7dcad2b2022-02-04 16:49:03 +00001#! /usr/bin/env python3
2import sys
3import getopt
4import json
5import os
6
7
8def usage(exitCode):
9 print("""
10 Usage:
11 ./should_run_project.py --project <project-name> --branch <current branch name>\n\
12 project-name: the name of the project from the workflow file\n\
13 branch: the target branch on the build\n\
14 Branches whose name starts with 'compose' use the compose configuration whereas\n\
15 everything else uses the main configuration\n\
16 See ci-config.json for the configuration.
17 """)
18 sys.exit(exitCode)
19
20# finds the configuration we should use based on the branch
21
22
23def getCurrentConfig(branch: str):
24 configFilePath = os.path.join(os.path.dirname(
25 os.path.realpath(__file__)), "ci-config.json")
26 configFile = open(configFilePath)
27 ciConfig = json.load(configFile)
28 configFile.close()
29 if "compose-compiler" in branch:
30 return ciConfig["compose"]
31 else:
32 return ciConfig["main"]
33
34
35def main(argv):
36 projectName = ''
37 branch = ''
38 try:
39 opts, args = getopt.getopt(argv, "h", ["project=", "branch="])
40 except getopt.GetoptError as err:
41 print(err)
42 usage(2)
43 for opt, arg in opts:
44 if opt == '-h':
45 usage(0)
46 elif opt in ("--project"):
47 projectName = arg
48 elif opt in ("--branch"):
49 branch = arg
50 else:
51 print("invalid argument ", opt, "-", arg)
52 usage(2)
53
54 currentConfig = getCurrentConfig(branch)
55 result = currentConfig["default"]
56 if "include" in currentConfig:
57 result = projectName in currentConfig["include"]
58 # run exclude after include to give it priority
59 if "exclude" in currentConfig:
60 result = not (projectName in currentConfig["exclude"])
61 print(str(result).lower())
62
63
64if __name__ == "__main__":
65 main(sys.argv[1:])