Skip to content

Commit 1d2b799

Browse files
committed
ci(codeql): Add CodeQL analysis
1 parent 6015fd7 commit 1d2b799

File tree

11 files changed

+450
-252
lines changed

11 files changed

+450
-252
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# CI
1313
/.github/ @lucasssvaz @me-no-dev @P-R-O-C-H-Y
14+
/.github/codeql/ @lucasssvaz
1415
/.gitlab/ @lucasssvaz
1516
/tests/ @lucasssvaz @P-R-O-C-H-Y
1617

.github/codeql/codeql-config.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "CodeQL config"
2+
3+
packs:
4+
- trailofbits/cpp-queries
5+
- githubsecuritylab/codeql-cpp-queries
6+
- githubsecuritylab/codeql-python-queries
7+
8+
queries:
9+
- uses: security-extended
10+
- uses: security-and-quality
11+
12+
query-filters:
13+
- exclude:
14+
query path:
15+
- /^experimental\/.*/
16+
- exclude:
17+
tags contain:
18+
- experimental
19+
- exclude:
20+
problem.severity:
21+
- recommendation
22+
- exclude:
23+
id: tob/cpp/use-of-legacy-algorithm

.github/scripts/find_all_boards.sh

Lines changed: 0 additions & 39 deletions
This file was deleted.

.github/scripts/find_boards.sh

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/bin/bash
2+
3+
# Unified script to find boards for testing
4+
# Usage:
5+
# ./find_boards.sh all # Find all boards
6+
# ./find_boards.sh new <owner> <base_ref> # Find only new/modified boards
7+
8+
# Function to create JSON matrix and set environment variables
9+
create_json_matrix_and_set_env() {
10+
local message_type=$1 # "Boards" or "New boards"
11+
shift # Remove the first argument (message_type) from the array
12+
local boards_array=("$@")
13+
14+
# Sort the boards array alphabetically
15+
mapfile -t sorted_boards < <(printf '%s\n' "${boards_array[@]}" | sort)
16+
17+
local board_count=${#sorted_boards[@]}
18+
19+
echo "${message_type} found: $board_count"
20+
echo "BOARD-COUNT=$board_count" >> "$GITHUB_ENV"
21+
22+
if [ "$board_count" -gt 0 ]; then
23+
json_matrix='['
24+
local temp_count=$board_count
25+
for board in "${sorted_boards[@]}"; do
26+
json_matrix+='"'$board'"'
27+
if [ "$temp_count" -gt 1 ]; then
28+
json_matrix+=","
29+
fi
30+
temp_count=$((temp_count - 1))
31+
done
32+
json_matrix+=']'
33+
34+
echo "$json_matrix"
35+
echo "FQBNS=${json_matrix}" >> "$GITHUB_ENV"
36+
else
37+
echo "FQBNS=" >> "$GITHUB_ENV"
38+
fi
39+
}
40+
41+
# Function to process board name and add to array
42+
process_board() {
43+
local board_name=$1
44+
local boards_array_ref=$2
45+
46+
# skip esp32c2 as we dont build libs for it
47+
if [ "$board_name" == "esp32c2" ]; then
48+
echo "Skipping 'espressif:esp32:$board_name'"
49+
return
50+
fi
51+
52+
eval "$boards_array_ref+=(\"espressif:esp32:$board_name\")"
53+
echo "Added 'espressif:esp32:$board_name' to array"
54+
}
55+
56+
# Function to get all boards
57+
get_all_boards() {
58+
local boards_array=()
59+
local boards_list
60+
boards_list=$(grep '.tarch=' boards.txt)
61+
62+
while read -r line; do
63+
local board_name
64+
board_name=$(echo "$line" | cut -d '.' -f1 | cut -d '#' -f1)
65+
process_board "$board_name" "boards_array"
66+
done <<< "$boards_list"
67+
68+
create_json_matrix_and_set_env "Boards" "${boards_array[@]}"
69+
}
70+
71+
# Function to get new/modified boards
72+
get_new_boards() {
73+
local owner_repository=$1
74+
local base_ref=$2
75+
76+
if [ -z "$owner_repository" ] || [ -z "$base_ref" ]; then
77+
echo "Error: For 'new' mode, owner_repository and base_ref are required"
78+
echo "Usage: ./find_boards.sh new <owner_repository> <base_ref>"
79+
exit 1
80+
fi
81+
82+
# Download the boards.txt file from the base branch
83+
curl -L -o boards_base.txt https://raw.githubusercontent.com/"$owner_repository"/"$base_ref"/boards.txt
84+
85+
# Compare boards.txt file in the repo with the modified file from PR
86+
local diff
87+
diff=$(diff -u boards_base.txt boards.txt)
88+
89+
# Check if the diff is empty
90+
if [ -z "$diff" ]; then
91+
echo "No changes in boards.txt file"
92+
echo "FQBNS="
93+
exit 0
94+
fi
95+
96+
# Extract added or modified lines (lines starting with '+' or '-')
97+
local modified_lines
98+
modified_lines=$(echo "$diff" | grep -E '^[+-][^+-]')
99+
100+
# Print the modified lines for debugging
101+
echo "Modified lines:"
102+
echo "$modified_lines"
103+
104+
local boards_array=()
105+
local previous_board=""
106+
107+
# Extract board names from the modified lines, and add them to the boards_array
108+
while read -r line; do
109+
local board_name
110+
board_name=$(echo "$line" | cut -d '.' -f1 | cut -d '#' -f1)
111+
# remove + or - from the board name at the beginning
112+
board_name=${board_name#[-+]}
113+
if [ "$board_name" != "" ] && [ "$board_name" != "+" ] && [ "$board_name" != "-" ] && [ "$board_name" != "esp32_family" ]; then
114+
if [ "$board_name" != "$previous_board" ]; then
115+
process_board "$board_name" "boards_array"
116+
previous_board="$board_name"
117+
fi
118+
fi
119+
done <<< "$modified_lines"
120+
121+
create_json_matrix_and_set_env "New boards" "${boards_array[@]}"
122+
}
123+
124+
# Main script logic
125+
mode=$1
126+
127+
if [ "$mode" = "all" ]; then
128+
get_all_boards
129+
elif [ "$mode" = "new" ]; then
130+
get_new_boards "$2" "$3"
131+
else
132+
echo "Error: Invalid mode. Use 'all' or 'new'"
133+
echo "Usage:"
134+
echo " ./find_boards.sh all"
135+
echo " ./find_boards.sh new <owner_repository> <base_ref>"
136+
exit 1
137+
fi

.github/scripts/find_new_boards.sh

Lines changed: 0 additions & 62 deletions
This file was deleted.

.github/workflows/allboards.yml

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)