Skip to content

Commit 81e08dd

Browse files
committed
v0.5.0
- Fix uploading issues - Fix CodeQL version && install
1 parent 7052368 commit 81e08dd

File tree

3 files changed

+53
-28
lines changed

3 files changed

+53
-28
lines changed

bin/codeql-upload

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,49 @@
11
#!/bin/bash
22
set -e
3+
34
source $EXTENSION_LOCATION/bin/codeql-utils
45

5-
FILES=$(find $CODEQL_RESULTS -type f -name "*.sarif")
6+
CODEQL_DATABASE_PATHS=$(cat $CODEQL_DATABASE_PATHS_FILE)
7+
8+
9+
if [ ! -z $CODEQL_DATABASE_PATHS ]; then
10+
debug "Database paths found :: $CODEQL_DATABASE_PATHS"
11+
# for each database path, find sarif file
12+
FILES=""
13+
for CODEQL_DATABASE_PATH in $CODEQL_DATABASE_PATHS; do
14+
SARIF_FILE="$CODEQL_RESULTS/$(basename $CODEQL_DATABASE_PATH).sarif"
15+
debug "Possible SARIF file :: $SARIF_FILE"
16+
if [ -f $SARIF_FILE ]; then
17+
FILES="$FILES $SARIF_FILE"
18+
fi
19+
done
20+
else
21+
info "Uploading all SARIF files found in :: $CODEQL_RESULTS"
22+
FILES=$(find $CODEQL_RESULTS -type f -name "*.sarif")
23+
fi
24+
25+
info "GitHub Instance :: $GITHUB_INSTANCE"
626

727

828
# Upload results for each SARIF results file found
929
for SARIF_FILE in $FILES; do
10-
echo "SARIF File uploading :: $SARIF_FILE"
11-
debug "GitHub Instance :: $GITHUB_INSTANCE"
12-
debug "GitHub Repository :: $GITHUB_REPOSITORY"
13-
1430
if [ ! -f $SARIF_FILE ]; then
15-
echo "ERROR"
31+
error "SARIF file not found :: $SARIF_FILE"
1632
exit 1
1733
fi
1834

35+
info "SARIF File uploading :: $SARIF_FILE"
36+
37+
debug "GitHub Instance :: $GITHUB_INSTANCE"
38+
debug "GitHub Repository :: $GITHUB_REPOSITORY"
39+
1940
gh codeql github upload-results \
2041
--sarif=$SARIF_FILE \
2142
--github-url=$GITHUB_INSTANCE \
2243
--repository=$GITHUB_REPOSITORY \
2344
--ref=$GIT_REF \
2445
--commit=$GIT_HASH
25-
done
26-
27-
2846

47+
debug "Finished uploading SARIF file :: $SARIF_FILE"
2948

49+
done

bin/codeql-utils

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
set -e
44

5+
export QL_LANGUAGES="cpp,csharp,go,java,javascript,python,ruby"
6+
57
# https://unix.stackexchange.com/questions/9957/how-to-check-if-bash-can-print-colors
68
if test -t 1; then
79
ncolors=$(tput colors)
@@ -69,11 +71,11 @@ info() {
6971
}
7072
debug() {
7173
if [ ! -z ${DEBUG+x} ]; then
72-
echo "${blue}[#] DEBUG: $@${normal}"
74+
echo "${blue}[#] DEBUG: $@ ${normal}"
7375
fi
7476
}
7577
warning() {
76-
echo "${yellow}[!] WARNING: $@${normal}"
78+
echo "${yellow}[!] WARNING: $@ ${normal}"
7779
}
7880
error() {
7981
echo "${red}[*] ERROR: $@${normal}"
@@ -82,25 +84,23 @@ error() {
8284

8385
# CodeQL methods
8486

87+
codeql-version() {
88+
# return the version of CodeQL installed
89+
CODEQL_VERSION=$($CODEQL_BINARY version --format=terse 2>/dev/null)
90+
echo "$CODEQL_VERSION"
91+
}
92+
8593
codeql-install() {
8694
# https://github.com/GeekMasher/.dotfiles/blob/d08a1525c624e88b4d686cf70da349616d2b8aa4/codeql/.local/codeql-update
8795
info "Installing CodeQL via gh-cli..."
96+
8897
gh extensions install github/gh-codeql
8998
gh codeql set-version latest
9099

91100
# install new packs for each language
92-
LANGS="cpp,csharp,go,java,javascript,python,ruby"
93-
for lang in $(echo $LANGS | sed "s/,/ /g"); do
101+
for lang in $(echo $QL_LANGUAGES | sed "s/,/ /g"); do
94102
gh codeql pack download "codeql/$lang-queries"
95103
done
96-
info "CodeQL installed!"
97-
}
98-
99-
find-codeql() {
100-
# returns the command / location to run CodeQL from
101-
echo "TODO"
102-
}
103104

104-
get-languages() {
105-
echo "TODO"
105+
info "CodeQL installed!"
106106
}

gh-codeql-scan

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export EXTENSION_LOCATION="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
55
source $EXTENSION_LOCATION/bin/codeql-utils
66

77
# >> CodeQL Scan
8-
export CODEQL_SCAN_VERSION="0.4.2"
8+
export CODEQL_SCAN_VERSION="0.5.0"
99
# enabled by default
1010
export CODEQL_SCAN_BANNER=1
1111

@@ -116,19 +116,20 @@ done
116116

117117
display-banner
118118

119-
# Check if CodeQL is installed and have a version
120-
CODEQL_VERSION="$($CODEQL_BINARY version --format=terse || echo '')"
119+
debug "Checking CodeQL installation :: $CODEQL_BINARY"
120+
CODEQL_VERSION=$(codeql-version)
121+
debug "CodeQL Original version :: $CODEQL_VERSION"
121122

122123
if [ "$CODEQL_VERSION" = "" ]; then
123124
warning "CodeQL is not installed, now installing automatically..."
124125

125126
codeql-install
126-
127+
# re-export the gh cli codeql extension
127128
export CODEQL_BINARY="gh codeql"
128-
export CODEQL_VERSION=$($CODEQL_BINARY version --format=terse)
129+
export CODEQL_VERSION=$(codeql-version)
129130
fi
130131

131-
debug "Using CodeQL binary :: $CODEQL_BINARY"
132+
132133
info "Using CodeQL version :: $CODEQL_VERSION"
133134

134135
# Output dirs
@@ -168,6 +169,8 @@ elif [ $MODE = "upload" ]; then
168169

169170
$EXTENSION_LOCATION/bin/codeql-upload $@
170171

172+
info "Find Code Scanning results at: $GITHUB_INSTANCE/$GITHUB_REPOSITORY/security/code-scanning"
173+
171174
elif [ $MODE = "scan" ]; then
172175
info "Running Scan mode..."
173176

@@ -181,6 +184,8 @@ elif [ $MODE = "scan" ]; then
181184
if [ "$GITHUB_UPLOAD" = "1" ]; then
182185
info "Uploading results to GitHub..."
183186
$EXTENSION_LOCATION/bin/codeql-upload $@
187+
188+
info "Find Code Scanning results at: $GITHUB_INSTANCE/$GITHUB_REPOSITORY/security/code-scanning"
184189
else
185190
debug "Results are not uploaded to GitHub"
186191
fi

0 commit comments

Comments
 (0)