Skip to content

Commit 4d08092

Browse files
committed
Virus scans and super-linter added
Virus scans and super-linter added - Cpp and C scans with clang style enabled. - Python scanner enabled - Golang scanner enabled. - Markdown lint enabled. Signed-off-by: Milosz Linkiewicz <milosz.linkiewicz@intel.com>
1 parent 797ef9b commit 4d08092

File tree

14 files changed

+420
-24
lines changed

14 files changed

+420
-24
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BasedOnStyle: LLVM
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
#########################
3+
#########################
4+
## Golang Linter rules ##
5+
#########################
6+
#########################
7+
8+
# configure golangci-lint
9+
# see https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml
10+
issues:
11+
exclude-rules:
12+
- path: _test\.go
13+
linters:
14+
- dupl
15+
- gosec
16+
- goconst
17+
linters:
18+
enable:
19+
- gosec
20+
- unconvert
21+
- gocyclo
22+
- goconst
23+
- goimports
24+
- gocritic
25+
- govet
26+
- revive
27+
linters-settings:
28+
errcheck:
29+
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
30+
# default is false: such cases aren't reported by default.
31+
check-blank: true
32+
govet:
33+
enable:
34+
# report about shadowed variables
35+
- shadowing
36+
gocyclo:
37+
# minimal code complexity to report, 30 by default
38+
min-complexity: 15
39+
maligned:
40+
# print struct with more effective memory layout or not, false by default
41+
suggest-new: true
42+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
###########################
3+
###########################
4+
## Markdown Linter rules ##
5+
###########################
6+
###########################
7+
8+
# Linter rules doc:
9+
# - https://github.com/DavidAnson/markdownlint
10+
#
11+
# Note:
12+
# To comment out a single error:
13+
# <!-- markdownlint-disable -->
14+
# any violations you want
15+
# <!-- markdownlint-restore -->
16+
#
17+
18+
###############
19+
# Rules by id #
20+
###############
21+
MD004: false # Unordered list style
22+
MD007:
23+
indent: 2 # Unordered list indentation
24+
MD013:
25+
line_length: 400 # Line length 80 is far too short
26+
MD026:
27+
punctuation: ".,;:!。,;:" # List of not allowed
28+
MD029: false # Ordered list item prefix
29+
MD033: false # Allow inline HTML
30+
MD036: false # Emphasis used instead of a heading
31+
32+
#################
33+
# Rules by tags #
34+
#################
35+
blank_lines: false # Error on blank lines
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[MASTER]
2+
3+
# Use multiple processes to speed up Pylint.
4+
jobs=0
5+
6+
[MESSAGES CONTROL]
7+
8+
# Ignoring Import Errors is desired as super-linter
9+
# does not support installing dependencies as it runs
10+
disable=import-error
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
###########################################
3+
# These are the rules used for #
4+
# linting all the yaml files in the stack #
5+
# NOTE: #
6+
# You can disable line with: #
7+
# # yamllint disable-line #
8+
###########################################
9+
rules:
10+
braces:
11+
level: warning
12+
min-spaces-inside: 0
13+
max-spaces-inside: 0
14+
min-spaces-inside-empty: 1
15+
max-spaces-inside-empty: 5
16+
brackets:
17+
level: warning
18+
min-spaces-inside: 0
19+
max-spaces-inside: 0
20+
min-spaces-inside-empty: 1
21+
max-spaces-inside-empty: 5
22+
colons:
23+
level: warning
24+
max-spaces-before: 0
25+
max-spaces-after: 1
26+
commas:
27+
level: warning
28+
max-spaces-before: 0
29+
min-spaces-after: 1
30+
max-spaces-after: 1
31+
comments: disable
32+
comments-indentation: disable
33+
document-end: disable
34+
document-start:
35+
level: warning
36+
present: true
37+
empty-lines:
38+
level: warning
39+
max: 2
40+
max-start: 0
41+
max-end: 0
42+
hyphens:
43+
level: warning
44+
max-spaces-after: 1
45+
indentation:
46+
level: warning
47+
spaces: consistent
48+
indent-sequences: true
49+
check-multi-line-strings: false
50+
key-duplicates: enable
51+
line-length:
52+
level: warning
53+
max: 80
54+
allow-non-breakable-words: true
55+
allow-non-breakable-inline-mappings: true
56+
new-line-at-end-of-file: disable
57+
new-lines:
58+
type: unix
59+
trailing-spaces: disable

.github/scripts/github_common.sh

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#!/bin/bash
2+
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
# Copyright 2024 Intel Corporation
5+
6+
script_dir=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")
7+
repository_root=$(readlink -f "${script_dir}/../..")
8+
9+
# shellcheck source="../../scripts/common.sh"
10+
. "${repository_root}/scripts/common.sh"
11+
12+
allow_non_ascii_filenames="false"
13+
14+
function get_main_sha()
15+
{
16+
log_info "Getting origin/main commit SHA"
17+
git_origin_main=$(git rev-parse --verify origin/main)
18+
log_info "running against origin/master=${git_origin_main}"
19+
echo $git_origin_main
20+
}
21+
22+
function get_head_sha()
23+
{
24+
log_info "Getting HEAD commit SHA"
25+
if $(git rev-parse --verify HEAD >/dev/null 2>&1)
26+
then
27+
git_current_hash=$(git rev-parse --verify HEAD)
28+
else
29+
echo "This is first commit, nothing to check, exiting"
30+
exit 0
31+
fi
32+
log_info "running against HEAD=${git_current_hash}"
33+
echo $git_current_hash
34+
}
35+
36+
function check_nonascii_files()
37+
{
38+
local github_origin_main="$1"
39+
local github_current_hash="$2"
40+
local allow_non_ascii=${3:-false}
41+
42+
if [ "$allow_non_ascii" == "false" ]
43+
then
44+
if test $(git diff --diff-filter=AR --relative --name-only -z $github_origin_main $github_current_hash | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
45+
then
46+
cat <<EOF
47+
Error: You attempted to add a non-ASCII file name.
48+
This is not allowed in Cloud Native Data Services repository.
49+
To be portable it is mandatory for you to rename all the file.
50+
EOF
51+
fi
52+
fi
53+
}
54+
55+
function check_file_subdir_type()
56+
{
57+
local modified_file="$1"
58+
local fields_range=${2:-'1'}
59+
60+
if [ -z "$modified_file" ]
61+
then
62+
printf "Function check_file_subdir_type requires exacly 1 valid argument." 1>&2
63+
exit 1
64+
fi
65+
printf "${modified_file}" | cut -d'/' "-f${fields_range}"
66+
}
67+
68+
function files_subdir_types()
69+
{
70+
local github_origin_main="$1"
71+
local github_current_hash="$2"
72+
73+
# diff-filter params, uppercase include, lowercase exclude:
74+
# Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), changed (T), Unmerged (U), Unknown (X), pairing Broken (B)
75+
modified_file_list="$(git diff --diff-filter=dxb --relative --name-only -z $github_origin_main $github_current_hash | xargs -0)"
76+
77+
for pt in $modified_file_list
78+
do
79+
modified_file="$(readlink -f "${pt}")"
80+
81+
[ -d "$modified_file" ] && modified_dir="$modified_file" || modified_dir="$(dirname "$modified_file")";
82+
case $(check_file_subdir_type "${modified_file}") in
83+
deployment)
84+
deployment_subdir_check "${modified_file}" "${modified_dir}"
85+
;;
86+
87+
config)
88+
configuration_subdir_check "${modified_file}"
89+
;;
90+
91+
docs)
92+
documentation_subdir_check "${modified_file}"
93+
;;
94+
95+
.github)
96+
github_workflow_subdir_check "${modified_file}"
97+
;;
98+
99+
tests|scripts)
100+
ansible_subdir_check "${modified_file}"
101+
;;
102+
103+
*)
104+
if echo "${modified_file}" | grep --silent ".*\.sh\$"; then
105+
shell_script_file_check "${modified_file}"
106+
elif echo "${modified_file}" | grep --silent ".*\.py\$"; then
107+
python_script_file_check "${modified_file}"
108+
elif echo "${modified_file}" | grep --silent "\(\.yaml\$\)\|\(\.yml\$\)"; then
109+
ansible_subdir_check "${modified_file}"
110+
else
111+
other_file_check "${modified_file}"
112+
fi
113+
;;
114+
esac
115+
done
116+
}
117+
118+
function images_subdir_check {
119+
local filepath="$1"
120+
shift
121+
log_info "Dockerfiles images subdirectory. ${filepath}"
122+
}
123+
124+
function deployment_subdir_check() {
125+
local filepath="$1"
126+
local dirpath="$2"
127+
shift; shift;
128+
log_info "Helm Charts deployment subdirectory. ${filepath}"
129+
helm lint "$dirpath" 1>&2 || true
130+
}
131+
132+
function ansible_subdir_check() {
133+
local filepath="$1"
134+
local dirpath="$2"
135+
shift; shift;
136+
echo "ansible roles and playbooks subdirectory. ${filepath}"
137+
ansible-lint "$filepath" 1>&2 || true
138+
}
139+
140+
function inventories_subdir_check() {
141+
local filepath="$1"
142+
shift
143+
log_info "inventories files subdirectory. ${filepath}"
144+
}
145+
146+
function configuration_subdir_check() {
147+
local filepath="$1"
148+
shift
149+
log_info "configuration files subdirectory. ${filepath}"
150+
}
151+
152+
function documentation_subdir_check() {
153+
local filepath="$1"
154+
shift
155+
log_info "documentation files and styles subdirectory. ${filepath}"
156+
}
157+
158+
function github_workflow_subdir_check() {
159+
local filepath="$1"
160+
shift
161+
log_info "GitHub workflows subdirectory. ${filepath}"
162+
}
163+
164+
function shell_script_file_check() {
165+
local filepath="$1"
166+
shift
167+
log_info "Shell script file path. ${filepath}"
168+
shellcheck -f tty "${repository_root}/$filepath" 1>&2
169+
}
170+
171+
function python_script_file_check() {
172+
local filepath="$1"
173+
shift
174+
log_info "Python script file path. ${filepath}"
175+
}
176+
177+
function other_file_check() {
178+
local filepath="$1"
179+
shift
180+
log_info "Other file path, not categorized. ${filepath}"
181+
}
182+
183+
function start_git_head_parsing() {
184+
cd "${repository_root}"
185+
git_current_hash="$(get_head_sha)"
186+
git_origin_main="$(get_main_sha)"
187+
check_nonascii_files "$git_origin_main" "$git_current_hash" allow_non_ascii_filenames
188+
files_subdir_types "$git_origin_main" "$git_current_hash" || true
189+
}
190+
191+
start_git_head_parsing

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ permissions:
2020
contents: read
2121

2222
concurrency:
23-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
23+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || env.GITHUB_SHA }}
2424
cancel-in-progress: true
2525

2626
jobs:

.github/workflows/coverity.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ env:
2020
permissions:
2121
contents: read
2222

23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || env.GITHUB_SHA }}
25+
cancel-in-progress: true
26+
2327
jobs:
2428
coverity:
2529
runs-on: 'ubuntu-22.04'

0 commit comments

Comments
 (0)