-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathsetup.py
60 lines (51 loc) · 2.39 KB
/
setup.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
#!/usr/bin/env python3
import os
import sys
import argparse
from sys import path as syspath
from libs.utils import *
from libs.github import *
from libs.codeql import *
CODEQL_HOME = get_env_variable('CODEQL_HOME')
logger = getLogger('codeql-container-setup')
logger.setLevel(INFO)
def parse_arguments():
parser = argparse.ArgumentParser(description='Setup codeql components.')
# should we update the local copy of codeql-cli if a new version is available?
parser.add_argument("-c", "--check-latest-cli", help="check the latest codeql-cli package available and install it",
default=False, action="store_true")
# should we update the local copy of codeql queries if a new version is available?
parser.add_argument("-q", "--check-latest-queries", help="check the latest codeql queries available and install it",
default=False, action="store_true")
#(makes query execution faster, but building the container build slower).
parser.add_argument("-p", "--precompile-latest-queries", help="if new queries were downloaded, precompile it",
default=False, action="store_true")
args = parser.parse_args()
return args
def setup():
"""
Download and install the latest codeql cli
Download and install the latest codeql queries
"""
logger.info("Starting setup...")
args = parse_arguments()
# check version and download the latest version
get_latest_codeql(args)
logger.info("End setup...")
def get_latest_codeql(args):
codeql = CodeQL(CODEQL_HOME)
current_installed_version = codeql.get_current_local_version()
logger.info(f'Current codeql version: {current_installed_version}')
# ensure we only query for the latest codeql cli version if we might actually update it
if args.check_latest_cli:
latest_online_version = codeql.get_latest_codeql_github_version()
if current_installed_version != latest_online_version.tag_name:
# we got a newer version online, download and install it
codeql.download_and_install_latest_codeql(latest_online_version)
# get the latest queries regardless (TODO: Optimize by storing and checking the last commit hash?)
if args.check_latest_queries:
codeql.download_and_install_latest_codeql_queries()
if args.precompile_latest_queries:
codeql.precompile_queries()
logger = get_logger()
setup()