Skip to content

Commit

Permalink
CodeQL setup (#36)
Browse files Browse the repository at this point in the history
In nob, add conditional run with sanitizers used by CodeQL workflow.
https://github.com/iglesias/coding-challenges/actions/runs/12557297977/job/35009713999#step:4:943
  • Loading branch information
iglesias authored Dec 31, 2024
1 parent 86d9265 commit 1485056
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
analyze:
name: Analyze (${{ matrix.language }})
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
include:
- language: c-cpp
build-mode: manual
- language: python
build-mode: none

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# 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.
# 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

- if: matrix.build-mode == 'manual'
shell: bash
run: |
sudo apt-get install libboost-all-dev libgtest-dev
g++ -std=c++20 -DBUILD_ONLY -o nob nob.cpp
./nob
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
4 changes: 4 additions & 0 deletions nob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ void build_and_run_gtest_file(std::string_view filename)
{
Cstr path = PATH(filename.data());
CMD("g++", CPPFLAGS, "-o", NOEXT(path), path, "-lgtest");
#ifndef BUILD_ONLY // github.com/iglesias/coding-challenges/actions/runs/12532941559/job/34952138092#step:4:943
CMD(NOEXT(path));
#endif
}

Pid build_gtest_file_async(std::string_view path)
Expand Down Expand Up @@ -113,6 +115,7 @@ void work_out_leetcode()

for (const Pid& pid : pids) pid_wait(pid);

#ifndef BUILD_ONLY // github.com/iglesias/coding-challenges/actions/runs/12532941559/job/34952138092#step:4:943
pids.clear();

for (const auto& entry : fs::directory_iterator("leetcode")) if (fs::is_regular_file(entry.path())) {
Expand All @@ -121,6 +124,7 @@ void work_out_leetcode()
if (filename.ends_with(".cpp")) pids.push_back(run_gtest_file_async("leetcode/" + filename)); }

for (const Pid& pid : pids) pid_wait(pid);
#endif
}

void build_codeforces_cpp_files() {
Expand Down

0 comments on commit 1485056

Please sign in to comment.