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..b9e7e042 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,78 @@ +name: Test +on: [push] + +jobs: + test: + name: 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.11' + 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: test + 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/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 diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..ef0e3e73 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,4 @@ +sonar.projectKey=populationgenomics_analysis-runner +sonar.python.version=3.11 +sonar.python.coverage.reportPaths=coverage.xml +sonar.python.xunit.reportPath=test-execution.xml