|
| 1 | +# Copyright 2023, Victor Chavez |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +stages: |
| 5 | + - compile |
| 6 | + - quality |
| 7 | + - style |
| 8 | + - usage |
| 9 | + - static_analysis |
| 10 | + - pages |
| 11 | + |
| 12 | +variables: |
| 13 | + SRC_DIR: src |
| 14 | + NORDIC_CONNECT_SDK_VERSION: v2.3.0 |
| 15 | + ZEPHYR_TOOLCHAIN_VERSION: 0.14.1 |
| 16 | + ZEPHYR_BOARD: nrf52dk_nrf52832 |
| 17 | + # Paths defined in docker image nordicplayground/nrfconnect-sdk:main |
| 18 | + PROJ_PATH: /workdir/project |
| 19 | + SDK_PATH: /workdir/zephyr-sdk |
| 20 | + COMPILATION_FILE: $PROJ_PATH/build/compile_commands.json |
| 21 | + |
| 22 | +Usage Analysis: |
| 23 | + image: registry.git.fh-aachen.de/embeddedtools/static-analysis/embedded-sa-docker:nrf-connect |
| 24 | + tags: |
| 25 | + - shared |
| 26 | + stage: usage |
| 27 | + needs: |
| 28 | + ["Compile"] |
| 29 | + before_script: |
| 30 | + - tar -xf zephyr_build.tar.xz -C $PROJ_PATH |
| 31 | + - cd $PROJ_PATH |
| 32 | + - export ZEPHYR_ELF=$(find -type f -name 'zephyr.elf') |
| 33 | + - mv $ZEPHYR_ELF ${CI_PROJECT_DIR}/zephyr.elf |
| 34 | + - pip3 install requests |
| 35 | + - pip3 install -Iv puncover==0.2.2 |
| 36 | + - cd ${CI_PROJECT_DIR} |
| 37 | + - git clone https://github.com/vChavezB/puncover_html |
| 38 | + - git clone https://git.fh-aachen.de/embedded-guidelines/utils/puncover-toolchain-find |
| 39 | + - export GCC_BASE=$(python3 puncover-toolchain-find/puncover-toolchain-find.py "${COMPILATION_FILE}") |
| 40 | + script: |
| 41 | + - echo $GCC_BASE |
| 42 | + - puncover --elf_file ${CI_PROJECT_DIR}/zephyr.elf --gcc_tools_base $GCC_BASE --build_dir $PROJ_PATH/build > /dev/null & |
| 43 | + - sleep 5 |
| 44 | + - python3 puncover_html/puncover_html.py usage_analysis |
| 45 | + artifacts: |
| 46 | + name: "${CI_PROJECT_NAME}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}" |
| 47 | + expire_in: 10 mins |
| 48 | + paths: |
| 49 | + - usage_analysis |
| 50 | + |
| 51 | +Halstead Metrics: |
| 52 | + image: registry.git.fh-aachen.de/embeddedtools/ccccc-docker:latest |
| 53 | + tags: |
| 54 | + - shared |
| 55 | + needs: |
| 56 | + ["Compile"] |
| 57 | + variables: |
| 58 | + OUT_DIR: ${CI_PROJECT_DIR}/html_out |
| 59 | + stage: quality |
| 60 | + before_script: |
| 61 | + - export SRC_FILES=$(find ${SRC_DIR} -name '*.c' -o -name '*.cpp' -type f | paste -sd " ") |
| 62 | + - mkdir -p $PROJ_PATH |
| 63 | + - tar -xf zephyr_build.tar.xz -C $PROJ_PATH |
| 64 | + script: |
| 65 | + - mv $COMPILATION_FILE compile_commands.json |
| 66 | + - mkdir ${OUT_DIR} |
| 67 | + - ccccc ${SRC_FILES} -t $HTML_STATIC/template/html/template.tpl > ${OUT_DIR}/index.html |
| 68 | + - cp -a $HTML_STATIC/* ${OUT_DIR} |
| 69 | + - cd ${OUT_DIR} |
| 70 | + - rm -rf 3rd/doctest |
| 71 | + - sed -i 's!file:////usr/bin/ccccc/!!g' index.html |
| 72 | + artifacts: |
| 73 | + name: "${CI_PROJECT_NAME}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}" |
| 74 | + expire_in: 10 mins |
| 75 | + paths: |
| 76 | + - $OUT_DIR |
| 77 | + |
| 78 | +Style: |
| 79 | + image: registry.git.fh-aachen.de/embeddedtools/embedded-quality-docker:latest |
| 80 | + tags: |
| 81 | + - shared |
| 82 | + stage: style |
| 83 | + before_script: |
| 84 | + - wget -nv https://git.fh-aachen.de/embedded-guidelines/cfg/kwstyle_config/-/raw/main/kwstyle_embedded_guidelines.xml |
| 85 | + - wget -nv https://git.fh-aachen.de/embedded-guidelines/cfg/vera-fh-profile/-/raw/main/FH.tcl |
| 86 | + - mv FH.tcl /usr/lib/vera++/profiles/FH.tcl |
| 87 | + script: |
| 88 | + # Creat input file with all c/c++ sources |
| 89 | + - find ${SRC_DIR} -type f -regex '.*\.\(ino\|c\|cpp\|hpp\|h\)' > input_files.txt |
| 90 | + - KWStyle -D input_files.txt -xml kwstyle_embedded_guidelines.xml -html kwsytle_html |
| 91 | + - vera++ -p FH.tcl -i input_files.txt -o vera.log -P max-line-length=125 -e |
| 92 | + artifacts: |
| 93 | + when: on_failure |
| 94 | + name: "${CI_PROJECT_NAME}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}" |
| 95 | + expire_in: 10 mins |
| 96 | + paths: |
| 97 | + - vera.log |
| 98 | + - kwsytle_html |
| 99 | + |
| 100 | + |
| 101 | +Security: |
| 102 | + image: registry.git.fh-aachen.de/embeddedtools/embedded-quality-docker:latest |
| 103 | + tags: |
| 104 | + - shared |
| 105 | + stage: quality |
| 106 | + script: |
| 107 | + - flawfinder ${SRC_DIR}/ > flaws.out |
| 108 | + - cat flaws.out |
| 109 | + artifacts: |
| 110 | + name: "${CI_PROJECT_NAME}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}" |
| 111 | + expire_in: 10 mins |
| 112 | + paths: |
| 113 | + - flaws.out |
| 114 | + |
| 115 | +Complexity: |
| 116 | + image: registry.git.fh-aachen.de/embeddedtools/embedded-quality-docker:latest |
| 117 | + tags: |
| 118 | + - shared |
| 119 | + stage: quality |
| 120 | + script: |
| 121 | + - lizard ${SRC_DIR} -l cpp -o complexity.html |
| 122 | + - cppclean ${SRC_DIR} > cppclean.txt || true |
| 123 | + artifacts: |
| 124 | + name: "${CI_PROJECT_NAME}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}" |
| 125 | + expire_in: 10 mins |
| 126 | + paths: |
| 127 | + - complexity.html |
| 128 | + - cppclean.txt |
| 129 | + |
| 130 | +Duplicates: |
| 131 | + image: registry.git.fh-aachen.de/embeddedtools/embedded-quality-docker:latest |
| 132 | + tags: |
| 133 | + - shared |
| 134 | + stage: quality |
| 135 | + variables: |
| 136 | + MIN_DUP_TOKEN: 50 #minimum tokens to detect as duplicates for cpd |
| 137 | + script: |
| 138 | + #Change name of sketch so it can be detected by tools |
| 139 | + - $PMD_RUN cpd --minimum-tokens $MIN_DUP_TOKEN --files $SRC_DIR --language cpp --fail-on-violation false --format xml > cpd.xml |
| 140 | + - xsltproc $PMD_PATH/cpdhtml.xslt cpd.xml > cpd_duplicates.html |
| 141 | + #Lizard |
| 142 | + - lizard -l cpp -Eduplicate ${SRC_DIR} > lizard_duplicates.txt || true |
| 143 | + #Remove the complexity report and just get the duplicate info |
| 144 | + - sed -i '1,/^Duplicates$/d' lizard_duplicates.txt |
| 145 | + artifacts: |
| 146 | + name: "${CI_PROJECT_NAME}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}" |
| 147 | + expire_in: 10 mins |
| 148 | + paths: |
| 149 | + - cpd_duplicates.html |
| 150 | + - lizard_duplicates.txt |
| 151 | + |
| 152 | +Metrics: |
| 153 | + image: registry.git.fh-aachen.de/embeddedtools/embedded-quality-docker:latest |
| 154 | + tags: |
| 155 | + - shared |
| 156 | + stage: quality |
| 157 | + variables: |
| 158 | + #More info about the metrics here https://metrixplusplus.github.io/metrixplusplus/docs/01-u-overview |
| 159 | + METRIC_ARGS: --std.code.filelines.total --std.code.lines.preprocessor --std.code.lines.comments --std.code.complexity.maxindent --std.code.todo.strings --std.code.lines.code --std.code.complexity.cyclomatic --std.code.maintindex.simple |
| 160 | + before_script: |
| 161 | + - apk add --no-cache git |
| 162 | + script: |
| 163 | + - cd /tmp/ |
| 164 | + - git clone $CI_REPOSITORY_URL main_branch |
| 165 | + - cd main_branch |
| 166 | + #If on the main branch,checkout one commit before |
| 167 | + - |- |
| 168 | + if [[ $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH ]]; then |
| 169 | + git checkout ${CI_COMMIT_SHA}^ |
| 170 | + fi |
| 171 | + - metrix++ collect ${METRIC_ARGS} -- ${SRC_DIR} |
| 172 | + - cd $CI_PROJECT_DIR/ |
| 173 | + - metrix++ collect ${METRIC_ARGS} -- ${SRC_DIR} |
| 174 | + - metrix++ view --db-file=metrixpp.db --db-file-prev=/tmp/main_branch/metrixpp.db > metrics.txt |
| 175 | + - cat metrics.txt |
| 176 | + artifacts: |
| 177 | + name: "${CI_PROJECT_NAME}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}" |
| 178 | + expire_in: 10 mins |
| 179 | + paths: |
| 180 | + - metrics.txt |
| 181 | + |
| 182 | +Compile: |
| 183 | + image: registry.git.fh-aachen.de/embeddedtools/nrf-docker:$NORDIC_CONNECT_SDK_VERSION |
| 184 | + tags: |
| 185 | + - shared |
| 186 | + stage: compile |
| 187 | + script: |
| 188 | + - cd $PROJ_PATH |
| 189 | + - west build $CI_PROJECT_DIR/samples/uptime --board $ZEPHYR_BOARD |
| 190 | + #- sed -i 's!--param=min-pagesize=0 !!g' $COMPILATION_FILE |
| 191 | + # Build files required for static analysis |
| 192 | + - tar -cJf $CI_PROJECT_DIR/zephyr_build.tar.xz build |
| 193 | + artifacts: |
| 194 | + name: "${CI_PROJECT_NAME}-${CI_JOB_STAGE}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}" |
| 195 | + expire_in: 10 mins |
| 196 | + paths: |
| 197 | + - zephyr_build.tar.xz |
| 198 | + |
| 199 | +Cppcheck: |
| 200 | + needs: |
| 201 | + - job: Compile |
| 202 | + image: registry.git.fh-aachen.de/embeddedtools/static-analysis/cppcheck-docker:latest |
| 203 | + tags: |
| 204 | + - shared |
| 205 | + stage: static_analysis |
| 206 | + variables: |
| 207 | + REPORT_DIR: cppcheck_report |
| 208 | + script: |
| 209 | + #Analyze src dir and generate xml output |
| 210 | + - wget -nv https://git.fh-aachen.de/embedded-guidelines/cfg/cppcheck-cfg/-/raw/main/cppcheck_suppresion.txt |
| 211 | + - export CPPCHECK_ARGS="--suppressions-list=cppcheck_suppresion.txt --force --enable=all --inline-suppr" |
| 212 | + - cppcheck ${CPPCHECK_ARGS} --xml --xml-version=2 ${SRC_DIR} 2>cpp_check_report.xml |
| 213 | + #convert xml output to html |
| 214 | + - cppcheck-htmlreport --source-dir=. --title=$project_name --file=cpp_check_report.xml --report-dir=$REPORT_DIR |
| 215 | + #After checking errors, make the ci/cd fail if cppcheck found errors |
| 216 | + - cppcheck ${CPPCHECK_ARGS} --error-exitcode=1 ${SRC_DIR} |
| 217 | + artifacts: |
| 218 | + when: on_failure |
| 219 | + name: "${CI_PROJECT_NAME}-${CI_JOB_STAGE}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}" |
| 220 | + expire_in: 10 mins |
| 221 | + paths: |
| 222 | + - $REPORT_DIR |
| 223 | + |
| 224 | +PVS Studio: |
| 225 | + image: registry.git.fh-aachen.de/embeddedtools/static-analysis/embedded-sa-docker:nrf-connect |
| 226 | + needs: |
| 227 | + - job: Compile |
| 228 | + tags: |
| 229 | + - shared |
| 230 | + stage: static_analysis |
| 231 | + variables: |
| 232 | + REPORT_DIR: PVS_report |
| 233 | + ZEPHYR_SYSLIB: /usr/lib/gcc/arm-zephyr-eabi |
| 234 | + before_script: |
| 235 | + #Add PVS Studio comments for free analysis, refer to: |
| 236 | + #https://pvs-studio.com/en/docs/warnings/v009/ |
| 237 | + - git clone https://git.fh-aachen.de/embeddedutils/pvs-free #utility to add pvs free comments |
| 238 | + - tar -xf zephyr_build.tar.xz -C $PROJ_PATH |
| 239 | + script: |
| 240 | + # Add comments to use academic license |
| 241 | + - python3 pvs-free/pvs-free.py . --add |
| 242 | + # PVS studio cant detect zephyr arm compiler, replace with vanilla arm-none-eabi |
| 243 | + #- sed -i 's/arm-zephyr-eabi-gcc/arm-none-eabi-gcc/g' $COMPILATION_FILE |
| 244 | + #- sed -i 's/arm-zephyr-eabi-g++/arm-none-eabi-g++/g' $COMPILATION_FILE |
| 245 | + #- sed -i 's!workdir/zephyr-sdk/arm-zephyr-eabi/bin!usr/bin!g' $COMPILATION_FILE |
| 246 | + - pvs-studio-analyzer analyze -f $COMPILATION_FILE -o project.log -e \*$PROJ_PATH/\* |
| 247 | + - plog-converter -t fullhtml project.log -o $REPORT_DIR |
| 248 | + - |- |
| 249 | + if ! grep -q Congratulations "$REPORT_DIR/index.html"; then |
| 250 | + >&2 echo "PVS Studio found issues!" |
| 251 | + exit 1 |
| 252 | + fi |
| 253 | + artifacts: |
| 254 | + when: on_failure |
| 255 | + name: "${CI_PROJECT_NAME}-${CI_JOB_STAGE}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}" |
| 256 | + expire_in: 10 mins |
| 257 | + paths: |
| 258 | + - $REPORT_DIR |
| 259 | + |
| 260 | +CodeChecker: |
| 261 | + image: registry.git.fh-aachen.de/embeddedtools/static-analysis/embedded-sa-docker:nrf-connect |
| 262 | + needs: |
| 263 | + - job: Compile |
| 264 | + tags: |
| 265 | + - shared |
| 266 | + stage: static_analysis |
| 267 | + variables: |
| 268 | + CODECHECKER_ANALYZER_OUT: /tmp |
| 269 | + REPORT_DIR: codechecker_report |
| 270 | + before_script: |
| 271 | + - wget -nv https://git.fh-aachen.de/embedded-guidelines/cfg/codechecker-cfg/-/raw/main/FH-Codechecker.json |
| 272 | + - mkdir $REPORT_DIR |
| 273 | + # Build files required for static analysis |
| 274 | + - tar -xf zephyr_build.tar.xz -C $PROJ_PATH |
| 275 | + script: |
| 276 | + #Activating python env for codechecker |
| 277 | + - source $CODECHECKER_ACTIVATE |
| 278 | + #Env Variable that tells codechecker to analyze compiler calls for arm toolchain |
| 279 | + - export CC_LOGGER_GCC_LIKE="arm-zephyr-eabi-gcc:arm-zephyr-eabi-g++" |
| 280 | + #Create Skip file for analyzing project, only src of the project |
| 281 | + # more information about the skip file format: |
| 282 | + # https://codechecker.readthedocs.io/en/latest/analyzer/user_guide/#skip |
| 283 | + #- echo -e "+*/$SRC_DIR\n" >> skip.file #only analyze the source files |
| 284 | + - echo -e "-$PROJ_PATH*\n" >> skip.file |
| 285 | + - echo -e "-$SDK_PATH*" >> skip.file |
| 286 | + - echo -e "-D__WCHAR_MIN__=0 -m32 -I/workdir/zephyr-sdk/arm-zephyr-eabi/lib/gcc/arm-zephyr-eabi/10.3.0/include/" >> sa_flags.txt |
| 287 | + - echo -e "-extra-arg-before='-m32' -extra-arg-before='-I/workdir/zephyr-sdk/arm-zephyr-eabi/lib/gcc/arm-zephyr-eabi/10.3.0/include/'" >> tidy_flags.txt |
| 288 | + #Analyze the files |
| 289 | + - CodeChecker analyze $COMPILATION_FILE --tidyargs tidy_flags.txt --saargs sa_flags.txt --ctu -i skip.file --enable extreme --output $CODECHECKER_ANALYZER_OUT --config FH-Codechecker.json > /dev/null |
| 290 | + #Parse the analysis as html |
| 291 | + - CodeChecker parse --export html --output ${REPORT_DIR} $CODECHECKER_ANALYZER_OUT --verbose debug |
| 292 | + artifacts: |
| 293 | + when: on_failure |
| 294 | + name: "${CI_PROJECT_NAME}-${CI_JOB_STAGE}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}" |
| 295 | + expire_in: 10 mins |
| 296 | + paths: |
| 297 | + - $REPORT_DIR |
| 298 | + |
| 299 | +pages: |
| 300 | + variables: |
| 301 | + # allows retrieving commits far away from last tag for proj number in doxygen |
| 302 | + GIT_DEPTH: "50" |
| 303 | + image: registry.git.fh-aachen.de/embeddedtools/docs:latest |
| 304 | + tags: |
| 305 | + - shared |
| 306 | + stage: pages |
| 307 | + script: |
| 308 | + - mkdir public |
| 309 | + - GIT_VERSION=$(git describe --long --always --tags) |
| 310 | + - git clone https://git.fh-aachen.de/embedded-guidelines/cfg/doxygen_cfg.git --recurse-submodules --branch v1.2.0 |
| 311 | + - cd doxygen_cfg |
| 312 | + #change name for project in doxyfile |
| 313 | + - sed -i "s!ProjectName!$CI_PROJECT_NAME!g" Doxyfile.in |
| 314 | + #Replace input files in template |
| 315 | + - sed -i "s!README_FILE!${CI_PROJECT_DIR}/README.md!g" Doxyfile.in |
| 316 | + - sed -i "s!PROJ_NUM!${GIT_VERSION}!g" Doxyfile.in |
| 317 | + - sed -i "s!INPUT_FILES!${CI_PROJECT_DIR}/${SRC_DIR}!g" Doxyfile.in |
| 318 | + - doxygen Doxyfile.in |
| 319 | + - mv html/* ${CI_PROJECT_DIR}/public |
| 320 | + artifacts: |
| 321 | + name: "${CI_PROJECT_NAME}-${CI_JOB_STAGE}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}" |
| 322 | + expire_in: 10 mins |
| 323 | + paths: |
| 324 | + - public |
| 325 | + rules: |
| 326 | + - if: $CI_COMMIT_BRANCH == "main" |
| 327 | + - if: $CI_COMMIT_BRANCH == "master" |
| 328 | + - if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/' |
0 commit comments