From f96f820d011919587f87b2bdf761fa3553050e82 Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 21 Dec 2023 00:25:41 +0700 Subject: [PATCH 1/8] feat: CI - Add codeql analysis workflow --- .github/workflows/codeql-analysis.yml | 116 ++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 000000000..456a70139 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,116 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: + - main + tags: ["v[0-9]+.[0-9]+.[0-9]+"] + paths: + [ + ".github/scripts/**", + ".github/workflows/build.yml", + "**/CMakeLists.txt", + "**/Makefile", + "**/*.h", + "**/*.hpp", + "**/*.c", + "**/*.cpp", + "**/*.cu", + "**/*.cc", + "**/*.cxx", + "llama.cpp", + "!docs/**", + "!.gitignore", + "!README.md", + ] + pull_request: + types: [opened, synchronize, reopened] + paths: + [ + ".github/scripts/**", + ".github/workflows/build.yml", + "**/CMakeLists.txt", + "**/Makefile", + "**/*.h", + "**/*.hpp", + "**/*.c", + "**/*.cpp", + "**/*.cu", + "**/*.cc", + "**/*.cxx", + "llama.cpp", + "!docs/**", + "!.gitignore", + "!README.md", + ] + +jobs: + analyze: + name: Analyze + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners + # Consider using larger runners for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ["c-cpp"] + # CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ] + # Use only 'java-kotlin' to analyze code written in Java, Kotlin or both + # Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + 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. + + # 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 + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" From 3715ae7ebd6a74f552ee1c9c8cf47336f27642f9 Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 21 Dec 2023 00:25:53 +0700 Subject: [PATCH 2/8] chore: reformat code --- controllers/health.h | 15 ++++++++------- controllers/processManager.cc | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/controllers/health.h b/controllers/health.h index c45d92b8e..9d4a71689 100644 --- a/controllers/health.h +++ b/controllers/health.h @@ -5,11 +5,12 @@ using namespace drogon; -class health : public drogon::HttpSimpleController -{ - public: - void asyncHandleHttpRequest(const HttpRequestPtr& req, std::function &&callback) override; - PATH_LIST_BEGIN - PATH_ADD("/healthz", Get); - PATH_LIST_END +class health : public drogon::HttpSimpleController { +public: + void asyncHandleHttpRequest( + const HttpRequestPtr &req, + std::function &&callback) override; + PATH_LIST_BEGIN + PATH_ADD("/healthz", Get); + PATH_LIST_END }; diff --git a/controllers/processManager.cc b/controllers/processManager.cc index 13849ac93..2874a3860 100644 --- a/controllers/processManager.cc +++ b/controllers/processManager.cc @@ -2,10 +2,10 @@ #include #include -void processManager::destroy(const HttpRequestPtr &req, - std::function &&callback) { +void processManager::destroy( + const HttpRequestPtr &req, + std::function &&callback) { LOG_INFO << "Program is exitting, goodbye!"; exit(0); return; }; -// Add definition of your processing function here From 616a03e2086a387fd6d4abf253ad38251b1c0c69 Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 21 Dec 2023 00:26:15 +0700 Subject: [PATCH 3/8] chore: Delete autobump workflow --- .github/workflows/auto-bump-llamacpp.yml | 39 ------------------------ 1 file changed, 39 deletions(-) delete mode 100644 .github/workflows/auto-bump-llamacpp.yml diff --git a/.github/workflows/auto-bump-llamacpp.yml b/.github/workflows/auto-bump-llamacpp.yml deleted file mode 100644 index f16185620..000000000 --- a/.github/workflows/auto-bump-llamacpp.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Auto Bump llama.cpp -on: - schedule: - - cron: '0 2 * * *' - workflow_dispatch: - -jobs: - auto-bump: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Check changes llama.cpp master HEAD and push update if any - id: git-status - run: | - cd llama.cpp/ - git fetch origin - git checkout master - git reset --hard origin/master - cd ../ - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 - with: - token: ${{ secrets.GITHUB_TOKEN }} - commit-message: Update llama.cpp - title: "chore: Auto bump llama.cpp version" - branch: bump-llamacpp - branch-suffix: timestamp - labels: "type: chore" - reviewers: tikikun - assignees: vuonghoainam - delete-branch: true - add-paths : "llama.cpp" - base: main - From 31477972623b39e933550a6eaa6a1ed398a4f445 Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 21 Dec 2023 00:30:15 +0700 Subject: [PATCH 4/8] fix: fix syntax error for codeql analysis --- .github/workflows/codeql-analysis.yml | 84 +++++++++++++-------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 456a70139..52539cf9c 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -12,48 +12,48 @@ name: "CodeQL" on: - push: - branches: - - main - tags: ["v[0-9]+.[0-9]+.[0-9]+"] - paths: - [ - ".github/scripts/**", - ".github/workflows/build.yml", - "**/CMakeLists.txt", - "**/Makefile", - "**/*.h", - "**/*.hpp", - "**/*.c", - "**/*.cpp", - "**/*.cu", - "**/*.cc", - "**/*.cxx", - "llama.cpp", - "!docs/**", - "!.gitignore", - "!README.md", - ] - pull_request: - types: [opened, synchronize, reopened] - paths: - [ - ".github/scripts/**", - ".github/workflows/build.yml", - "**/CMakeLists.txt", - "**/Makefile", - "**/*.h", - "**/*.hpp", - "**/*.c", - "**/*.cpp", - "**/*.cu", - "**/*.cc", - "**/*.cxx", - "llama.cpp", - "!docs/**", - "!.gitignore", - "!README.md", - ] + push: + branches: + - main + tags: ["v[0-9]+.[0-9]+.[0-9]+"] + paths: + [ + ".github/scripts/**", + ".github/workflows/build.yml", + "**/CMakeLists.txt", + "**/Makefile", + "**/*.h", + "**/*.hpp", + "**/*.c", + "**/*.cpp", + "**/*.cu", + "**/*.cc", + "**/*.cxx", + "llama.cpp", + "!docs/**", + "!.gitignore", + "!README.md", + ] + pull_request: + types: [opened, synchronize, reopened] + paths: + [ + ".github/scripts/**", + ".github/workflows/build.yml", + "**/CMakeLists.txt", + "**/Makefile", + "**/*.h", + "**/*.hpp", + "**/*.c", + "**/*.cpp", + "**/*.cu", + "**/*.cc", + "**/*.cxx", + "llama.cpp", + "!docs/**", + "!.gitignore", + "!README.md", + ] jobs: analyze: From c70b4ba2a28df1280aac07a32fc27979e03ddf09 Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 21 Dec 2023 00:30:38 +0700 Subject: [PATCH 5/8] chore: refactor processManager.h to delete commented lines --- controllers/processManager.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/controllers/processManager.h b/controllers/processManager.h index dcc4b47f6..7abfbe2d4 100644 --- a/controllers/processManager.h +++ b/controllers/processManager.h @@ -8,16 +8,12 @@ using namespace drogon; class processManager : public drogon::HttpController { public: METHOD_LIST_BEGIN - // use METHOD_ADD to add your custom processing function here; - // METHOD_ADD(processManager::get, "/{2}/{1}", Get); // path is - // /processManager/{arg2}/{arg1} + METHOD_ADD(processManager::destroy, "/destroy", Delete); // path is /processManager/{arg1}/{arg2}/list METHOD_LIST_END - // your declaration of processing function maybe like this: + void destroy(const HttpRequestPtr &req, std::function &&callback); - // void your_method_name(const HttpRequestPtr& req, std::function &&callback, double p1, int p2) const; }; From 2756cef649a2a80b2441ce88d18527f237d36465 Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 21 Dec 2023 00:34:04 +0700 Subject: [PATCH 6/8] fix: CI - Add command to build and clone recursive --- .github/workflows/codeql-analysis.yml | 11 ++++++++--- controllers/llamaCPP.cc | 1 - 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 52539cf9c..0eab7432e 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -82,6 +82,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + submodules: recursive # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL @@ -106,9 +108,12 @@ jobs: # If the Autobuild fails above, remove it and uncomment the following three lines. # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh + - run: | + ./install_deps.sh + mkdir build && cd build + cmake .. + CC=gcc-8 make -j $(sysctl -n hw.ncp) + ls -la - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 diff --git a/controllers/llamaCPP.cc b/controllers/llamaCPP.cc index 849940d01..d30fd93b5 100644 --- a/controllers/llamaCPP.cc +++ b/controllers/llamaCPP.cc @@ -13,7 +13,6 @@ using namespace inferences; using json = nlohmann::json; -// To store state of each inference request struct State { bool isStopped = false; int task_id; From 8f392c69ddf7ae5dd528e418f8d09a6d51729779 Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 21 Dec 2023 00:37:50 +0700 Subject: [PATCH 7/8] chore: CI - Add paths change to trigger github ci --- .github/workflows/codeql-analysis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 0eab7432e..0ecca0610 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -20,6 +20,7 @@ on: [ ".github/scripts/**", ".github/workflows/build.yml", + ".github/workflows/codeql-analysis.yml", "**/CMakeLists.txt", "**/Makefile", "**/*.h", @@ -40,6 +41,7 @@ on: [ ".github/scripts/**", ".github/workflows/build.yml", + ".github/workflows/codeql-analysis.yml", "**/CMakeLists.txt", "**/Makefile", "**/*.h", From 515558426aa1ff4150cc72fc861106e782830a9f Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 21 Dec 2023 00:40:53 +0700 Subject: [PATCH 8/8] fix: Update autobuild step --- .github/workflows/codeql-analysis.yml | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 0ecca0610..a6c29964f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -87,30 +87,13 @@ jobs: with: submodules: recursive - # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v3 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. - # 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 - - # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). - # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v3 - - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - - - run: | + run: | ./install_deps.sh mkdir build && cd build cmake ..