From 2b39482e28a327b2cba5d2884209c92815db354b Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sat, 25 Jun 2022 15:32:00 +0200 Subject: [PATCH] Add check script --- .github/workflows/check.yml | 95 ++++++++++++++++ .github/workflows/check_great_ai.yml | 26 ----- .github/workflows/generic-lint-python.yml | 29 ----- .../workflows/generic-sonarqube-python.yml | 105 ------------------ 4 files changed, 95 insertions(+), 160 deletions(-) create mode 100644 .github/workflows/check.yml delete mode 100644 .github/workflows/check_great_ai.yml delete mode 100644 .github/workflows/generic-lint-python.yml delete mode 100644 .github/workflows/generic-sonarqube-python.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..d216787 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,95 @@ +name: Check library + +on: + workflow_dispatch: + push: + branches: + - main + - dev + +jobs: + test: + name: Build and test on Python ${{ matrix.python-version }} + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ["3.8.12", "3.9.12", "3.10.4"] + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip setuptools pytest pytest-cov pytest-subtests pytest-asyncio + (pip install --editable .) || true + (test -f requirements.txt && pip install -r requirements.txt --upgrade) || true + (test -f dev-requirements.txt && pip install -r dev-requirements.txt --upgrade) || true + + - name: Check code and formatting + run: scripts/check-python.sh . + + - name: Run tests + run: python3 -m pytest --cov=. --cov-report=xml --junit-xml pytest.xml --asyncio-mode=strict || true + + - name: Upload results + if: always() + uses: actions/upload-artifact@v2 + with: + name: Unit test coverage (Python ${{ matrix.python-version }}) + path: *.xml + + sonar: + name: Analyse Python project with SonarQube + needs: test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt --upgrade + + - name: Download test results + uses: actions/download-artifact@v2 + with: + path: artifacts + + - uses: sonarsource/sonarqube-scan-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + with: + args: > + -Dsonar.projectKey=great-ai + -Dsonar.login=${{ secrets.SONAR_TOKEN }} + -Dsonar.verbose=true + -Dsonar.python.coverage.reportPaths=artifacts/*/coverage.xml + -Dsonar.coverage.exclusions=**/external/**/* + -Dsonar.exclusions=**/external/**/*,artifacts/**/* + + publish-test-results: + name: Publish unit test results + needs: test + runs-on: ubuntu-latest + if: always() + steps: + - name: Download artifacts + uses: actions/download-artifact@v2 + with: + path: artifacts + + - name: Publish results + uses: EnricoMi/publish-unit-test-result-action@v1 + with: + files: artifacts/*/pytest.xml diff --git a/.github/workflows/check_great_ai.yml b/.github/workflows/check_great_ai.yml deleted file mode 100644 index b4ca6f1..0000000 --- a/.github/workflows/check_great_ai.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Check library - -on: - workflow_dispatch: - push: - branches: - - main - paths: - - "great_ai/**" - - ".github/workflows/*" - -jobs: - lint: - uses: ./.github/workflows/generic-lint-python.yml - with: - path_to_project: great_ai - - sonar: - needs: lint - uses: ./.github/workflows/generic-sonarqube-python.yml - with: - project_name: great-ai - path_to_project: great_ai - secrets: - sonar_token: ${{ secrets.SONAR_TOKEN }} - sonar_host: ${{ secrets.SONAR_HOST_URL }} diff --git a/.github/workflows/generic-lint-python.yml b/.github/workflows/generic-lint-python.yml deleted file mode 100644 index 14ccfc8..0000000 --- a/.github/workflows/generic-lint-python.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Check linting and formatting of Python project - -on: - workflow_call: - inputs: - path_to_project: - required: true - type: string - -jobs: - lint: - name: Check linting and formatting of Python project - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up Python 3.8 - uses: actions/setup-python@v2 - with: - python-version: 3.8.12 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt --upgrade - working-directory: ${{ inputs.path_to_project }} - - - name: Check code and formatting - run: scripts/check-python.sh ${{ inputs.path_to_project }} diff --git a/.github/workflows/generic-sonarqube-python.yml b/.github/workflows/generic-sonarqube-python.yml deleted file mode 100644 index d2c4635..0000000 --- a/.github/workflows/generic-sonarqube-python.yml +++ /dev/null @@ -1,105 +0,0 @@ -name: Analyse Python project - -on: - workflow_call: - inputs: - project_name: - required: true - type: string - path_to_project: - required: true - type: string - secrets: - sonar_token: - required: true - sonar_host: - required: true - -jobs: - test: - name: Build and test on Python ${{ matrix.python-version }} - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - python-version: ["3.8.12", "3.9.12", "3.10.4"] - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - - name: Install dependencies - run: | - python3 -m pip install --upgrade pip setuptools pytest pytest-cov pytest-subtests pytest-asyncio - cd ${{ inputs.path_to_project }} - (pip install --editable .) || true - (test -f requirements.txt && pip install -r requirements.txt --upgrade) || true - (test -f dev-requirements.txt && pip install -r dev-requirements.txt --upgrade) || true - - - name: Run tests - run: python3 -m pytest --cov=. --cov-report=xml --junit-xml pytest.xml --asyncio-mode=strict || true - working-directory: ${{ inputs.path_to_project }} - - - name: Upload results - if: always() - uses: actions/upload-artifact@v2 - with: - name: Unit test coverage (Python ${{ matrix.python-version }}) - path: ${{ inputs.path_to_project }}/*.xml - - sonar: - name: Analyse Python project with SonarQube - needs: test - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt --upgrade - working-directory: ${{ inputs.path_to_project }} - - - name: Download test results - uses: actions/download-artifact@v2 - with: - path: ${{ inputs.path_to_project }}/artifacts - - - uses: sonarsource/sonarqube-scan-action@master - env: - SONAR_TOKEN: ${{ secrets.sonar_token }} - SONAR_HOST_URL: ${{ secrets.sonar_host }} - with: - projectBaseDir: ${{ inputs.path_to_project }} - args: > - -Dsonar.projectKey=${{ inputs.project_name }} - -Dsonar.login=${{ secrets.sonar_token }} - -Dsonar.verbose=true - -Dsonar.python.coverage.reportPaths=artifacts/*/coverage.xml - -Dsonar.coverage.exclusions=**/external/**/* - -Dsonar.exclusions=**/external/**/*,artifacts/**/* - - publish-test-results: - name: Publish unit test results - needs: test - runs-on: ubuntu-latest - if: always() - steps: - - name: Download artifacts - uses: actions/download-artifact@v2 - with: - path: artifacts - - - name: Publish results - uses: EnricoMi/publish-unit-test-result-action@v1 - with: - files: artifacts/*/pytest.xml