1+ name : CI/CD Pipeline
2+
3+ on :
4+ push :
5+ branches : [ main, master, develop ]
6+ pull_request :
7+ branches : [ main, master, develop ]
8+ workflow_dispatch :
9+
10+ jobs :
11+ test :
12+ name : Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
13+ runs-on : ${{ matrix.os }}
14+ strategy :
15+ fail-fast : false
16+ matrix :
17+ os : [ubuntu-latest, macos-latest, windows-latest]
18+ python-version : ["3.10", "3.11", "3.12"]
19+
20+ steps :
21+ - name : Checkout code
22+ uses : actions/checkout@v4
23+
24+ - name : Set up Python ${{ matrix.python-version }}
25+ uses : actions/setup-python@v4
26+ with :
27+ python-version : ${{ matrix.python-version }}
28+
29+ - name : Cache pip dependencies
30+ uses : actions/cache@v3
31+ with :
32+ path : ~/.cache/pip
33+ key : ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
34+ restore-keys : |
35+ ${{ runner.os }}-pip-
36+
37+ - name : Install dependencies
38+ run : |
39+ python -m pip install --upgrade pip
40+ pip install build twine
41+ pip install -e .[dev,test]
42+
43+ - name : Run tests with pytest
44+ run : |
45+ pytest tests/ -v --cov=agb --cov-report=xml --cov-report=term-missing
46+ env :
47+ # Set environment variables if tests require API keys
48+ AGB_API_KEY : ${{ secrets.AGB_API_KEY_TEST }}
49+
50+ - name : Upload coverage reports to Codecov
51+ if : matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
52+ uses : codecov/codecov-action@v3
53+ with :
54+ file : ./coverage.xml
55+ flags : unittests
56+ name : codecov-umbrella
57+
58+ - name : Build package
59+ run : python -m build
60+
61+ - name : Check package integrity
62+ run : twine check dist/*
63+
64+ - name : Upload build artifacts
65+ if : matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
66+ uses : actions/upload-artifact@v3
67+ with :
68+ name : python-package
69+ path : dist/
70+ retention-days : 7
71+
72+ lint :
73+ name : Code Quality Checks
74+ runs-on : ubuntu-latest
75+ steps :
76+ - name : Checkout code
77+ uses : actions/checkout@v4
78+
79+ - name : Set up Python
80+ uses : actions/setup-python@v4
81+ with :
82+ python-version : " 3.11"
83+
84+ - name : Install dependencies
85+ run : |
86+ python -m pip install --upgrade pip
87+ pip install -e .[dev,test]
88+
89+ - name : Run Black
90+ run : black --check --diff .
91+
92+ - name : Run isort
93+ run : isort --check-only --diff .
94+
95+ - name : Run Flake8
96+ run : flake8 .
97+
98+ - name : Run MyPy
99+ run : mypy agb/
100+ continue-on-error : true # MyPy may have some type issues, allow failure for now
101+
102+ security :
103+ name : Security Scan
104+ runs-on : ubuntu-latest
105+ steps :
106+ - name : Checkout code
107+ uses : actions/checkout@v4
108+
109+ - name : Set up Python
110+ uses : actions/setup-python@v4
111+ with :
112+ python-version : " 3.11"
113+
114+ - name : Install dependencies
115+ run : |
116+ python -m pip install --upgrade pip
117+ pip install bandit[toml] safety
118+
119+ - name : Run Bandit security scan
120+ run : bandit -r agb/ -f json -o bandit-report.json
121+ continue-on-error : true
122+
123+ - name : Run Safety dependency scan
124+ run : safety check --json --output safety-report.json
125+ continue-on-error : true
126+
127+ - name : Upload security reports
128+ uses : actions/upload-artifact@v3
129+ with :
130+ name : security-reports
131+ path : |
132+ bandit-report.json
133+ safety-report.json
134+ if : always()
135+
136+ # Only run on main branch when tests pass
137+ integration-test :
138+ name : Integration Tests
139+ runs-on : ubuntu-latest
140+ needs : [test, lint]
141+ if : github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
142+ steps :
143+ - name : Checkout code
144+ uses : actions/checkout@v4
145+
146+ - name : Set up Python
147+ uses : actions/setup-python@v4
148+ with :
149+ python-version : " 3.11"
150+
151+ - name : Install dependencies
152+ run : |
153+ python -m pip install --upgrade pip
154+ pip install -e .[dev,test]
155+
156+ - name : Run integration tests
157+ run : |
158+ # Run integration tests
159+ pytest tests/integration/ -v --maxfail=5
160+ env :
161+ AGB_API_KEY : ${{ secrets.AGB_API_KEY_TEST }}
162+ continue-on-error : true # Integration tests may fail due to external dependencies
0 commit comments