From bdeed64796d7e2c6d9cf30b5d7d2e2ac2c636b6b Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Thu, 21 Nov 2024 16:42:03 +0000 Subject: [PATCH 1/6] copy from blueapi, still need to configure env values @ --- .github/workflows/codeql.yaml | 93 +++++++++++++++++++++++++++++++ .github/workflows/sonarcloud.yaml | 24 ++++++++ 2 files changed, 117 insertions(+) create mode 100644 .github/workflows/codeql.yaml create mode 100644 .github/workflows/sonarcloud.yaml diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml new file mode 100644 index 0000000000..06863c52fd --- /dev/null +++ b/.github/workflows/codeql.yaml @@ -0,0 +1,93 @@ +# 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"] + pull_request: + branches: ["main"] + schedule: + - cron: "23 10 * * 2" + +jobs: + analyze: + name: Analyze (${{ matrix.language }}) + # 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 (GitHub.com only) + # Consider using larger runners or machines with greater resources for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + 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: python + build-mode: none + # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' + # Use `c-cpp` to analyze code written in C, C++ or both + # Use 'java-kotlin' to analyze code written in Java, Kotlin or both + # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both + # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, + # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. + # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how + # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages + 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 }} + 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 the analyze step fails for one of the languages you are analyzing with + # "We were unable to automatically build your code", modify the matrix above + # to set the build mode to "manual" for that language. Then modify this step + # to build your code. + # ℹī¸ 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: matrix.build-mode == 'manual' + shell: bash + run: | + echo 'If you are using a "manual" build mode for one or more of the' \ + 'languages you are analyzing, replace this with the commands to build' \ + 'your code, for example:' + echo ' make bootstrap' + echo ' make release' + exit 1 + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" + diff --git a/.github/workflows/sonarcloud.yaml b/.github/workflows/sonarcloud.yaml new file mode 100644 index 0000000000..550693bf3d --- /dev/null +++ b/.github/workflows/sonarcloud.yaml @@ -0,0 +1,24 @@ +on: + # Trigger analysis when pushing in main or pull requests, and when creating + # a pull request. + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] +name: SonarCloud check +jobs: + sonarcloud: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + # Disabling shallow clone is recommended for improving relevancy of reporting + fetch-depth: 0 + - name: SonarCloud Scan + uses: sonarsource/sonarcloud-github-action@v3.0.0 # Ex: v2.1.0, See the latest version at https://github.com/marketplace/actions/sonarcloud-scan + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_ORG_KEY: ${{ secrets.SONAR_ORG_KEY }} + + From f61fa9f39a6533346a87cb3d371ab7df2108e6a9 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Mon, 25 Nov 2024 15:47:50 +0000 Subject: [PATCH 2/6] lint --- .github/workflows/codeql.yaml | 1 - .github/workflows/sonarcloud.yaml | 2 -- 2 files changed, 3 deletions(-) diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml index 06863c52fd..32ca7e19d3 100644 --- a/.github/workflows/codeql.yaml +++ b/.github/workflows/codeql.yaml @@ -90,4 +90,3 @@ jobs: uses: github/codeql-action/analyze@v3 with: category: "/language:${{matrix.language}}" - diff --git a/.github/workflows/sonarcloud.yaml b/.github/workflows/sonarcloud.yaml index 550693bf3d..b1790840a3 100644 --- a/.github/workflows/sonarcloud.yaml +++ b/.github/workflows/sonarcloud.yaml @@ -20,5 +20,3 @@ jobs: env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_ORG_KEY: ${{ secrets.SONAR_ORG_KEY }} - - From cfe48a31ca7d9cfebf9daabd93a55b162987347e Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Tue, 26 Nov 2024 11:59:17 +0000 Subject: [PATCH 3/6] add sonar config --- sonar-project.properties | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 sonar-project.properties diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000000..f4d67eee55 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,20 @@ +# This is the name and version displayed in the SonarCloud UI. +sonar.projectKey=swift-testing_blueapi-test +sonar.organization=swift-testing + +sonar.projectName=blueapi-test +sonar.projectVersion=1.0 + + +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +#sonar.sources=. + +# Encoding of the source code. Default is default system encoding +# sonar.sourceEncoding=UTF-8 +# relative paths to source directories. More details and properties are described +# in https://sonarcloud.io/documentation/project-administration/narrowing-the-focus/ +sonar.sources=src + +# python settings +sonar.python.version=3.10 +sonar.python.coverage.reportPaths=coverage.xml From 12578273bf295604eca98b771dc7e0f2d87bba38 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Wed, 11 Dec 2024 10:51:48 +0000 Subject: [PATCH 4/6] address comments --- .../workflows/{codeql.yaml => _codeql.yaml} | 21 +++++++++++------- .github/workflows/periodic.yml | 4 ++++ .github/workflows/sonarcloud.yaml | 22 ------------------- 3 files changed, 17 insertions(+), 30 deletions(-) rename .github/workflows/{codeql.yaml => _codeql.yaml} (93%) delete mode 100644 .github/workflows/sonarcloud.yaml diff --git a/.github/workflows/codeql.yaml b/.github/workflows/_codeql.yaml similarity index 93% rename from .github/workflows/codeql.yaml rename to .github/workflows/_codeql.yaml index 32ca7e19d3..82f187e864 100644 --- a/.github/workflows/codeql.yaml +++ b/.github/workflows/_codeql.yaml @@ -12,12 +12,17 @@ name: "CodeQL" on: - push: - branches: ["main"] - pull_request: - branches: ["main"] - schedule: - - cron: "23 10 * * 2" + workflow_call: + inputs: + codeql: + description: "Specify the trigger type" + required: true + type: string + default: "push" + secrets: + codeql_token: + description: "Token for CodeQL" + required: true jobs: analyze: @@ -27,8 +32,8 @@ jobs: # - https://gh.io/supported-runners-and-hardware-resources # - https://gh.io/using-larger-runners (GitHub.com only) # Consider using larger runners or machines with greater resources for possible analysis time improvements. - runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} - timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + runs-on: "ubuntu-latest" + timeout-minutes: 120 permissions: # required for all workflows security-events: write diff --git a/.github/workflows/periodic.yml b/.github/workflows/periodic.yml index e2a0fd1b9e..7a21dba314 100644 --- a/.github/workflows/periodic.yml +++ b/.github/workflows/periodic.yml @@ -11,3 +11,7 @@ jobs: uses: ./.github/workflows/_tox.yml with: tox: docs build -- -b linkcheck + codeql: + uses: ./.github/workflows/_codeql.yml + with: + codeql: "Check codeql setup" diff --git a/.github/workflows/sonarcloud.yaml b/.github/workflows/sonarcloud.yaml deleted file mode 100644 index b1790840a3..0000000000 --- a/.github/workflows/sonarcloud.yaml +++ /dev/null @@ -1,22 +0,0 @@ -on: - # Trigger analysis when pushing in main or pull requests, and when creating - # a pull request. - push: - branches: - - main - pull_request: - types: [opened, synchronize, reopened] -name: SonarCloud check -jobs: - sonarcloud: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - # Disabling shallow clone is recommended for improving relevancy of reporting - fetch-depth: 0 - - name: SonarCloud Scan - uses: sonarsource/sonarcloud-github-action@v3.0.0 # Ex: v2.1.0, See the latest version at https://github.com/marketplace/actions/sonarcloud-scan - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_ORG_KEY: ${{ secrets.SONAR_ORG_KEY }} From 4d0ba0e99c0b0ed446e5d6bdd01b06417231a79f Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Wed, 11 Dec 2024 10:57:16 +0000 Subject: [PATCH 5/6] deleted sonar properites --- sonar-project.properties | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 sonar-project.properties diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index f4d67eee55..0000000000 --- a/sonar-project.properties +++ /dev/null @@ -1,20 +0,0 @@ -# This is the name and version displayed in the SonarCloud UI. -sonar.projectKey=swift-testing_blueapi-test -sonar.organization=swift-testing - -sonar.projectName=blueapi-test -sonar.projectVersion=1.0 - - -# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. -#sonar.sources=. - -# Encoding of the source code. Default is default system encoding -# sonar.sourceEncoding=UTF-8 -# relative paths to source directories. More details and properties are described -# in https://sonarcloud.io/documentation/project-administration/narrowing-the-focus/ -sonar.sources=src - -# python settings -sonar.python.version=3.10 -sonar.python.coverage.reportPaths=coverage.xml From 428e06d0c01eaa894db6320c41dd961d17bf9db7 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Wed, 11 Dec 2024 11:49:13 +0000 Subject: [PATCH 6/6] simplify codeql yaml logic --- .github/workflows/_codeql.yaml | 44 ---------------------------------- 1 file changed, 44 deletions(-) diff --git a/.github/workflows/_codeql.yaml b/.github/workflows/_codeql.yaml index 82f187e864..4a15ce70ec 100644 --- a/.github/workflows/_codeql.yaml +++ b/.github/workflows/_codeql.yaml @@ -1,14 +1,3 @@ -# 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: @@ -28,10 +17,7 @@ jobs: analyze: name: Analyze (${{ matrix.language }}) # 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 (GitHub.com only) - # Consider using larger runners or machines with greater resources for possible analysis time improvements. runs-on: "ubuntu-latest" timeout-minutes: 120 permissions: @@ -51,14 +37,8 @@ jobs: include: - language: python build-mode: none - # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' - # Use `c-cpp` to analyze code written in C, C++ or both - # Use 'java-kotlin' to analyze code written in Java, Kotlin or both - # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. - # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how - # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages steps: - name: Checkout repository uses: actions/checkout@v4 @@ -69,29 +49,5 @@ jobs: 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 the analyze step fails for one of the languages you are analyzing with - # "We were unable to automatically build your code", modify the matrix above - # to set the build mode to "manual" for that language. Then modify this step - # to build your code. - # ℹī¸ 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: matrix.build-mode == 'manual' - shell: bash - run: | - echo 'If you are using a "manual" build mode for one or more of the' \ - 'languages you are analyzing, replace this with the commands to build' \ - 'your code, for example:' - echo ' make bootstrap' - echo ' make release' - exit 1 - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 - with: - category: "/language:${{matrix.language}}"