|
| 1 | +# Copyright (C) 2021 Intel Corporation |
| 2 | +# SPDX-License-Identifier: BSD-3-Clause |
| 3 | + |
| 4 | +# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions |
| 5 | + |
| 6 | +name: Coverity Pull Request Scan |
| 7 | + |
| 8 | +permissions: |
| 9 | + # Grant read permissions to private container images. |
| 10 | + packages: read |
| 11 | + |
| 12 | +on: |
| 13 | + pull_request: |
| 14 | + paths: |
| 15 | + - '**' |
| 16 | + - '!**.md' |
| 17 | + - '!**/.clang-format' |
| 18 | + - '!**/COPYING' |
| 19 | + - '!**/LICENSE' |
| 20 | + - '!.github/**' |
| 21 | + - '.github/workflows/coverity-pull-request.yml' |
| 22 | + - '!.gitignore' |
| 23 | + - '!cmake/manifests/**' |
| 24 | + - '!container/**' |
| 25 | + - '!docs/**' |
| 26 | + - '!scripts/**' |
| 27 | + types: |
| 28 | + - opened |
| 29 | + - reopened |
| 30 | + - synchronize |
| 31 | + - labeled |
| 32 | + - unlabeled |
| 33 | + |
| 34 | +jobs: |
| 35 | + build: |
| 36 | + name: Coverity Validation |
| 37 | + if: ${{ ! contains( github.event.pull_request.labels.*.name, 'coverity-override') }} |
| 38 | + runs-on: |
| 39 | + - self-hosted |
| 40 | + - linux |
| 41 | + - x64 |
| 42 | + - container |
| 43 | + |
| 44 | + container: |
| 45 | + image: ghcr.io/intel/fpga-runtime-for-opencl/ubuntu-22.04-dev:main |
| 46 | + volumes: |
| 47 | + - /opt/coverity:/opt/coverity |
| 48 | + |
| 49 | + steps: |
| 50 | + - name: Checkout PR |
| 51 | + uses: actions/checkout@v3 |
| 52 | + - run: echo /opt/coverity/latest/bin >> "$GITHUB_PATH" |
| 53 | + - name: Build current |
| 54 | + run: | |
| 55 | + cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release |
| 56 | + # The --compiler names must match those used by CMake. |
| 57 | + # https://community.synopsys.com/s/article/cov-build-returns-WARNING-No-files-were-emitted-This-may-be-due-to-a-problem-with-your-configuration |
| 58 | + # https://community.synopsys.com/s/article/Configuring-Your-Compilers-for-Coverity-Analysis |
| 59 | + cov-configure --config config.xml --template --comptype gcc --compiler cc |
| 60 | + cov-configure --config config.xml --template --comptype g++ --compiler c++ |
| 61 | + cov-build --config config.xml --dir results ninja -C build -v -k0 |
| 62 | + cov-manage-emit --dir results --tu-pattern "file('/lib/CppUTest/')" delete |
| 63 | + cov-analyze --config config.xml --dir results --concurrency --security --rule --enable-constraint-fpp --enable-fnptr --enable-virtual |
| 64 | + cov-format-errors --text-output-style multiline --dir results --filesort --file "$PWD" --strip-path "$PWD" > cov-errors.txt |
| 65 | + cat cov-errors.txt |
| 66 | + - name: Build base |
| 67 | + run: | |
| 68 | + git fetch origin |
| 69 | + git reset --hard origin/$GITHUB_BASE_REF |
| 70 | + rm -rf build_base |
| 71 | + mkdir -p build_base |
| 72 | + cd build_base |
| 73 | + CC=gcc CXX=g++ cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release |
| 74 | + cov-configure --config config.xml --template --comptype gcc --compiler gcc |
| 75 | + cov-configure --config config.xml --template --comptype g++ --compiler g++ |
| 76 | + cov-build --config config.xml --dir results ninja -v && cov-manage-emit --dir results --tu-pattern "file('/lib/CppUTest/')" delete && cov-analyze --config config.xml --dir results --concurrency --security --rule --enable-constraint-fpp --enable-fnptr --enable-virtual |
| 77 | + cov-format-errors --text-output-style multiline --dir results --filesort --file "$(realpath ..)" --strip-path "$(realpath ..)" > ../cov-errors-base.txt |
| 78 | + cd .. |
| 79 | + readlink -f cov-errors-base.txt |
| 80 | + - name: Upload current cov-errors.txt |
| 81 | + uses: actions/upload-artifact@v3 |
| 82 | + with: |
| 83 | + name: fpga-runtime-for-opencl-${{ github.sha }}-coverity-${{ github.run_id }} |
| 84 | + path: cov-errors.txt |
| 85 | + if-no-files-found: error |
| 86 | + - name: Upload base cov-errors.txt |
| 87 | + uses: actions/upload-artifact@v3 |
| 88 | + with: |
| 89 | + name: fpga-runtime-for-opencl-${{ github.sha }}-coverity-${{ github.run_id }} |
| 90 | + path: cov-errors-base.txt |
| 91 | + if-no-files-found: error |
| 92 | + - name: Verify no new Coverity Issues |
| 93 | + run: | |
| 94 | + set +e |
| 95 | + # Diffing the coverity issues exist in the current repo, and the coverity issues exist in the current repo + current PR |
| 96 | + diff cov-errors-base.txt cov-errors.txt | grep -E "^>|<" > diff.txt |
| 97 | + set -e |
| 98 | + export countLeft=$(grep -c '^<' diff.txt) |
| 99 | + if [ $countLeft -gt 0 ]; then |
| 100 | + echo "I can not determine if there is a new Coverity issue introduced by this PR" |
| 101 | + echo "This might be because you are modifying a file that has coverity issues" |
| 102 | + echo "Please check cov-errors.txt and cov-errors-base.txt manually to see if there are new coverity issues" |
| 103 | + echo "After checking manually, please add a <coverity-override> tag on this PR to disable this check for this PR" |
| 104 | + cat cov-errors.txt |
| 105 | + exit 1 |
| 106 | + fi |
| 107 | + export count=$(grep -c '^> $' diff.txt) |
| 108 | + if [ $count -gt 0 ]; then |
| 109 | + echo "There are $(( $count / 2 )) new coverity issues introduced by this PR" |
| 110 | + echo "You should fix these issues before mergin them in" |
| 111 | + cat cov-errors.txt |
| 112 | + exit 1 |
| 113 | + fi |
0 commit comments