Home | History | Annotate | Line # | Download | only in workflows
      1 name: 'Static Analysis'
      2 on: [pull_request]
      3 jobs:
      4   static-analysis:
      5     runs-on: ubuntu-latest
      6     steps:
      7       # We build libunwind ourselves because sadly the version
      8       # provided by Ubuntu via apt-get is much too old.
      9       - name: Check out libunwind
     10         uses: actions/checkout@v4
     11         with:
     12           repository: libunwind/libunwind
     13           path: libunwind
     14           ref: 'v1.6.2'
     15           github-server-url: 'https://github.com'
     16       - name: Install libunwind
     17         run: |
     18           cd libunwind
     19           autoreconf -i
     20           ./configure --prefix=/usr
     21           make -s -j $(nproc) V=0
     22           sudo make -s install V=0
     23           cd ..
     24           rm -rf libunwind
     25       - name: Check out repository
     26         uses: actions/checkout@v4
     27       # We download LLVM directly from the latest stable release
     28       # on GitHub, because this tends to be much newer than the
     29       # version available via apt-get in Ubuntu.
     30       - name: Download LLVM
     31         uses: dsaltares/fetch-gh-release-asset@master
     32         with:
     33           repo: 'llvm/llvm-project'
     34           version: 'tags/llvmorg-16.0.4'
     35           file: 'clang[+]llvm-.*x86_64-linux-gnu.*'
     36           regex: true
     37           target: 'llvm_assets/'
     38           token: ${{ secrets.GITHUB_TOKEN }}
     39       - name: Install prerequisites
     40         id: install_prerequisites
     41         run: |
     42           tar -C llvm_assets -xaf llvm_assets/*.tar* &
     43           sudo apt-get update
     44           sudo apt-get install -y jq bear python3-pip
     45           pip install codechecker
     46           echo "Extracting LLVM from tar" 1>&2
     47           wait
     48           echo "LLVM_BIN_DIR=$(echo llvm_assets/clang*/bin)" >> "$GITHUB_OUTPUT"
     49       - name: Run static analysis
     50         id: run_static_analysis
     51         run: >
     52           PATH="${{ steps.install_prerequisites.outputs.LLVM_BIN_DIR }}:$PATH"
     53           LDFLAGS='-L/usr/lib'
     54           scripts/run_static_analysis.sh static_analysis_results "$GITHUB_OUTPUT"
     55       - name: Upload static analysis results
     56         if: ${{ steps.run_static_analysis.outputs.HAS_STATIC_ANALYSIS_RESULTS }} == '1'
     57         uses: actions/upload-artifact@v4
     58         with:
     59           name: static_analysis_results
     60           path: static_analysis_results
     61       - name: Check static analysis results
     62         run: |
     63           if [[ "${{ steps.run_static_analysis.outputs.HAS_STATIC_ANALYSIS_RESULTS }}" == '1' ]]
     64           then
     65               echo "::error::Static analysis found issues with your code. Download the 'static_analysis_results' artifact from this workflow and view the 'index.html' file contained within it in a web browser locally for detailed results."
     66               exit 1
     67           fi
     68 
     69