|
| 1 | +--- |
| 2 | +# This action is centrally managed in https://github.com/<organization>/.github/ |
| 3 | +# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in |
| 4 | +# the above-mentioned repo. |
| 5 | + |
| 6 | +# This workflow will analyze all supported languages in the repository using CodeQL Analysis. |
| 7 | + |
| 8 | +name: "CodeQL" |
| 9 | + |
| 10 | +on: |
| 11 | + push: |
| 12 | + branches: ["master", "nightly"] |
| 13 | + pull_request: |
| 14 | + branches: ["master", "nightly"] |
| 15 | + schedule: |
| 16 | + - cron: '00 12 * * 0' # every Sunday at 12:00 UTC |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + languages: |
| 24 | + name: Get language matrix |
| 25 | + runs-on: ubuntu-latest |
| 26 | + outputs: |
| 27 | + matrix: ${{ steps.lang.outputs.result }} |
| 28 | + continue: ${{ steps.continue.outputs.result }} |
| 29 | + steps: |
| 30 | + - name: Get repo languages |
| 31 | + uses: actions/github-script@v7 |
| 32 | + id: lang |
| 33 | + with: |
| 34 | + script: | |
| 35 | + // CodeQL supports ['cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift'] |
| 36 | + // Use only 'java' to analyze code written in Java, Kotlin or both |
| 37 | + // Use only 'javascript' to analyze code written in JavaScript, TypeScript or both |
| 38 | + // Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support |
| 39 | + const supported_languages = ['cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift'] |
| 40 | +
|
| 41 | + const remap_languages = { |
| 42 | + 'c++': 'cpp', |
| 43 | + 'c#': 'csharp', |
| 44 | + 'kotlin': 'java', |
| 45 | + 'typescript': 'javascript', |
| 46 | + } |
| 47 | +
|
| 48 | + const repo = context.repo |
| 49 | + const response = await github.rest.repos.listLanguages(repo) |
| 50 | + let matrix = { |
| 51 | + "include": [] |
| 52 | + } |
| 53 | +
|
| 54 | + for (let [key, value] of Object.entries(response.data)) { |
| 55 | + // remap language |
| 56 | + if (remap_languages[key.toLowerCase()]) { |
| 57 | + console.log(`Remapping language: ${key} to ${remap_languages[key.toLowerCase()]}`) |
| 58 | + key = remap_languages[key.toLowerCase()] |
| 59 | + } |
| 60 | + if (supported_languages.includes(key.toLowerCase()) && |
| 61 | + !matrix['include'].includes({"language": key.toLowerCase()})) { |
| 62 | + console.log(`Found supported language: ${key}`) |
| 63 | + matrix['include'].push({"language": key.toLowerCase()}) |
| 64 | + } |
| 65 | + } |
| 66 | +
|
| 67 | + // print languages |
| 68 | + console.log(`matrix: ${JSON.stringify(matrix)}`) |
| 69 | +
|
| 70 | + return matrix |
| 71 | +
|
| 72 | + - name: Continue |
| 73 | + uses: actions/github-script@v7 |
| 74 | + id: continue |
| 75 | + with: |
| 76 | + script: | |
| 77 | + // if matrix['include'] is an empty list return false, otherwise true |
| 78 | + const matrix = ${{ steps.lang.outputs.result }} // this is already json encoded |
| 79 | +
|
| 80 | + if (matrix['include'].length == 0) { |
| 81 | + return false |
| 82 | + } else { |
| 83 | + return true |
| 84 | + } |
| 85 | +
|
| 86 | + analyze: |
| 87 | + name: Analyze |
| 88 | + if: ${{ needs.languages.outputs.continue == 'true' }} |
| 89 | + needs: [languages] |
| 90 | + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} |
| 91 | + timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} |
| 92 | + permissions: |
| 93 | + actions: read |
| 94 | + contents: read |
| 95 | + security-events: write |
| 96 | + |
| 97 | + strategy: |
| 98 | + fail-fast: false |
| 99 | + matrix: ${{ fromJson(needs.languages.outputs.matrix) }} |
| 100 | + |
| 101 | + steps: |
| 102 | + - name: Maximize build space |
| 103 | + uses: easimon/maximize-build-space@v8 |
| 104 | + with: |
| 105 | + root-reserve-mb: 20480 |
| 106 | + remove-dotnet: ${{ (matrix.language == 'csharp' && 'false') || 'true' }} |
| 107 | + remove-android: 'true' |
| 108 | + remove-haskell: 'true' |
| 109 | + remove-codeql: 'false' |
| 110 | + remove-docker-images: 'true' |
| 111 | + |
| 112 | + - name: Checkout repository |
| 113 | + uses: actions/checkout@v4 |
| 114 | + with: |
| 115 | + submodules: recursive |
| 116 | + |
| 117 | + # Initializes the CodeQL tools for scanning. |
| 118 | + - name: Initialize CodeQL |
| 119 | + uses: github/codeql-action/init@v3 |
| 120 | + with: |
| 121 | + languages: ${{ matrix.language }} |
| 122 | + # If you wish to specify custom queries, you can do so here or in a config file. |
| 123 | + # By default, queries listed here will override any specified in a config file. |
| 124 | + # Prefix the list here with "+" to use these queries and those in the config file. |
| 125 | + |
| 126 | + # yamllint disable-line rule:line-length |
| 127 | + # 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 |
| 128 | + # queries: security-extended,security-and-quality |
| 129 | + |
| 130 | + # Pre autobuild |
| 131 | + # create a file named .codeql-prebuild-${{ matrix.language }}.sh in the root of your repository |
| 132 | + - name: Prebuild |
| 133 | + run: | |
| 134 | + # check if .qodeql-prebuild-${{ matrix.language }}.sh exists |
| 135 | + if [ -f "./.codeql-prebuild-${{ matrix.language }}.sh" ]; then |
| 136 | + echo "Running .codeql-prebuild-${{ matrix.language }}.sh" |
| 137 | + ./.codeql-prebuild-${{ matrix.language }}.sh |
| 138 | + fi |
| 139 | +
|
| 140 | + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). |
| 141 | + - name: Autobuild |
| 142 | + uses: github/codeql-action/autobuild@v3 |
| 143 | + |
| 144 | + - name: Perform CodeQL Analysis |
| 145 | + uses: github/codeql-action/analyze@v3 |
| 146 | + with: |
| 147 | + category: "/language:${{matrix.language}}" |
0 commit comments