-
Notifications
You must be signed in to change notification settings - Fork 1
143 lines (123 loc) · 4.78 KB
/
test.yml
File metadata and controls
143 lines (123 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Run tox tests
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches: [main]
jobs:
test:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
test-env: ["py312", "lint"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
version: "0.6.14"
python-version: ${{ matrix.python-version }}
enable-cache: true
- name: Cache tox environments
uses: actions/cache@v4
with:
path: .tox/
key: ${{ runner.os }}-tox-${{ matrix.test-env }}-${{ hashFiles('**/pyproject.toml', '**/tox.ini') }}
restore-keys: |
${{ runner.os }}-tox-${{ matrix.test-env }}-
${{ runner.os }}-tox-
- name: Install tox with UV
run: uv tool install tox
- name: Create test env
shell: bash
run: |
cp .env.example .env
sed -i "s|API_KEY=your_api_key_here|API_KEY=${{ secrets.API_KEY || 'test_api_key' }}|" .env
sed -i "s|BASE_URL=https://api.example.com|BASE_URL=${{ secrets.BASE_URL || 'https://api.test.com' }}|" .env
- name: Run tox environment
id: tox
run: |
tox -e ${{ matrix.test-env }}
- name: Generate test report
if: matrix.test-env == 'py312'
shell: bash
run: |
echo "# 🧪 Test Report" > apihub-client-test-report.md
echo "" >> apihub-client-test-report.md
echo "## Test Results" >> apihub-client-test-report.md
echo "" >> apihub-client-test-report.md
echo "### Test Environment" >> apihub-client-test-report.md
echo "" >> apihub-client-test-report.md
echo "- **Python Version:** ${{ matrix.python-version }}" >> apihub-client-test-report.md
echo "- **OS:** Ubuntu Latest" >> apihub-client-test-report.md
echo "- **Tox Environment:** ${{ matrix.test-env }}" >> apihub-client-test-report.md
echo "" >> apihub-client-test-report.md
echo "### Status" >> apihub-client-test-report.md
echo "" >> apihub-client-test-report.md
if [ ${{ steps.tox.outcome }} == "success" ]; then
echo "✅ All tests passed successfully!" >> apihub-client-test-report.md
else
echo "❌ Some tests failed. Please check the logs above." >> apihub-client-test-report.md
fi
- name: Run coverage separately
if: matrix.test-env == 'py312'
run: |
uv run --frozen pytest test/ --cov=src/apihub_client --cov-report=xml --cov-report=html --cov-fail-under=85
- name: Render the report to the PR
if: matrix.test-env == 'py312' && github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: apihub-client-test-report
recreate: true
path: apihub-client-test-report.md
- name: Output reports to the job summary
if: matrix.test-env == 'py312'
shell: bash
run: |
if [ -f "apihub-client-test-report.md" ]; then
{
echo "<details><summary>ApiHub Client Test Report</summary>"
echo ""
cat "apihub-client-test-report.md"
echo ""
echo "</details>"
} >> "$GITHUB_STEP_SUMMARY"
fi
- name: Upload test artifacts
if: always() && matrix.test-env == 'py312'
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.python-version }}
path: |
htmlcov/
coverage.xml
.coverage
apihub-client-test-report.md
retention-days: 30
test-summary:
if: always() && github.event.pull_request.draft == false
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Test Summary
shell: bash
run: |
echo "## 📋 Test Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.test.result }}" == "success" ]; then
echo "✅ **Unit Tests:** Passed" >> $GITHUB_STEP_SUMMARY
echo "✅ **Linting:** Passed" >> $GITHUB_STEP_SUMMARY
else
echo "❌ **Tests:** Failed" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.test.result }}" == "success" ]; then
echo "🎉 **Overall Status:** All checks passed! Ready for merge." >> $GITHUB_STEP_SUMMARY
else
echo "⚠️ **Overall Status:** Some checks failed. Please review and fix before merging." >> $GITHUB_STEP_SUMMARY
fi