Migrate MISRA scanning to Github Actions + Update to cppcheck v2.7 (#923)

* Initial creation of test action

* Fix relative directory

* Change to cppcheck v2.7

* Change script call

* Direct error count into file

* Fix env writing

* env update

* More env testing

* Another env test

* More testing

* More testing

* Yet more env testing

* Change to results count file

* Further testing

* Remove continue on error

* Force script to complete successfully

* Force create results dir

* Force set results directory

* Fix bad syntax

* Add badge to README

* Remove Azure pipelines

* Re-add cat of results file

* Add quiet option to script

* Add back missing line
This commit is contained in:
Josh Stewart 2022-09-07 16:04:51 +10:00 committed by GitHub
parent 75d6c2ff61
commit cf45e6c289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 65 deletions

51
.github/workflows/misra.yml vendored Normal file
View File

@ -0,0 +1,51 @@
name: Perform MISRA scan
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches:
- master
- GH_misra
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-22.04
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Install cppcheck
run: |
sudo apt-get install cppcheck
- name: Run MISRA scan
continue-on-error: true
run: |
cd $GITHUB_WORKSPACE/misra/
mkdir .results
chmod +x check_misra.sh
./check_misra.sh -c /usr/bin -o ./.results -q
echo "Scan complete"
NumViolations=`cat .results/error_count.txt`
echo $NumViolations
echo "VIOLATIONS=$NumViolations" >> $GITHUB_ENV
- name: Save output to Gist
if: github.event_name != 'pull_request' && github.repository_owner == 'noisymime'
env:
MISRA_GIST: ${{ secrets.MISRA_GIST }}
VIOLATIONS: ${{ env.VIOLATIONS }}
uses: schneegans/dynamic-badges-action@v1.4.0
with:
auth: ${{ secrets.MISRA_GIST }}
gistID: d8a449a3f6d3307dab457431512502f9
filename: misra_results.json
label: MISRA Violations
color: red
message: ${{ env.VIOLATIONS }}

View File

@ -8,7 +8,7 @@
[![Unit Tests](https://img.shields.io/github/workflow/status/noisymime/speeduino/Unit%20Tests?label=Unit%20Tests)](https://github.com/noisymime/speeduino/actions/workflows/unit-tests.yml)
[![Open Bounties](https://img.shields.io/bountysource/team/speeduino/activity.svg)](https://www.bountysource.com/teams/speeduino)
[![GitHub commits](https://img.shields.io/github/commits-since/noisymime/speeduino/202207.svg)](https://github.com/noisymime/speeduino/compare/202207...master)
![MISRA](https://img.shields.io/azure-devops/tests/speeduino/Speeduino/1?label=MISRA&passed_label=warnings&failed_label=violations)
![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/noisymime/d8a449a3f6d3307dab457431512502f9/raw/misra_results.json)
[![Chat on Discord](https://img.shields.io/badge/discord-speeduino-CC2B5E.svg?style=flat&logo=discord)](https://speeduino.com/home/community/discord)
##### A low cost, DIY friendly Engine Management System (ECU) based on the Arduino framework

View File

@ -1,45 +0,0 @@
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- bash: |
sudo sed -i -- 's/#deb-src/deb-src/g' /etc/apt/sources.list && sudo sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list
sudo apt-get update
sudo apt-get build-dep -qq cppcheck
displayName: 'Installing deps'
- bash: |
git clone --depth=10 https://github.com/noisymime/speeduino noisymime/speeduino
git clone --depth=10 https://github.com/noisymime/cppcheck.git noisymime/cppcheck_github
displayName: 'Cloning repos'
- bash: |
cd noisymime/cppcheck_github
make
displayName: 'Making cppcheck'
- bash: |
cd noisymime
chmod +x speeduino/misra/check_misra.sh
speeduino/misra/check_misra.sh -c "cppcheck_github"
#This task is always an error if there are MISRA violations
continueOnError: true
displayName: 'Running Scan'
# Publish test results to Azure Pipelines
- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/misra.xml'
#searchFolder: '$(System.DefaultWorkingDirectory)' # Optional
#mergeTestResults: false # Optional
#failTaskOnFailedTests: false # Optional
#testRunTitle: # Optional
#buildPlatform: # Optional
#buildConfiguration: # Optional
publishRunAttachments: true # Optional

View File

@ -7,6 +7,7 @@ source_folder="$script_folder/../speeduino" # -s, --source
file_exts="ino" # -e, --exts
out_folder="$script_folder/.results" # -o, --out
cppcheck_path="" # -c, --cppcheck
quiet=0 # -q, --quiet
function parse_command_line() {
while [ $# -gt 0 ] ; do
@ -15,6 +16,7 @@ function parse_command_line() {
-e | --exts) file_exts="$2" ;;
-o | --out) out_folder="$2" ;;
-c | --cppcheck) cppcheck_path="$2" ;;
-q | --quiet) quiet=1 ;;
-*)
echo "Unknown option: " $1
exit 1
@ -34,6 +36,7 @@ function run_cppcheck() {
--suppressions-list="$script_folder/suppressions.txt" \
-DCORE_AVR=1 \
-D__AVR_ATmega2560__ \
--quiet \
$i 2>> "$cpp_result_file"
done
shopt -u nullglob nocaseglob
@ -47,7 +50,7 @@ function process_cpp_results() {
# Remove duplicate lines
sort | uniq > "$intermediate_file"
# Count error lines
local __error_count=`grep ": error:" < "$intermediate_file" | wc -l`
local __error_count=`grep -i "Mandatory" < "$intermediate_file" | wc -l`
# Unfold the line groups for readability
tr '~' '\n' < "$intermediate_file" > "$result_file"
rm -f "$intermediate_file"
@ -69,11 +72,10 @@ rm -f "$result_file"
run_cppcheck
error_count="$(process_cpp_results)"
cat "$result_file"
echo $error_count MISRA violations
if [ $error_count -gt 0 ]; then
exit 1
else
exit 0
if [ $quiet -eq 0 ]; then
cat "$result_file"
fi
echo $error_count MISRA violations
echo $error_count > ".results/error_count.txt"
exit 0

View File

@ -94,17 +94,17 @@ No text specified
Rule 9.5
No text specified
Rule 10.1
Operations must be of an essentially correct type (Eg no shift on signed values, comparison is not boolean, incrementing/decrementing a bool etc)
Mandatory - Operations must be of an essentially correct type (Eg no shift on signed values, comparison is not boolean, incrementing/decrementing a bool etc)
Rule 10.2
No text specified
Rule 10.3
No text specified
Rule 10.4
The target of an operation must be of an appropriate type
Mandatory - The target of an operation must be of an appropriate type
Rule 10.5
No text specified
Rule 10.6
An expression should not assign a value to a variable of a narrower or essentially different type
Mandatory - An expression should not assign a value to a variable of a narrower or essentially different type
Rule 10.7
No text specified
Rule 10.8
@ -114,7 +114,7 @@ No text specified
Rule 11.2
No text specified
Rule 11.3
A cast shall not be performed between a pointer to object type and a pointer to a different object type
Mandatory - A cast shall not be performed between a pointer to object type and a pointer to a different object type
Rule 11.4
Advisory - Object pointers should not be treated as or converted to integers
Rule 11.5
@ -126,7 +126,7 @@ No text specified
Rule 11.8
No text specified
Rule 11.9
An integer null pointer shall have no value assigned other than NULL macro
Mandatory - An integer null pointer shall have no value assigned other than NULL macro
Rule 12.1
Advisory - Order of operations within an expression must be explicit. Multiple conditions in a logical operation should have brackets around them.
Rule 12.2
@ -166,9 +166,9 @@ No text specified
Rule 15.5
Advisory - A function should only have a single return point
Rule 15.6
Loops, switch and if/else statements must have brackets around their body
Mandatory - Loops, switch and if/else statements must have brackets around their body
Rule 15.7
'else if' statements must terminate with a final 'else'
Mandatory - 'else if' statements must terminate with a final 'else'
Rule 16.1
No text specified
Rule 16.2
@ -186,7 +186,7 @@ No text specified
Rule 17.1
No text specified
Rule 17.2
Functions shall not call themselves, either directly or indirectly
Mandatory - Functions shall not call themselves, either directly or indirectly
Rule 17.3
No text specified
Rule 17.4
@ -196,7 +196,7 @@ No text specified
Rule 17.6
No text specified
Rule 17.7
The value returned by a function having non-void return type shall be used
Mandatory - The value returned by a function having non-void return type shall be used
Rule 17.8
Advisory - An argument to a function should be treated as read-only
Rule 18.1
@ -232,7 +232,7 @@ Advisory - Use of #undef is not permitted
Rule 20.6
No text specified
Rule 20.7
Macro expressions must be enclosed in parentheses
Mandatory - Macro expressions must be enclosed in parentheses
Rule 20.8
No text specified
Rule 20.9
@ -252,7 +252,7 @@ No text specified
Rule 21.2
No text specified
Rule 21.3
Memory allocation functions (Eg malloc(), talloc() etc) shall not be used
Mandatory - Memory allocation functions (Eg malloc(), talloc() etc) shall not be used
Rule 21.4
No text specified
Rule 21.5