Skip to content

Code Coverage

Code Coverage #6183

Workflow file for this run

name: Code Coverage
on:
push:
branches:
- main
pull_request:
branches:
- main
# have the ability to trigger this workflow manually
workflow_dispatch:
jobs:
build:
name: Unit Test and SonarCloud Scan
runs-on: ubuntu-latest
env:
ANSIBLE_AI_DATABASE_HOST: localhost
ANSIBLE_AI_DATABASE_NAME: wisdom
ANSIBLE_AI_DATABASE_PASSWORD: wisdom
ANSIBLE_AI_DATABASE_USER: wisdom
DJANGO_SETTINGS_MODULE: ansible_ai_connect.main.settings.development
ENABLE_ANSIBLE_LINT_POSTPROCESS: True
PYTHONUNBUFFERED: 1
SECRET_KEY: somesecret
services:
postgres:
image: docker.io/library/postgres:alpine
env:
POSTGRES_USER: wisdom
POSTGRES_PASSWORD: wisdom
POSTGRES_DB: wisdom
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
##############
# Python tests
##############
- name: Setup Django server
uses: ./.github/actions/setup-django-server
with:
start-server: 'false'
- name: Running Unit Tests (Python)
run: |
coverage run --rcfile=setup.cfg -m ansible_ai_connect.manage test ansible_ai_connect
coverage xml
coverage report --rcfile=setup.cfg --format=markdown > code-coverage-results.md
# See https://sonarsource.atlassian.net/browse/SONARPY-1203
- name: Fix paths in coverage file
run: |
sed -i 's,/home/runner/work/ansible-wisdom-service/ansible-wisdom-service/,/github/workspace/,g' coverage.xml
##################
# TypeScript tests
##################
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '21.x'
cache: 'npm'
cache-dependency-path: ./ansible_ai_connect_admin_portal/package-lock.json
- name: Install Dependencies (TypeScript)
run: npm ci
working-directory: ./ansible_ai_connect_admin_portal
- name: Running Unit Tests (TypeScript)
run: npm run test
working-directory: ./ansible_ai_connect_admin_portal
############################
# TypeScript tests (chatbot)
############################
- name: Use Node.js (chatbot)
uses: actions/setup-node@v3
with:
node-version: '21.x'
cache: 'npm'
cache-dependency-path: ./ansible_ai_connect_chatbot/package-lock.json
- name: Install Dependencies (TypeScript) (chatbot)
run: npm install
working-directory: ./ansible_ai_connect_chatbot
- name: Install Chromium dependencies (chatbot)
run: npx playwright install-deps chromium
working-directory: ./ansible_ai_connect_chatbot
- name: Install Chromium (chatbot)
run: npx playwright install chromium
working-directory: ./ansible_ai_connect_chatbot
- name: Running Unit Tests with code coverage (TypeScript) (chatbot)
run: npm run coverage
working-directory: ./ansible_ai_connect_chatbot
#####################
# SonarCloud coverage
#####################
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
####################
# OpenAPI file check
####################
- name: Start Django server for OpenAPI generation
shell: bash
run: |
make run-server &
sleep 10
make create-cachetable
- name: Ensure the OpenAPI file is up to date
run: |
make update-openapi-schema
git diff --exit-code -- tools/openapi-schema/ansible-ai-connect-service.yaml
git diff --exit-code -- tools/openapi-schema/ansible-ai-connect-service.json
- name: Validate OpenAPI schema
continue-on-error: true
run: |
python3 -c "
from openapi_spec_validator import validate_url
from openapi_spec_validator.validation.validators import OpenAPIV30SpecValidator
validate_url('http://localhost:8000/api/schema/', cls=OpenAPIV30SpecValidator)
"
- name: Upload OpenAPI spec artifact (for sync on push to main)
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: openapi-schema
path: tools/openapi-schema/ansible-ai-connect-service.json
retention-days: 1
sync-to-central-repo:
name: Sync spec to central repo
needs: [build]
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main'
permissions:
contents: read
uses: ansible-automation-platform/aap-openapi-specs/.github/workflows/check-for-spec-drift.yml@devel

Check failure on line 157 in .github/workflows/code_coverage.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/code_coverage.yml

Invalid workflow file

error parsing called workflow ".github/workflows/code_coverage.yml" -> "ansible-automation-platform/aap-openapi-specs/.github/workflows/check-for-spec-drift.yml@devel" : workflow was not found. See https://docs.github.com/actions/learn-github-actions/reusing-workflows#access-to-reusable-workflows for more information.
with:
component_name: 'lightspeed'
spec_file_name: 'lightspeed.json'
artifact_name: 'openapi-schema'
spec_file_path_in_artifact: 'ansible-ai-connect-service.json'
branch_name: ${{ github.ref_name }}
commit_sha: ${{ github.sha }}
commit_message: ${{ github.event.head_commit.message }}
component_repo: ${{ github.repository }}
workflow_run_id: ${{ github.run_id }}
secrets:
SPEC_SYNC_TOKEN: ${{ secrets.OPENAPI_SPEC_SYNC_TOKEN }}