2023-08-12 14:52:16 -04:00
---
# This action is centrally managed in https://github.com/<organization>/.github/
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in
# the above-mentioned repo.
# This workflow will analyze all supported languages in the repository using CodeQL Analysis.
name : "CodeQL"
on :
push :
branches : [ "master" , "nightly" ]
pull_request :
branches : [ "master" , "nightly" ]
schedule :
- cron : '00 12 * * 0' # every Sunday at 12:00 UTC
2023-09-05 18:46:45 -04:00
concurrency :
2024-04-16 17:41:56 -04:00
group : "${{ github.workflow }}-${{ github.ref }}"
2023-09-05 18:46:45 -04:00
cancel-in-progress : true
2023-08-12 14:52:16 -04:00
jobs :
languages :
name : Get language matrix
runs-on : ubuntu-latest
outputs :
matrix : ${{ steps.lang.outputs.result }}
continue : ${{ steps.continue.outputs.result }}
steps :
- name : Get repo languages
2023-11-23 23:28:07 -05:00
uses : actions/github-script@v7
2023-08-12 14:52:16 -04:00
id : lang
with :
script : |
// CodeQL supports ['cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift']
// Use only 'java' to analyze code written in Java, Kotlin or both
// Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
// Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
const supported_languages = ['cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift']
const remap_languages = {
2023-08-12 15:53:45 -04:00
'c++' : 'cpp' ,
'c#' : 'csharp' ,
2023-08-12 14:52:16 -04:00
'kotlin' : 'java' ,
'typescript' : 'javascript' ,
}
const repo = context.repo
const response = await github.rest.repos.listLanguages(repo)
let matrix = {
"include": [ ]
}
2023-08-12 15:53:45 -04:00
for (let [key, value] of Object.entries(response.data)) {
2023-08-12 14:52:16 -04:00
// remap language
if (remap_languages[key.toLowerCase()]) {
console.log(`Remapping language : ${key} to ${remap_languages[key.toLowerCase()]}`)
key = remap_languages[key.toLowerCase()]
}
2024-04-16 17:41:56 -04:00
if (supported_languages.includes(key.toLowerCase())) {
2023-08-12 14:52:16 -04:00
console.log(`Found supported language : ${key}`)
2024-04-16 17:41:56 -04:00
let osList = ['ubuntu-latest'];
if (key.toLowerCase() === 'swift') {
osList = ['macos-latest'];
} else if (key.toLowerCase() === 'cpp') {
osList = ['macos-latest', 'ubuntu-latest', 'windows-latest'];
}
for (let os of osList) {
// set name for matrix
if (osList.length == 1) {
name = key.toLowerCase()
} else {
name = `${key.toLowerCase()}, ${os}`
}
// add to matrix
matrix['include'].push({"language": key.toLowerCase(), "os": os, "name": name})
}
2023-08-12 14:52:16 -04:00
}
}
// print languages
console.log(`matrix : ${JSON.stringify(matrix)}`)
return matrix
- name : Continue
2023-11-23 23:28:07 -05:00
uses : actions/github-script@v7
2023-08-12 14:52:16 -04:00
id : continue
with :
script : |
// if matrix['include'] is an empty list return false, otherwise true
const matrix = ${{ steps.lang.outputs.result }} // this is already json encoded
if (matrix['include'].length == 0) {
return false
} else {
return true
}
analyze :
2024-04-16 17:41:56 -04:00
name : Analyze (${{ matrix.name }})
2023-08-12 14:52:16 -04:00
if : ${{ needs.languages.outputs.continue == 'true' }}
2024-04-16 17:41:56 -04:00
defaults :
run :
shell : ${{ matrix.os == 'windows-latest' && 'msys2 {0}' || 'bash' }}
env :
GITHUB_CODEQL_BUILD : true
2023-08-12 14:52:16 -04:00
needs : [ languages]
2024-04-16 17:41:56 -04:00
runs-on : ${{ matrix.os || 'ubuntu-latest' }}
2023-08-12 14:52:16 -04:00
timeout-minutes : ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions :
actions : read
contents : read
security-events : write
strategy :
fail-fast : false
matrix : ${{ fromJson(needs.languages.outputs.matrix) }}
steps :
2023-10-07 11:28:42 -04:00
- name : Maximize build space
2024-04-16 17:41:56 -04:00
if : runner.os == 'Linux'
2023-10-07 11:28:42 -04:00
uses : easimon/maximize-build-space@v8
with :
root-reserve-mb : 20480
2023-10-12 12:22:23 -04:00
remove-dotnet : ${{ (matrix.language == 'csharp' && 'false') || 'true' }}
2023-10-07 11:28:42 -04:00
remove-android : 'true'
remove-haskell : 'true'
remove-codeql : 'false'
remove-docker-images : 'true'
2023-08-12 14:52:16 -04:00
- name : Checkout repository
2023-09-05 18:46:45 -04:00
uses : actions/checkout@v4
2023-08-12 15:53:45 -04:00
with :
submodules : recursive
2023-08-12 14:52:16 -04:00
2024-04-16 17:41:56 -04:00
- name : Setup msys2
if : runner.os == 'Windows'
uses : msys2/setup-msys2@v2
with :
update : true
2023-08-12 14:52:16 -04:00
# Initializes the CodeQL tools for scanning.
- name : Initialize CodeQL
2023-12-19 16:41:03 -05:00
uses : github/codeql-action/init@v3
2023-08-12 14:52:16 -04:00
with :
languages : ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# yamllint disable-line rule:line-length
# 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
# queries: security-extended,security-and-quality
2023-08-12 15:53:45 -04:00
# Pre autobuild
# create a file named .codeql-prebuild-${{ matrix.language }}.sh in the root of your repository
2024-04-16 17:41:56 -04:00
# create a file named .codeql-build-${{ matrix.language }}.sh in the root of your repository
2023-08-12 15:53:45 -04:00
- name : Prebuild
2024-04-16 17:41:56 -04:00
id : prebuild
2023-08-12 15:53:45 -04:00
run : |
2024-04-16 17:41:56 -04:00
# check if prebuild script exists
filename=".codeql-prebuild-${{ matrix.language }}-${{ runner.os }}.sh"
if [ -f "./${filename}" ]; then
echo "Running prebuild script: ${filename}"
./${filename}
2023-08-12 15:53:45 -04:00
fi
2023-08-12 14:52:16 -04:00
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
- name : Autobuild
2024-04-16 17:41:56 -04:00
if : steps.prebuild.outputs.skip_autobuild != 'true'
2023-12-19 16:41:03 -05:00
uses : github/codeql-action/autobuild@v3
2023-08-12 14:52:16 -04:00
- name : Perform CodeQL Analysis
2023-12-19 16:41:03 -05:00
uses : github/codeql-action/analyze@v3
2023-08-12 14:52:16 -04:00
with :
category : "/language:${{matrix.language}}"