Skip to content

Commit ea9b771

Browse files
committed
feat: Optimize remaining GitHub Actions workflows with enhanced features
## Tests Workflow (tests.yml): - Enhanced dependency caching with better cache keys - Added test environment validation - Improved error reporting with detailed logs - Added comprehensive job summaries - Better artifact management with longer retention ## CI Workflow (ci.yml): - Added timeout protection (45 minutes) - Enhanced caching for CI-specific pip dependencies - Improved build environment validation - Better Codecov integration with verbose output - Enhanced documentation build process - Added artifact management for docs - Comprehensive CI build summaries ## Pre-commit Workflow (pre-commit.yml): - Added pre-commit environment caching - Enhanced configuration validation - Better error handling with diff output - Increased timeout to 15 minutes for complex repos - Added comprehensive job summaries with helpful tips All workflows now feature: - Better caching strategies - Enhanced error handling and reporting - Comprehensive job summaries - Improved logging with emojis for better UX - Proper fetch-depth for git operations - Consistent timeout protection
1 parent b8b86b8 commit ea9b771

File tree

4 files changed

+224
-15
lines changed

4 files changed

+224
-15
lines changed

.github/workflows/api_reference.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Set up Python
3434
uses: actions/setup-python@v5
3535
with:
36-
python-version: "3.11" # Use same as main CI
36+
python-version: "3.13.2" # Use same as main CI
3737
cache: "pip"
3838

3939
- name: Cache Python dependencies

.github/workflows/ci.yml

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,131 @@ concurrency:
1717
jobs:
1818
build:
1919
runs-on: self-hosted
20+
timeout-minutes: 45
2021
strategy:
2122
fail-fast: false
2223
matrix:
2324
python-version: ["3.10", "3.11", "3.12", "3.13"]
2425

2526
steps:
26-
- uses: actions/checkout@v4
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
2732
- name: Set up Python ${{ matrix.python-version }}
2833
uses: actions/setup-python@v5
2934
with:
3035
python-version: ${{ matrix.python-version }}
3136
cache: "pip"
3237

38+
- name: Cache pip dependencies
39+
uses: actions/cache@v4
40+
with:
41+
path: ~/.cache/pip
42+
key: ${{ runner.os }}-ci-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements*.txt', 'pyproject.toml', 'setup.py') }}
43+
restore-keys: |
44+
${{ runner.os }}-ci-pip-${{ matrix.python-version }}-
45+
${{ runner.os }}-ci-pip-
46+
3347
- name: Install dependencies
3448
run: |
49+
echo "🔧 Installing dependencies for CI build..."
3550
python -m pip install --upgrade pip
3651
python -m pip install pytest pytest-cov
37-
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
38-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
52+
53+
# Install package requirements
54+
if [ -f requirements-dev.txt ]; then
55+
echo "📦 Installing requirements-dev.txt..."
56+
pip install -r requirements-dev.txt
57+
fi
58+
if [ -f requirements.txt ]; then
59+
echo "📦 Installing requirements.txt..."
60+
pip install -r requirements.txt
61+
fi
62+
63+
echo "✅ Dependencies installed successfully"
64+
65+
- name: Validate build environment
66+
run: |
67+
echo "🔍 Validating CI environment..."
68+
python --version
69+
pip --version
70+
pytest --version
71+
72+
echo "📊 Key installed packages:"
73+
pip list | grep -E "(pytest|coverage|sphinx|numpy|scipy)" || true
3974
4075
- name: Test with pytest
4176
run: |
42-
pytest --cov=./ --cov-report=xml
77+
echo "🧪 Running CI tests..."
78+
pytest --cov=./ --cov-report=xml --cov-report=term-missing -v
79+
echo "✅ Tests completed successfully"
4380
4481
- name: Upload coverage to Codecov
4582
uses: codecov/codecov-action@v5
4683
with:
4784
files: ./coverage.xml
4885
fail_ci_if_error: false
86+
verbose: true
87+
env:
88+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
4989

5090
- name: Build documentation
5191
if: matrix.python-version == '3.11' && github.event_name == 'push'
5292
run: |
93+
echo "📚 Building documentation..."
5394
if [ -f docs/requirements.txt ]; then
95+
echo "📦 Installing documentation dependencies..."
5496
pip install -r docs/requirements.txt
5597
pip install -r docs/requirements-dev.txt
98+
99+
echo "🔨 Building HTML documentation..."
56100
cd docs && make clean html
101+
echo "✅ Documentation built successfully"
102+
else
103+
echo "⚠️ No docs/requirements.txt found, skipping documentation build"
57104
fi
58105
59106
- name: Archive code coverage results
60107
uses: actions/upload-artifact@v4
61108
with:
62109
name: code-coverage-report-${{ matrix.python-version }}
63110
path: coverage.xml
64-
retention-days: 5
111+
retention-days: 7
112+
113+
- name: Archive documentation
114+
if: matrix.python-version == '3.11' && github.event_name == 'push'
115+
uses: actions/upload-artifact@v4
116+
with:
117+
name: documentation-html
118+
path: docs/_build/html/
119+
retention-days: 14
120+
121+
- name: Generate CI summary
122+
if: always()
123+
run: |
124+
echo "# 🏗️ CI Build Results - Python ${{ matrix.python-version }}" >> $GITHUB_STEP_SUMMARY
125+
echo "" >> $GITHUB_STEP_SUMMARY
126+
127+
if [ $? -eq 0 ]; then
128+
echo "✅ **Status**: Build and tests successful" >> $GITHUB_STEP_SUMMARY
129+
else
130+
echo "❌ **Status**: Build or tests failed" >> $GITHUB_STEP_SUMMARY
131+
fi
132+
133+
echo "" >> $GITHUB_STEP_SUMMARY
134+
echo "### Build Information:" >> $GITHUB_STEP_SUMMARY
135+
echo "- **Python Version**: ${{ matrix.python-version }}" >> $GITHUB_STEP_SUMMARY
136+
echo "- **Runner**: ${{ runner.os }}" >> $GITHUB_STEP_SUMMARY
137+
echo "- **Event**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
138+
echo "- **Branch**: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
139+
echo "- **Commit**: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
140+
141+
echo "" >> $GITHUB_STEP_SUMMARY
142+
echo "### Artifacts Generated:" >> $GITHUB_STEP_SUMMARY
143+
echo "- Code coverage report" >> $GITHUB_STEP_SUMMARY
144+
145+
if [ "${{ matrix.python-version }}" = "3.11" ] && [ "${{ github.event_name }}" = "push" ]; then
146+
echo "- HTML documentation (Python 3.11 only)" >> $GITHUB_STEP_SUMMARY
147+
fi

.github/workflows/pre-commit.yml

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,93 @@ concurrency:
1414
jobs:
1515
pre-commit:
1616
runs-on: self-hosted
17-
timeout-minutes: 10
17+
timeout-minutes: 15
1818
steps:
19-
- uses: actions/checkout@v4
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
2023

2124
- name: Set up Python
2225
uses: actions/setup-python@v5
2326
with:
2427
python-version: "3.13.2"
28+
cache: "pip"
29+
30+
- name: Cache pre-commit environments
31+
uses: actions/cache@v4
32+
with:
33+
path: ~/.cache/pre-commit
34+
key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
35+
restore-keys: |
36+
pre-commit-${{ runner.os }}-
2537
2638
- name: Cache pip dependencies
2739
uses: actions/cache@v4
2840
with:
2941
path: ~/.cache/pip
30-
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
42+
key: ${{ runner.os }}-precommit-pip-${{ hashFiles('**/requirements*.txt', '.pre-commit-config.yaml') }}
3143
restore-keys: |
32-
${{ runner.os }}-pip-
44+
${{ runner.os }}-precommit-pip-
3345
3446
- name: Install pre-commit
3547
run: |
48+
echo "🔧 Installing pre-commit..."
3649
python -m pip install --upgrade pip
3750
pip install pre-commit
51+
echo "✅ Pre-commit installed successfully"
52+
53+
- name: Validate pre-commit configuration
54+
run: |
55+
echo "🔍 Validating pre-commit configuration..."
56+
pre-commit --version
57+
58+
if [ -f .pre-commit-config.yaml ]; then
59+
echo "📋 Pre-commit configuration found"
60+
echo "Configured hooks:"
61+
grep -E "^\s*-\s+repo:|^\s+id:" .pre-commit-config.yaml | head -10
62+
else
63+
echo "❌ No .pre-commit-config.yaml found"
64+
exit 1
65+
fi
3866
3967
- name: Run pre-commit hooks
4068
run: |
69+
echo "🧹 Running pre-commit hooks..."
4170
pre-commit clean
4271
pre-commit migrate-config
4372
pre-commit install
44-
pre-commit run --all-files
73+
74+
# Run hooks and capture output
75+
if pre-commit run --all-files --show-diff-on-failure; then
76+
echo "✅ All pre-commit hooks passed"
77+
else
78+
echo "❌ Some pre-commit hooks failed"
79+
exit 1
80+
fi
81+
82+
- name: Generate pre-commit summary
83+
if: always()
84+
run: |
85+
echo "# 🧹 Pre-commit Check Results" >> $GITHUB_STEP_SUMMARY
86+
echo "" >> $GITHUB_STEP_SUMMARY
87+
88+
if [ $? -eq 0 ]; then
89+
echo "✅ **Status**: All pre-commit hooks passed" >> $GITHUB_STEP_SUMMARY
90+
else
91+
echo "❌ **Status**: Some pre-commit hooks failed" >> $GITHUB_STEP_SUMMARY
92+
fi
93+
94+
echo "" >> $GITHUB_STEP_SUMMARY
95+
echo "### Check Information:" >> $GITHUB_STEP_SUMMARY
96+
echo "- **Python Version**: 3.13.2" >> $GITHUB_STEP_SUMMARY
97+
echo "- **Runner**: ${{ runner.os }}" >> $GITHUB_STEP_SUMMARY
98+
echo "- **Event**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
99+
echo "- **Branch**: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
100+
echo "- **Commit**: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
101+
102+
echo "" >> $GITHUB_STEP_SUMMARY
103+
echo "### Pre-commit Hooks:" >> $GITHUB_STEP_SUMMARY
104+
echo "All configured hooks in \`.pre-commit-config.yaml\` were executed." >> $GITHUB_STEP_SUMMARY
105+
echo "" >> $GITHUB_STEP_SUMMARY
106+
echo "> 💡 **Tip**: If hooks failed, check the action logs for specific issues. Common fixes include formatting code with \`black\`, \`prettier\`, or fixing linting issues."

.github/workflows/tests.yml

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,96 @@ jobs:
2222
python-version: ${{ github.ref == 'refs/heads/dev' && fromJSON('["3.10"]') || fromJSON('["3.10", "3.11", "3.12", "3.13"]') }}
2323

2424
steps:
25-
- uses: actions/checkout@v4
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
2629

2730
- name: Set up Python ${{ matrix.python-version }}
2831
uses: actions/setup-python@v5
2932
with:
3033
python-version: ${{ matrix.python-version }}
34+
cache: "pip"
3135

3236
- name: Cache pip dependencies
3337
uses: actions/cache@v4
3438
with:
3539
path: ~/.cache/pip
36-
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements*.txt') }}
40+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements*.txt', 'pyproject.toml', 'setup.py') }}
3741
restore-keys: |
42+
${{ runner.os }}-pip-${{ matrix.python-version }}-
3843
${{ runner.os }}-pip-
3944
4045
- name: Install dependencies
4146
run: |
47+
echo "🔧 Installing dependencies for Python ${{ matrix.python-version }}..."
4248
python -m pip install --upgrade pip
4349
python -m pip install pytest pytest-cov
50+
51+
# Install package in development mode
4452
pip install -e .[dev]
45-
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
53+
54+
# Install additional dev requirements if they exist
55+
if [ -f requirements-dev.txt ]; then
56+
echo "📦 Installing requirements-dev.txt..."
57+
pip install -r requirements-dev.txt
58+
fi
59+
60+
echo "✅ Dependencies installed successfully"
4661
shell: bash
4762

63+
- name: Validate test environment
64+
run: |
65+
echo "🔍 Validating test environment..."
66+
python --version
67+
pip --version
68+
pytest --version
69+
python -c "import kaira; print(f'Kaira version: {kaira.__version__}')" || echo "⚠️ Kaira not importable"
70+
71+
echo "📊 Installed packages:"
72+
pip list | head -20
73+
4874
- name: Test with pytest
4975
run: |
50-
pytest --cov=kaira --cov-report=xml
76+
echo "🧪 Running tests with pytest..."
77+
pytest --cov=kaira --cov-report=xml --cov-report=term-missing -v
78+
echo "✅ Tests completed"
79+
80+
- name: Upload test results
81+
if: always()
82+
uses: actions/upload-artifact@v4
83+
with:
84+
name: test-results-python-${{ matrix.python-version }}
85+
path: |
86+
coverage.xml
87+
pytest.xml
88+
retention-days: 7
89+
90+
- name: Generate test summary
91+
if: always()
92+
run: |
93+
echo "# 🧪 Test Results - Python ${{ matrix.python-version }}" >> $GITHUB_STEP_SUMMARY
94+
echo "" >> $GITHUB_STEP_SUMMARY
95+
96+
if [ $? -eq 0 ]; then
97+
echo "✅ **Status**: All tests passed" >> $GITHUB_STEP_SUMMARY
98+
else
99+
echo "❌ **Status**: Some tests failed" >> $GITHUB_STEP_SUMMARY
100+
fi
101+
102+
echo "" >> $GITHUB_STEP_SUMMARY
103+
echo "### Test Environment:" >> $GITHUB_STEP_SUMMARY
104+
echo "- **Python Version**: ${{ matrix.python-version }}" >> $GITHUB_STEP_SUMMARY
105+
echo "- **Runner**: ${{ runner.os }}" >> $GITHUB_STEP_SUMMARY
106+
echo "- **Branch**: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
107+
echo "- **Commit**: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
108+
109+
# Add coverage info if available
110+
if [ -f coverage.xml ]; then
111+
echo "" >> $GITHUB_STEP_SUMMARY
112+
echo "### Coverage:" >> $GITHUB_STEP_SUMMARY
113+
echo "Coverage report generated and uploaded as artifact." >> $GITHUB_STEP_SUMMARY
114+
fi
51115
52116
- name: Upload coverage to Codecov
53117
uses: codecov/codecov-action@v5

0 commit comments

Comments
 (0)