1+ name : CI/CD Pipeline
2+
3+ on :
4+ push :
5+ branches : [main, develop]
6+ pull_request :
7+ branches : [main]
8+ schedule :
9+ - cron : ' 0 0 * * 0' # Weekly security scan
10+
11+ env :
12+ REGISTRY : ghcr.io
13+ IMAGE_NAME : ${{ github.repository }}
14+
15+ jobs :
16+ test-powershell :
17+ runs-on : windows-latest
18+ steps :
19+ - uses : actions/checkout@v3
20+
21+ - name : Run Pester tests
22+ shell : pwsh
23+ run : |
24+ Install-Module -Name Pester -Force -SkipPublisherCheck
25+ Invoke-Pester -Path ./tests -OutputFormat NUnitXml -OutputFile TestResults.xml
26+
27+ - name : Upload test results
28+ uses : actions/upload-artifact@v3
29+ if : always()
30+ with :
31+ name : powershell-test-results
32+ path : TestResults.xml
33+
34+ - name : Run PSScriptAnalyzer
35+ shell : pwsh
36+ run : |
37+ Install-Module -Name PSScriptAnalyzer -Force
38+ Invoke-ScriptAnalyzer -Path . -Recurse -OutputFormat SARIF -OutFile PSAnalysis.sarif
39+
40+ - name : Upload SARIF file
41+ uses : github/codeql-action/upload-sarif@v2
42+ with :
43+ sarif_file : PSAnalysis.sarif
44+
45+ test-python :
46+ runs-on : ubuntu-latest
47+ strategy :
48+ matrix :
49+ python-version : ["3.9", "3.10", "3.11"]
50+
51+ steps :
52+ - uses : actions/checkout@v3
53+
54+ - name : Set up Python ${{ matrix.python-version }}
55+ uses : actions/setup-python@v4
56+ with :
57+ python-version : ${{ matrix.python-version }}
58+
59+ - name : Install dependencies
60+ run : |
61+ python -m pip install --upgrade pip
62+ pip install -r requirements.txt
63+ pip install pytest pytest-cov pytest-asyncio black flake8 bandit
64+
65+ - name : Lint with flake8
66+ run : |
67+ flake8 python-automation --count --select=E9,F63,F7,F82 --show-source --statistics
68+ flake8 python-automation --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
69+
70+ - name : Format check with black
71+ run : black --check python-automation
72+
73+ - name : Security scan with bandit
74+ run : bandit -r python-automation -f json -o bandit-report.json
75+
76+ - name : Test with pytest
77+ run : |
78+ pytest python-automation/tests --cov=python-automation --cov-report=xml --cov-report=html
79+
80+ - name : Upload coverage reports
81+ uses : codecov/codecov-action@v3
82+ with :
83+ file : ./coverage.xml
84+ flags : python
85+ name : Python ${{ matrix.python-version }}
86+
87+ test-database :
88+ runs-on : ubuntu-latest
89+ services :
90+ sqlserver :
91+ image : mcr.microsoft.com/mssql/server:2019-latest
92+ env :
93+ ACCEPT_EULA : Y
94+ SA_PASSWORD : YourStrong@Passw0rd
95+ ports :
96+ - 1433:1433
97+ options : >-
98+ --health-cmd "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P YourStrong@Passw0rd -Q 'SELECT 1'"
99+ --health-interval 10s
100+ --health-timeout 5s
101+ --health-retries 5
102+
103+ steps :
104+ - uses : actions/checkout@v3
105+
106+ - name : Initialize database
107+ run : |
108+ /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P YourStrong@Passw0rd -i database/init.sql
109+
110+ - name : Run database tests
111+ run : |
112+ /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P YourStrong@Passw0rd -Q "EXEC sp_GetLicenseUtilization"
113+
114+ security-scan :
115+ runs-on : ubuntu-latest
116+ steps :
117+ - uses : actions/checkout@v3
118+
119+ - name : Run Trivy vulnerability scanner
120+ uses : aquasecurity/trivy-action@master
121+ with :
122+ scan-type : ' fs'
123+ scan-ref : ' .'
124+ format : ' sarif'
125+ output : ' trivy-results.sarif'
126+
127+ - name : Upload Trivy results to GitHub Security
128+ uses : github/codeql-action/upload-sarif@v2
129+ with :
130+ sarif_file : ' trivy-results.sarif'
131+
132+ - name : OWASP Dependency Check
133+ uses : dependency-check/Dependency-Check_Action@main
134+ with :
135+ project : ' Adobe-Automation'
136+ path : ' .'
137+ format : ' HTML'
138+
139+ build-docker :
140+ needs : [test-powershell, test-python]
141+ runs-on : ubuntu-latest
142+ permissions :
143+ contents : read
144+ packages : write
145+
146+ steps :
147+ - uses : actions/checkout@v3
148+
149+ - name : Set up Docker Buildx
150+ uses : docker/setup-buildx-action@v2
151+
152+ - name : Log in to Container Registry
153+ uses : docker/login-action@v2
154+ with :
155+ registry : ${{ env.REGISTRY }}
156+ username : ${{ github.actor }}
157+ password : ${{ secrets.GITHUB_TOKEN }}
158+
159+ - name : Extract metadata
160+ id : meta
161+ uses : docker/metadata-action@v4
162+ with :
163+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
164+ tags : |
165+ type=ref,event=branch
166+ type=ref,event=pr
167+ type=semver,pattern={{version}}
168+ type=semver,pattern={{major}}.{{minor}}
169+ type=sha
170+
171+ - name : Build and push PowerShell image
172+ uses : docker/build-push-action@v4
173+ with :
174+ context : .
175+ file : ./Dockerfile.powershell
176+ push : true
177+ tags : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/powershell:latest
178+ cache-from : type=gha
179+ cache-to : type=gha,mode=max
180+
181+ - name : Build and push Python image
182+ uses : docker/build-push-action@v4
183+ with :
184+ context : .
185+ file : ./Dockerfile.python
186+ push : true
187+ tags : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/python:latest
188+ cache-from : type=gha
189+ cache-to : type=gha,mode=max
190+
191+ deploy-staging :
192+ needs : [build-docker, security-scan]
193+ runs-on : ubuntu-latest
194+ if : github.ref == 'refs/heads/develop'
195+ environment : staging
196+
197+ steps :
198+ - uses : actions/checkout@v3
199+
200+ - name : Deploy to Kubernetes (Staging)
201+ run : |
202+ echo "Deploying to staging environment..."
203+ # kubectl apply -f kubernetes/deployment.yaml -n staging
204+
205+ deploy-production :
206+ needs : [build-docker, security-scan]
207+ runs-on : ubuntu-latest
208+ if : github.ref == 'refs/heads/main'
209+ environment : production
210+
211+ steps :
212+ - uses : actions/checkout@v3
213+
214+ - name : Deploy to Kubernetes (Production)
215+ run : |
216+ echo "Deploying to production environment..."
217+ # kubectl apply -f kubernetes/deployment.yaml -n production
218+
219+ - name : Run smoke tests
220+ run : |
221+ echo "Running smoke tests..."
222+ # ./scripts/smoke-tests.sh
223+
224+ - name : Send deployment notification
225+ if : always()
226+ run : |
227+ echo "Sending notification..."
228+ # curl -X POST ${{ secrets.WEBHOOK_URL }} -d "Deployment status: ${{ job.status }}"
0 commit comments