# GitHub Actions CI/CD Pipeline with Layered Testing
#
# This workflow runs tests in layered approach using shared environment setup:
# 1. Unit tests: Run on multiple Python versions (fast, no external dependencies)
# 2. Local tests: Run on single Python version (require local server startup)
# 3. Integration tests: Run on single Python version (require external services)
#
# Environment setup is shared with Copilot Setup Steps for consistency.
name: Tests
on:
# Run on pull requests - main testing phase
pull_request:
branches: [ main, master, develop ]
# Run on direct pushes to main/master (skip merge commits to avoid duplication)
push:
branches: [ main, master ]
jobs:
unit-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Setup PowerBI MCP Environment
uses: ./.github/actions/setup-powerbi-environment
with:
python-version: ${{ matrix.python-version }}
install-mode: "user"
environment-type: "ci"
# No secrets needed for unit tests - pass empty values
openai-model: "gpt-4o-mini"
log-level: "INFO"
- name: Check code formatting
run: |
# Check if code is properly formatted
echo "Checking code formatting with black..."
black --check --diff src/ tests/ --line-length=120
echo "Checking import organization with isort..."
isort --check-only --diff src/ tests/ --profile=black
echo "Code formatting checks passed!"
- name: Run lint checks
run: |
# Run flake8 with our configuration
flake8 src/ tests/ --config=.flake8
echo "Linting completed successfully"
- name: Run unit tests
run: |
# Set environment variable to indicate we're in CI
export CI=true
python -m pytest tests/unit/ -v --tb=short
echo "Unit tests completed on Python ${{ matrix.python-version }}"
local-tests:
runs-on: ubuntu-latest
needs: unit-tests
steps:
- uses: actions/checkout@v4
- name: Setup PowerBI MCP Environment
uses: ./.github/actions/setup-powerbi-environment
with:
python-version: "3.11" # Same as Copilot environment
install-mode: "user"
environment-type: "ci"
openai-model: "gpt-4o-mini"
log-level: "INFO"
- name: Run local tests
run: |
export CI=true
python -m pytest tests/local/ -v --tb=short
echo "Local tests completed"
integration-tests:
runs-on: ubuntu-latest
# Run integration tests on both pull requests and push to master
needs: [unit-tests, local-tests]
# Use copilot environment to access integration test variables and secrets
environment: copilot
steps:
- uses: actions/checkout@v4
- name: Setup PowerBI MCP Environment
uses: ./.github/actions/setup-powerbi-environment
with:
python-version: "3.11" # Same as Copilot environment
install-mode: "user"
environment-type: "ci"
openai-model: "gpt-4o-mini"
log-level: "INFO"
- name: Check integration test configuration
env:
ENABLE_INTEGRATION_TESTS: ${{ vars.ENABLE_INTEGRATION_TESTS }}
TEST_XMLA_ENDPOINT: ${{ secrets.TEST_XMLA_ENDPOINT }}
TEST_TENANT_ID: ${{ secrets.TEST_TENANT_ID }}
TEST_CLIENT_ID: ${{ secrets.TEST_CLIENT_ID }}
TEST_CLIENT_SECRET: ${{ secrets.TEST_CLIENT_SECRET }}
TEST_INITIAL_CATALOG: ${{ secrets.TEST_INITIAL_CATALOG }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
echo "Integration tests enabled: ${ENABLE_INTEGRATION_TESTS:-false}"
if [ "${ENABLE_INTEGRATION_TESTS}" = "true" ]; then
echo "✅ Integration tests will run"
echo "Test dataset: ${TEST_INITIAL_CATALOG:-Not configured}"
else
echo "ℹ️ Integration tests disabled or not configured"
fi
- name: Run integration tests
if: env.ENABLE_INTEGRATION_TESTS == 'true'
env:
ENABLE_INTEGRATION_TESTS: ${{ vars.ENABLE_INTEGRATION_TESTS }}
TEST_XMLA_ENDPOINT: ${{ secrets.TEST_XMLA_ENDPOINT }}
TEST_TENANT_ID: ${{ secrets.TEST_TENANT_ID }}
TEST_CLIENT_ID: ${{ secrets.TEST_CLIENT_ID }}
TEST_CLIENT_SECRET: ${{ secrets.TEST_CLIENT_SECRET }}
TEST_INITIAL_CATALOG: ${{ secrets.TEST_INITIAL_CATALOG }}
TEST_EXPECTED_TABLE: ${{ secrets.TEST_EXPECTED_TABLE }}
TEST_EXPECTED_COLUMN: ${{ secrets.TEST_EXPECTED_COLUMN }}
TEST_DAX_QUERY: ${{ secrets.TEST_DAX_QUERY }}
TEST_MIN_TABLES_COUNT: ${{ vars.TEST_MIN_TABLES_COUNT }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
echo "🚀 Running integration tests..."
python -m pytest tests/integration/ -v --tb=short
echo "Integration tests completed"
security-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run security scan
run: |
echo "Security scan temporarily disabled"
echo "TODO: Re-enable after configuring proper security scanning tools"