diff --git a/.devcontainer/dev_container.dockerfile b/.devcontainer/dev_container.dockerfile index 741b275..07e7dd0 100644 --- a/.devcontainer/dev_container.dockerfile +++ b/.devcontainer/dev_container.dockerfile @@ -1,5 +1,5 @@ # Base image for the development container -ARG BASE_URL=python:3.11-slim +ARG BASE_URL=python:3.8-slim FROM ${BASE_URL} USER root diff --git a/.github/workflows/github-python-workflow.yml b/.github/workflows/github-python-workflow.yml index b9056a1..9f09f67 100644 --- a/.github/workflows/github-python-workflow.yml +++ b/.github/workflows/github-python-workflow.yml @@ -1,16 +1,15 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - +# This workflow handles linting, testing, and SonarQube scanning for the OGC repository. name: Python Workflow on: push: branches: [main, develop] pull_request: - branches: [main, develop] + types: [opened, synchronize, reopened] jobs: - test: + lint: + name: Lint runs-on: ubuntu-latest steps: @@ -18,21 +17,91 @@ jobs: with: fetch-depth: 0 fetch-tags: true - - name: Set up Python 3.11 + + - name: Set up Python uses: actions/setup-python@v3 with: - python-version: "3.11" + python-version: "3.8" + - name: Install dependencies run: | pip install --upgrade pip setuptools && pip install .[dev] + - name: Run flake8 lint checks run: | # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --output-file=flake8-report.txt # exit-zero treats all errors as warnings - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics --output-file=flake8-report.txt + - name: Run black format checks - run: black --check --diff ogc example || true # For now pass even if files need formatting + run: black --check --diff ogc example > black-report.txt || true # For now pass even if files need formatting + + - name: Artifact flake8 report + uses: actions/upload-artifact@v4 + with: + name: flake8-report + path: flake8-report.txt + retention-days: 1 + + - name: Artifact black report + uses: actions/upload-artifact@v4 + with: + name: black-report + path: black-report.txt + retention-days: 1 + + unit_testing: + name: Unit Testing + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: "3.8" + + - name: Install dependencies + run: | + pip install --upgrade pip setuptools && pip install .[dev] + - name: Run pytest with coverage run: | - pytest -v --cov=ogc + coverage run --data-file=coverage.bin --branch \ + -m pytest --continue-on-collection-errors || \ + { echo "WARNING: Some tests have failed. (Temporarily ignored)"; true; } + coverage xml --data-file=coverage.bin -o coverage.xml + + - name: Artifact coverage document + uses: actions/upload-artifact@v4 + with: + name: coverage + path: coverage.xml + retention-days: 1 + + sonarqube_scan: + name: SonarQube Scan + needs: [unit_testing] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Download coverage artifact + uses: actions/download-artifact@v4 + with: + name: coverage + path: . + + - name: SonarQube Scan + uses: SonarSource/sonarqube-scan-action@fd88b7d7ccbaefd23d8f36f73b59db7a3d246602 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/pyproject.toml b/pyproject.toml index 3411a4d..0b9a391 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,8 +14,7 @@ name = "OGC" dynamic = ["version"] description = "OGC WCS and WMS server" authors = [{ name = "Creare" }] -license = "Apache-2.0" # Creare's preferred license -license-files = ["LICENSE.txt"] +license = { file = "LICENSE" } readme = "README.md" classifiers = [ # How mature is this project? Common values are @@ -50,10 +49,10 @@ dev = [ # TESTING "pytest", "pytest-mock", - "pytest-cov", "pytest-html", "pytest-remotedata", "recommonmark", + "coverage", # FORMATTING "pre_commit", "black", @@ -68,3 +67,8 @@ testpaths = ["ogc"] [tool.black] line-length = 120 + +[tool.coverage.run] +relative_files = true +source = ["ogc/"] +branch = true diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..43c8211 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,6 @@ + +sonar.projectKey=creare-com_ogc +sonar.organization=creare-com +sonar.qualitygate.wait=true +sonar.python.version=3.8 +sonar.python.coverage.reportPaths=coverage.xml \ No newline at end of file