mirror of
https://github.com/aimingmed/aimingmed-ai.git
synced 2026-02-04 22:25:34 +08:00
Merge pull request #75 from aimingmed/feature/test-coverage-report
try coverage
This commit is contained in:
commit
aaaf0f4242
20
.github/workflows/build.yml
vendored
20
.github/workflows/build.yml
vendored
@ -1,13 +1,10 @@
|
|||||||
name: Build + CI
|
name: Unittest and Build + CI
|
||||||
|
|
||||||
# Triggers: Equivalent to ADO trigger block
|
# Triggers: Equivalent to ADO trigger block
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- develop
|
- develop
|
||||||
# paths:
|
|
||||||
# - 'app/**'
|
|
||||||
# - '.github/workflows/**'
|
|
||||||
|
|
||||||
# Concurrency control: Ensures only one run per branch at a time, Equivalent to batch: true
|
# Concurrency control: Ensures only one run per branch at a time, Equivalent to batch: true
|
||||||
concurrency:
|
concurrency:
|
||||||
@ -15,8 +12,23 @@ concurrency:
|
|||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
run_backend_unittests:
|
||||||
|
name: Run Backend unit tests
|
||||||
|
permissions:
|
||||||
|
checks: write
|
||||||
|
secrets: inherit # Inherit secrets from the parent workflow
|
||||||
|
# Call the reusable workflow for unit tests
|
||||||
|
uses: ./.github/workflows/template_unit_pytest.yml
|
||||||
|
# Pass parameters as inputs to the reusable workflow
|
||||||
|
with:
|
||||||
|
projectName: Backend # Value defined in original variables
|
||||||
|
workingDir: app/backend
|
||||||
|
testsFolderName: tests
|
||||||
|
# secrets: inherit # Inherit secrets from the parent workflow
|
||||||
|
|
||||||
# This job defines the matrix and calls the reusable workflow for each image build
|
# This job defines the matrix and calls the reusable workflow for each image build
|
||||||
build:
|
build:
|
||||||
|
needs: run_backend_unittests
|
||||||
name: Build ${{ matrix.image_config.IMAGE_NAME }}
|
name: Build ${{ matrix.image_config.IMAGE_NAME }}
|
||||||
# Define necessary permissions if needed (e.g., for GitHub Packages)
|
# Define necessary permissions if needed (e.g., for GitHub Packages)
|
||||||
permissions:
|
permissions:
|
||||||
|
|||||||
2
.github/workflows/template_test.yml
vendored
2
.github/workflows/template_test.yml
vendored
@ -1,4 +1,4 @@
|
|||||||
name: Reusable Test Workflow
|
name: Reusable Integration Test Template
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
|||||||
93
.github/workflows/template_unit_pytest.yml
vendored
Normal file
93
.github/workflows/template_unit_pytest.yml
vendored
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
name: Reusable Unit Test with Pytest Template
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
projectName:
|
||||||
|
description: 'Name of the project'
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
workingDir:
|
||||||
|
description: 'Working directory for the component'
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
testsFolderName:
|
||||||
|
description: 'Tests folder name'
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_and_test:
|
||||||
|
name: Build and Test ${{ inputs.projectName }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 120
|
||||||
|
|
||||||
|
# Define environment variables based on inputs, similar to Azure variables
|
||||||
|
env:
|
||||||
|
SRC_PATH: ${{ github.workspace }}/${{ inputs.workingDir }}
|
||||||
|
TESTS_PATH: ${{ github.workspace }}/${{ inputs.workingDir }}/${{ inputs.testsFolderName }}
|
||||||
|
TESTS_RESULTS_PATH: ${{ github.workspace }}/${{ inputs.workingDir }}/results.xml
|
||||||
|
TESTS_COVERAGE_REPORT_PATH: ${{ github.workspace }}/${{ inputs.workingDir }}/coverage.xml
|
||||||
|
# Use the working directory input for commands that need it
|
||||||
|
WORKING_DIR: ${{ inputs.workingDir }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python 3.11
|
||||||
|
uses: actions/setup-python@v5 # Use latest stable version
|
||||||
|
with:
|
||||||
|
python-version: '3.11'
|
||||||
|
|
||||||
|
- name: Install build dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install pipenv
|
||||||
|
|
||||||
|
- name: Install environment including dev dependencies
|
||||||
|
working-directory: ${{ env.WORKING_DIR }}
|
||||||
|
run: |
|
||||||
|
echo "Current directory:"
|
||||||
|
pwd
|
||||||
|
echo "Listing files:"
|
||||||
|
ls -al
|
||||||
|
echo "Pipfile content:"
|
||||||
|
cat Pipfile
|
||||||
|
pipenv sync -d
|
||||||
|
|
||||||
|
- name: Run tests with pytest
|
||||||
|
working-directory: ${{ env.WORKING_DIR }}
|
||||||
|
run: |
|
||||||
|
pipenv run pytest --version
|
||||||
|
# Use the environment variables defined above for paths
|
||||||
|
pipenv run pytest -v -s -o log_cli=true --junitxml=results.xml --cov=${{ env.SRC_PATH }} --cov-report=xml:${{ env.TESTS_COVERAGE_REPORT_PATH }} ${{ env.TESTS_PATH }}
|
||||||
|
echo "Listing results in working directory:"
|
||||||
|
ls -al ${{ github.workspace }}/${{ env.WORKING_DIR }}
|
||||||
|
|
||||||
|
|
||||||
|
# Use a popular action for publishing test results for better GitHub integration
|
||||||
|
- name: Publish Test Report
|
||||||
|
uses: dorny/test-reporter@v1
|
||||||
|
if: success() || failure() # always run even if tests fail
|
||||||
|
with:
|
||||||
|
name: ${{ inputs.projectName }} Test Results
|
||||||
|
path: ${{ env.TESTS_RESULTS_PATH }}
|
||||||
|
reporter: java-junit # Specify JUnit format
|
||||||
|
|
||||||
|
# Upload coverage report as an artifact
|
||||||
|
- name: Upload coverage report artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
if: success() || failure() # always run
|
||||||
|
with:
|
||||||
|
name: ${{ inputs.projectName }}-coverage-report
|
||||||
|
path: ${{ env.TESTS_COVERAGE_REPORT_PATH }}
|
||||||
|
|
||||||
|
- name: Upload coverage to Codecov
|
||||||
|
uses: codecov/codecov-action@v5
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
files: ${{ env.TESTS_COVERAGE_REPORT_PATH }}
|
||||||
|
fail_ci_if_error: true
|
||||||
|
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
[](https://github.com/aimingmed/aimingmed-ai/actions/workflows/build.yml)
|
[](https://github.com/aimingmed/aimingmed-ai/actions/workflows/build.yml)
|
||||||
|
|
||||||
## Important note:
|
## Important note:
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ export default defineConfig({
|
|||||||
server: {
|
server: {
|
||||||
host: true,
|
host: true,
|
||||||
strictPort: true,
|
strictPort: true,
|
||||||
port: 5173
|
port:
|
||||||
},
|
},
|
||||||
test: {
|
test: {
|
||||||
globals: true,
|
globals: true,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user