|
2 | 2 |
|
3 | 3 | import os |
4 | 4 | import sys |
5 | | -from logging import Logger, getLogger, INFO |
| 5 | +import argparse |
6 | 6 | from sys import path as syspath |
7 | 7 | from libs.utils import * |
8 | 8 | from libs.github import * |
9 | 9 | from libs.codeql import * |
10 | 10 |
|
11 | | - # get the parent directory of the script, to link libs |
12 | | -sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) |
| 11 | +CODEQL_HOME = get_env_variable('CODEQL_HOME') |
13 | 12 |
|
14 | | -CODEQL_HOME = environ['CODEQL_HOME'] |
| 13 | +# should we update the local copy of codeql-cli if a new version is available? |
| 14 | +CHECK_LATEST_CODEQL_CLI = get_env_variable('CHECK_LATEST_CODEQL_CLI', True) |
15 | 15 |
|
16 | | -logger = getLogger('codeql-container') |
| 16 | +# should we update the local copy of codeql queries if a new version is available? |
| 17 | +CHECK_LATEST_QUERIES = get_env_variable('CHECK_LATEST_QUERIES', True) |
| 18 | + |
| 19 | +# if we are downloading new queries, should we precompile them |
| 20 | +PRECOMPILE_QUERIES = get_env_variable('PRECOMPILE_QUERIES', True) |
| 21 | + |
| 22 | + |
| 23 | +logger = getLogger('codeql-container-setup') |
17 | 24 | logger.setLevel(INFO) |
18 | 25 |
|
| 26 | +def parse_arguments(): |
| 27 | + |
| 28 | + parser = argparse.ArgumentParser(description='Setup codeql components.') |
| 29 | + parser.add_argument("-c", "--check-latest-cli", help="check the latest codeql-cli package available and install it", |
| 30 | + default=False, action="store_true") |
| 31 | + parser.add_argument("-q", "--check-latest-queries", help="check the latest codeql queries available and install it", |
| 32 | + default=False, action="store_true") |
| 33 | + #(makes query execution faster, but building the container build slower). |
| 34 | + parser.add_argument("-p", "--precompile-latest-queries", help="if new queries were downloaded, precompile it", |
| 35 | + default=False, action="store_true") |
| 36 | + args = parser.parse_args() |
| 37 | + |
| 38 | + return args |
| 39 | + |
19 | 40 | def setup(): |
20 | 41 | """ |
21 | 42 | Download and install the latest codeql cli |
22 | 43 | Download and install the latest codeql queries |
23 | 44 | """ |
24 | | - |
| 45 | + args = parse_arguments() |
25 | 46 | # check version and download the latest version |
26 | | - get_latest_codeql() |
27 | | - # install vscode? |
28 | | - # clone codeql libs |
29 | | - # setup vscode + codeql |
30 | | - # wait for user |
31 | | - |
| 47 | + get_latest_codeql(args) |
32 | 48 |
|
33 | | -def get_latest_codeql(): |
| 49 | +def get_latest_codeql(args): |
34 | 50 | # what version do we have? |
35 | 51 | codeql = CodeQL(CODEQL_HOME) |
36 | 52 | current_installed_version = codeql.get_current_local_version() |
37 | 53 | logger.info(f'Current codeql version: {current_installed_version}') |
38 | 54 | latest_online_version = codeql.get_latest_codeql_github_version() |
39 | | - if current_installed_version != latest_online_version.title: |
| 55 | + if current_installed_version != latest_online_version.title and args.check_latest_cli: |
40 | 56 | # we got a newer version online, download and install it |
41 | 57 | codeql.download_and_install_latest_codeql(latest_online_version) |
42 | 58 | # get the latest queries regardless (TODO: Optimize by storing and checking the last commit hash?) |
43 | | - codeql.download_and_install_latest_codeql_queries() |
| 59 | + if args.check_latest_queries: |
| 60 | + codeql.download_and_install_latest_codeql_queries() |
| 61 | + if args.precompile_latest_queries: |
| 62 | + codeql.precompile_queries() |
44 | 63 |
|
| 64 | +logger = get_logger() |
45 | 65 | setup() |
46 | 66 |
|
0 commit comments