-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcodeql.py
More file actions
54 lines (43 loc) · 2.02 KB
/
codeql.py
File metadata and controls
54 lines (43 loc) · 2.02 KB
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
import os
from ghastoolkit import CodeQLPacks, CodeQLPack, GitHub
from ghastoolkit.utils.cli import CommandLine
class IaCCommandLine(CommandLine):
def arguments(self):
self.addModes(["publish", "version", "queries"])
parser = self.parser.add_argument_group("packs")
parser.add_argument("--cwd", default=os.getcwd(), help="The current working directory")
parser.add_argument("--bump", default="patch", choices=["major", "minor", "patch"], help="The version bump to apply to the pack (major, minor, patch)")
def run(self):
arguments = self.parse_args()
print("===== Running IaC CodeQL Pack CLI =====")
pack_lib = CodeQLPack(os.path.join(arguments.cwd, "ql", "lib", "qlpack.yml"))
pack_src = CodeQLPack(os.path.join(arguments.cwd, "ql", "src", "qlpack.yml"))
packs = CodeQLPacks()
packs.append(pack_lib)
packs.append(pack_src)
if arguments.mode == "publish":
self.runPublish(arguments, packs)
elif arguments.mode == "queries":
queries = pack_src.resolveQueries()
print(f"CodeQL Queries :: {len(queries)}")
for query in queries:
print(f"{query}")
elif arguments.mode == "version":
self.runBump(arguments, packs)
def runPublish(self, args, packs):
for pack in packs:
print(f"CodeQL Pack :: {pack} ({pack.path})")
if pack.remote_version != pack.version:
print(f"Publishing {pack} ({pack.remote_version} -> {pack.version})")
pack.publish()
else:
print(f"Skipping publish as remote pack is up to date ({pack.remote_version})")
def runBump(self, args, packs):
for pack in packs:
old_version = pack.version
print(f"CodeQL Pack :: {pack} ({pack.path})")
pack.updateVersion(args.bump)
print(f"Bumping {pack} ({old_version} -> {pack.version})")
pack.updatePack()
cli = IaCCommandLine()
cli.run()