Skip to content

Commit

Permalink
feat: add codeql scanning (#87)
Browse files Browse the repository at this point in the history
* feat: add codeql scanning
---------

Signed-off-by: Neethu Elizabeth Simon <[email protected]>
  • Loading branch information
NeethuES-intel authored Apr 3, 2024
1 parent b307909 commit 44a9f8b
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/.rdjson.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Convert hadolint JSON output to Reviewdog Diagnostic Format (rdjson)
# https://github.com/reviewdog/reviewdog/blob/f577bd4b56e5973796eb375b4205e89bce214bd9/proto/rdf/reviewdog.proto
{
source: {
name: "hadolint",
url: "https://github.com/hadolint/hadolint"
},
diagnostics: . | map({
message: .message,
code: {
value: .code,
url: (if .code | startswith("DL") then
"https://github.com/hadolint/hadolint/wiki/\(.code)"
elif .code | startswith("SC") then
"https://github.com/koalaman/shellcheck/wiki/\(.code)"
else
null
end),
} ,
location: {
path: .file,
range: {
start: {
line: .line,
column: .column
}
}
},
severity: ((.level|ascii_upcase|select(match("ERROR|WARNING|INFO")))//null)
})
}
21 changes: 21 additions & 0 deletions .github/.reviewdogConfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
runner:
bandit:
cmd: 'bandit -r ./ -f custom --msg-template "{relpath}:{line}:{col}:{test_id}:{severity}:{msg}" | tee "$PWD"/scan_results/banditResults.txt'
errorformat: # (optional if you use `format`)
- "%f:%l:%c:%m"
name: bandit # (optional. you can overwrite <tool-name> defined by runner key)
level: info # (optional. same as -level flag. [info,warning,error])
hadolint:
cmd: './bin/hadolint -c .github/.hadolint.yaml Dockerfile.* -f json | jq -f ".github/.rdjson.jq" -c | tee "$PWD"/scan_results/hadolintResults.txt'
format: rdjson
level: error # (optional. same as -level flag. [info,warning,error])
shellcheck:
cmd: shellcheck **/*.sh -f gcc | tee "$PWD"/scan_results/shellcheckResults.txt
errorformat:
- "%f:%l:%c:%m"
pep8:
cmd: pep8 **/*.py | tee "$PWD"/scan_results/pep8Results.txt
format: pep8
# golangci-lint:
# cmd: ./bin/golangci-lint run --config .github/.golangci.yml --out-format=line-number **/*.go
# format: golangci-lint
63 changes: 63 additions & 0 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
jobs:
analyze:
name: Analyze
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'python', 'go' ] #[ 'cpp', 'python', 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# :information_source: Command-line programs to run using the OS shell.
# :books: See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"

0 comments on commit 44a9f8b

Please sign in to comment.