Skip to content

Sync with main-repo - 2025-11-27 #6

Sync with main-repo - 2025-11-27

Sync with main-repo - 2025-11-27 #6

Workflow file for this run

# -*- coding: utf-8 -*-
# ============================================================================ #
# DockerDiscordControl (DDC) - Test Suite CI/CD Workflow #
# https://ddc.bot #
# Copyright (c) 2025 MAX #
# Licensed under the MIT License #
# ============================================================================ #
#
# This workflow runs automated tests with coverage reporting.
name: Tests
on:
push:
branches:
- main
- v2.0
- develop
paths:
- '**.py'
- 'tests/**'
- 'pytest.ini'
- '.github/workflows/tests.yml'
pull_request:
branches:
- main
- v2.0
paths:
- '**.py'
- 'tests/**'
workflow_dispatch: # Allow manual trigger
permissions:
contents: read # Checkout code
actions: read # Download artifacts
pull-requests: write # Comment on PRs
statuses: write # Update check statuses
jobs:
unit-tests:
name: Unit Tests (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt
- name: Run unit tests with coverage
run: |
echo "## Unit Tests - Python ${{ matrix.python-version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Run tests with coverage
python -m pytest tests/unit/ \
--cov=services \
--cov=app \
--cov=utils \
--cov-report=term-missing \
--cov-report=xml \
--cov-report=html \
-v || true
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Unit tests completed" >> $GITHUB_STEP_SUMMARY
- name: Upload coverage reports
if: matrix.python-version == '3.10'
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
- name: Upload coverage HTML
if: matrix.python-version == '3.10'
uses: actions/upload-artifact@v4
with:
name: coverage-html
path: htmlcov/
retention-days: 30
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
needs: unit-tests
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install -r requirements-test.txt
- name: Run integration tests
run: |
echo "## Integration Tests" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
python -m pytest tests/integration/ -v || true
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Integration tests completed" >> $GITHUB_STEP_SUMMARY
continue-on-error: true
test-summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [unit-tests, integration-tests]
if: always()
steps:
- name: Generate summary
run: |
echo "# Test Suite Summary" > test_summary.md
echo "" >> test_summary.md
echo "**Branch**: ${{ github.ref_name }}" >> test_summary.md
echo "**Commit**: ${{ github.sha }}" >> test_summary.md
echo "**Date**: $(date)" >> test_summary.md
echo "" >> test_summary.md
echo "## Job Results" >> test_summary.md
echo "" >> test_summary.md
echo "- Unit Tests: ${{ needs.unit-tests.result }}" >> test_summary.md
echo "- Integration Tests: ${{ needs.integration-tests.result }}" >> test_summary.md
echo "" >> test_summary.md
if [[ "${{ needs.unit-tests.result }}" == "success" ]]; then
echo "## ✅ Overall: PASS" >> test_summary.md
echo "All tests passed successfully!" >> test_summary.md
else
echo "## ⚠️ Overall: REVIEW NEEDED" >> test_summary.md
echo "Some tests may have failed. Please review." >> test_summary.md
fi
cat test_summary.md >> $GITHUB_STEP_SUMMARY
- name: Comment PR with test results
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let comment = '## Test Results\\n\\n';
comment += '**Unit Tests**: ${{ needs.unit-tests.result }}\\n';
comment += '**Integration Tests**: ${{ needs.integration-tests.result }}\\n\\n';
if ('${{ needs.unit-tests.result }}' === 'success') {
comment += '✅ All tests passed!\\n';
} else {
comment += '⚠️ Some tests failed. Please review the logs.\\n';
}
comment += '\\n[View full test report](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
continue-on-error: true