From 4e1761a049a886fb663a78c3c39e62fe3beebd02 Mon Sep 17 00:00:00 2001 From: Sabrina Yan <9669990+violetbrina@users.noreply.github.com> Date: Sat, 14 Sep 2024 15:36:27 +1000 Subject: [PATCH 1/6] Add sonarqube to test workflow --- .github/workflows/lint.yaml | 28 -------------- .github/workflows/test.yaml | 77 +++++++++++++++++++++++++++++++++++++ sonar-project.properties | 4 ++ 3 files changed, 81 insertions(+), 28 deletions(-) delete mode 100644 .github/workflows/lint.yaml create mode 100644 .github/workflows/test.yaml create mode 100644 sonar-project.properties diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml deleted file mode 100644 index 0b97c30f..00000000 --- a/.github/workflows/lint.yaml +++ /dev/null @@ -1,28 +0,0 @@ -name: Lint -on: [push] - -jobs: - lint: - runs-on: ubuntu-latest - defaults: - run: - shell: bash -l {0} - - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-python@v5 - with: - python-version: '3.10' - cache: 'pip' - - - name: Install packages - run: | - pip install . - pip install -r requirements-dev.txt - - - name: pre-commit - run: pre-commit run --all-files - - - name: Run-tests - run: python -m unittest test/test_analysis_runner.py diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000..177cd2b3 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,77 @@ +name: Test +on: [push] + +jobs: + test: + runs-on: ubuntu-latest + defaults: + run: + shell: bash -l {0} + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: '3.10' + cache: 'pip' + + - name: Install packages + run: | + pip install . + pip install -r requirements-dev.txt + + - name: pre-commit + run: pre-commit run --all-files + + - name: 'Run unit tests' + id: runtests + run: | + coverage run -m pytest test/ --junitxml=test-execution.xml + rc=$? + coverage xml + + echo "rc=$rc" >> $GITHUB_OUTPUT + + - name: 'Save coverage report as an Artifact' + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: ./coverage.xml + + - name: 'Save execution report as an Artifact' + uses: actions/upload-artifact@v4 + with: + name: execution-report + path: ./test-execution.xml + + sonarqube: + name: SonarQube scan + runs-on: ubuntu-latest + needs: unittests + environment: production + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + # Download the coverage report artifact + - name: 'Download coverage and execution report' + uses: actions/download-artifact@v4 + with: + pattern: '*-report' + + # Perform the SonarQube scan + - uses: sonarsource/sonarqube-scan-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + + # Optional: Fail the job if Quality Gate is red + # If you wish to fail your job when the Quality Gate is red, uncomment the + # following lines. This would typically be used to fail a deployment. + # - uses: sonarsource/sonarqube-quality-gate-action@master + # timeout-minutes: 5 + # env: + # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..ac1155b6 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,4 @@ +sonar.projectKey=populationgenomics_metamist_AZHVO0XpdaNSak8FrtKn +sonar.python.version=3.11 +sonar.python.coverage.reportPaths=coverage.xml +sonar.python.xunit.reportPath=test-execution.xml From c4278f471704f81df2cadb3c09ee18eb803350f1 Mon Sep 17 00:00:00 2001 From: Sabrina Yan <9669990+violetbrina@users.noreply.github.com> Date: Sat, 14 Sep 2024 15:37:49 +1000 Subject: [PATCH 2/6] Fix depends on --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 177cd2b3..88c59871 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -48,7 +48,7 @@ jobs: sonarqube: name: SonarQube scan runs-on: ubuntu-latest - needs: unittests + needs: test environment: production if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' steps: From 6cffe9da4f2f3e6c75d80e8082be5546a30d2917 Mon Sep 17 00:00:00 2001 From: Sabrina Yan <9669990+violetbrina@users.noreply.github.com> Date: Sat, 14 Sep 2024 15:38:20 +1000 Subject: [PATCH 3/6] Add name --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 88c59871..bb2c949e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -3,6 +3,7 @@ on: [push] jobs: test: + name: Test runs-on: ubuntu-latest defaults: run: From 796f71e2dd338ef4fc7ea3071b2b1887cb95eb42 Mon Sep 17 00:00:00 2001 From: Sabrina Yan <9669990+violetbrina@users.noreply.github.com> Date: Sat, 14 Sep 2024 16:10:01 +1000 Subject: [PATCH 4/6] Update requirements --- .github/workflows/test.yaml | 2 +- requirements-dev.txt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index bb2c949e..b9e7e042 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -14,7 +14,7 @@ jobs: - uses: actions/setup-python@v5 with: - python-version: '3.10' + python-version: '3.11' cache: 'pip' - name: Install packages diff --git a/requirements-dev.txt b/requirements-dev.txt index a93858e0..82cf647f 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,7 +1,9 @@ black bump2version cloudpathlib[all] +coverage cpg-utils>=4.12.1 pre-commit pylint +pytest toml From 943051b86a9f712390597b43cbfabe491595aab7 Mon Sep 17 00:00:00 2001 From: Sabrina Yan <9669990+violetbrina@users.noreply.github.com> Date: Sat, 14 Sep 2024 16:41:12 +1000 Subject: [PATCH 5/6] Update sonarqube project key --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index ac1155b6..7420f446 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,4 +1,4 @@ -sonar.projectKey=populationgenomics_metamist_AZHVO0XpdaNSak8FrtKn +sonar.projectKey=populationgenomics_analysis-runner_AZHvNgzldaNSak8FrtNV sonar.python.version=3.11 sonar.python.coverage.reportPaths=coverage.xml sonar.python.xunit.reportPath=test-execution.xml From 3a580cb8b01ffb6b96cb1da53b35182203f8ca5c Mon Sep 17 00:00:00 2001 From: Sabrina Yan <9669990+violetbrina@users.noreply.github.com> Date: Sat, 14 Sep 2024 17:15:51 +1000 Subject: [PATCH 6/6] Update sonarqube project key to simplified --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 7420f446..ef0e3e73 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,4 +1,4 @@ -sonar.projectKey=populationgenomics_analysis-runner_AZHvNgzldaNSak8FrtNV +sonar.projectKey=populationgenomics_analysis-runner sonar.python.version=3.11 sonar.python.coverage.reportPaths=coverage.xml sonar.python.xunit.reportPath=test-execution.xml