| 1 | # For most projects, this workflow file will not need changing; you simply need |
| 2 | # to commit it to your repository. |
| 3 | # |
| 4 | # You may wish to alter this file to override the set of languages analyzed, |
| 5 | # or to provide custom queries or build logic. |
| 6 | name: Analyze raylib with CodeQL |
| 7 | |
| 8 | on: |
| 9 | workflow_dispatch: |
| 10 | # push: |
| 11 | # branches: [ "main", "master" ] |
| 12 | pull_request: |
| 13 | branches: '*' |
| 14 | schedule: |
| 15 | - cron: '0 0 * * 1' |
| 16 | |
| 17 | env: |
| 18 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) |
| 19 | BUILD_TYPE: Release |
| 20 | |
| 21 | jobs: |
| 22 | analyze: |
| 23 | name: Analyze |
| 24 | # Runner size impacts CodeQL analysis time. To learn more, please see: |
| 25 | # - https://gh.io/recommended-hardware-resources-for-running-codeql |
| 26 | # - https://gh.io/supported-runners-and-hardware-resources |
| 27 | # - https://gh.io/using-larger-runners |
| 28 | # Consider using larger runners for possible analysis time improvements. |
| 29 | runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} |
| 30 | timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} |
| 31 | permissions: |
| 32 | actions: read |
| 33 | contents: read |
| 34 | security-events: write |
| 35 | |
| 36 | strategy: |
| 37 | fail-fast: false |
| 38 | matrix: |
| 39 | language: [ 'cpp' ] |
| 40 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] |
| 41 | # Use only 'java' to analyze code written in Java, Kotlin or both |
| 42 | # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both |
| 43 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support |
| 44 | |
| 45 | steps: |
| 46 | - name: Checkout repository |
| 47 | uses: actions/checkout@v4 |
| 48 | with: |
| 49 | submodules: recursive |
| 50 | |
| 51 | - name: Create Build Environment |
| 52 | # Some projects don't allow in-source building, so create a separate build directory |
| 53 | # We'll use this as our working directory for all subsequent commands |
| 54 | run: cmake -E make_directory ${{github.workspace}}/build |
| 55 | |
| 56 | - name: Setup Environment |
| 57 | run: | |
| 58 | sudo apt-get update -qq |
| 59 | sudo apt-get install gcc-multilib |
| 60 | sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev libwayland-dev libxkbcommon-dev |
| 61 | |
| 62 | - name: Configure CMake |
| 63 | # Use a bash shell so we can use the same syntax for environment variable |
| 64 | # access regardless of the host operating system |
| 65 | shell: bash |
| 66 | working-directory: ${{github.workspace}}/build |
| 67 | # Note the current convention is to use the -S and -B options here to specify source |
| 68 | # and build directories, but this is only available with CMake 3.13 and higher. |
| 69 | # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 |
| 70 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DPLATFORM=Desktop |
| 71 | |
| 72 | # Initializes the CodeQL tools for scanning. |
| 73 | - name: Initialize CodeQL |
| 74 | uses: github/codeql-action/init@v3 |
| 75 | with: |
| 76 | languages: ${{ matrix.language }} |
| 77 | # If you wish to specify custom queries, you can do so here or in a config file. |
| 78 | # By default, queries listed here will override any specified in a config file. |
| 79 | # Prefix the list here with "+" to use these queries and those in the config file. |
| 80 | |
| 81 | # 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 |
| 82 | # queries: security-extended,security-and-quality |
| 83 | queries: security-and-quality |
| 84 | |
| 85 | - name: Build |
| 86 | # Execute the build. You can specify a specific target with "--target <NAME>" |
| 87 | run: | |
| 88 | cd build |
| 89 | cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DPLATFORM=Desktop |
| 90 | cmake --build . --config $BUILD_TYPE |
| 91 | |
| 92 | - name: Perform CodeQL Analysis |
| 93 | uses: github/codeql-action/analyze@v3 |
| 94 | with: |
| 95 | category: "/language:${{matrix.language}}" |
| 96 | upload: false |
| 97 | id: step1 |
| 98 | |
| 99 | # Filter out rules with low severity or high false positve rate |
| 100 | # Also filter out warnings in third-party code |
| 101 | - name: Filter out unwanted errors and warnings |
| 102 | uses: advanced-security/filter-sarif@v1 |
| 103 | with: |
| 104 | patterns: | |
| 105 | -**:cpp/path-injection |
| 106 | -**:cpp/world-writable-file-creation |
| 107 | -**:cpp/poorly-documented-function |
| 108 | -**:cpp/potentially-dangerous-function |
| 109 | -**:cpp/use-of-goto |
| 110 | -**:cpp/integer-multiplication-cast-to-long |
| 111 | -**:cpp/comparison-with-wider-type |
| 112 | -**:cpp/leap-year/* |
| 113 | -**:cpp/ambiguously-signed-bit-field |
| 114 | -**:cpp/suspicious-pointer-scaling |
| 115 | -**:cpp/suspicious-pointer-scaling-void |
| 116 | -**:cpp/unsigned-comparison-zero |
| 117 | -**/cmake*/Modules/** |
| 118 | -**/src/external/glfw/** |
| 119 | -**/src/external/** |
| 120 | input: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif |
| 121 | output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif |
| 122 | |
| 123 | - name: Upload CodeQL results to code scanning |
| 124 | uses: github/codeql-action/upload-sarif@v2 |
| 125 | with: |
| 126 | sarif_file: ${{ steps.step1.outputs.sarif-output }} |
| 127 | category: "/language:${{matrix.language}}" |
| 128 | |
| 129 | - name: Upload CodeQL results as an artifact |
| 130 | if: success() || failure() |
| 131 | uses: actions/upload-artifact@v4 |
| 132 | with: |
| 133 | name: codeql-results |
| 134 | path: ${{ steps.step1.outputs.sarif-output }} |
| 135 | retention-days: 5 |