forked from jboulon/influent
-
Notifications
You must be signed in to change notification settings - Fork 1
373 lines (327 loc) · 11.7 KB
/
agro-maven.yml
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
name: Aggressive Maven CI/CD Pipeline
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: '0 3 * * *' # Runs daily at 3 AM UTC
workflow_dispatch: # Allows manual trigger
jobs:
# Job 1: Build the Project
build:
runs-on: ubuntu-latest
name: Build Project
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set Up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
cache: maven
- name: Display Java Version
run: java -version
- name: Maven Clean and Compile
run: mvn clean compile -fn
- name: Upload Build Logs
if: always()
uses: actions/upload-artifact@v3
with:
name: build-logs
path: target/build.log
- name: Notify Build Issues
if: failure()
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.example.com
server_port: 587
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: 'Build Job Encountered Issues'
body: |
The build job has completed with issues. Please check the workflow logs for details.
to: your-email@example.com
from: github-actions@example.com
# Job 2: Manage Maven Dependencies
manage-dependencies:
needs: build
runs-on: ubuntu-latest
name: Manage Maven Dependencies
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set Up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
cache: maven
- name: Generate Dependency Tree
run: mvn dependency:tree -fn -DoutputType=dot -DoutputFile=dependency-tree.dot
- name: Upload Dependency Tree
if: always()
uses: actions/upload-artifact@v3
with:
name: dependency-tree
path: dependency-tree.dot
- name: Analyze Dependencies
run: |
mvn dependency:analyze -fn > dependency-analysis.txt || echo "Dependency analysis failed, but continuing"
- name: Upload Dependency Analysis Report
if: always()
uses: actions/upload-artifact@v3
with:
name: dependency-analysis
path: dependency-analysis.txt
- name: Attempt to Auto-Fix Missing Dependencies
if: failure()
run: |
# Example: Automatically add missing dependencies (Requires custom scripting)
# This is a placeholder for actual implementation
echo "Attempting to auto-fix missing dependencies..."
# Implement logic to parse dependency-analysis.txt and update pom.xml
# For example, using sed, awk, or a custom script to insert dependencies
# WARNING: Automated POM modifications can introduce instability
- name: Commit and Push Auto-Fixes
if: failure()
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Auto-fix missing dependencies via GitHub Actions"
branch: main
file_pattern: pom.xml
- name: Notify Dependency Issues
if: failure()
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.example.com
server_port: 587
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: 'Maven Dependency Issues Detected'
body: |
The Maven dependency management has encountered issues. Auto-fix attempts have been made.
Please review the dependency-analysis.txt and the updated pom.xml for details.
to: your-email@example.com
from: github-actions@example.com
- name: Create GitHub Issue for Dependency Issues
if: failure()
uses: peter-evans/create-issue-from-file@v3
with:
title: 'Maven Dependency Issues Detected'
content-file: dependency-analysis.txt
labels: dependency, issue
# Job 3: Run Unit Tests
unit-tests:
needs: manage-dependencies
runs-on: ubuntu-latest
strategy:
matrix:
java-version: [8, 11, 17]
name: Run Unit Tests on Java ${{ matrix.java-version }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set Up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ matrix.java-version }}
cache: maven
- name: Maven Test with Retries
run: |
for i in {1..3}; do
mvn test -fn && break || sleep 15
done
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v3
with:
name: unit-test-results-java-${{ matrix.java-version }}
path: target/surefire-reports/
- name: Notify Unit Test Issues
if: failure()
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.example.com
server_port: 587
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: 'Unit Tests Encountered Issues'
body: |
The unit tests on Java ${{ matrix.java-version }} have completed with issues. Please check the workflow logs for details.
to: your-email@example.com
from: github-actions@example.com
# Job 4: Run Integration Tests
integration-tests:
needs: manage-dependencies
runs-on: ubuntu-latest
name: Run Integration Tests
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set Up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
cache: maven
- name: Maven Integration Test with Retries
run: |
for i in {1..3}; do
mvn verify -P integration-tests -fn && break || sleep 15
done
- name: Upload Integration Test Results
if: always()
uses: actions/upload-artifact@v3
with:
name: integration-test-results
path: target/failsafe-reports/
- name: Notify Integration Test Issues
if: failure()
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.example.com
server_port: 587
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: 'Integration Tests Encountered Issues'
body: |
The integration tests have completed with issues. Please check the workflow logs for details.
to: your-email@example.com
from: github-actions@example.com
# Job 5: Code Analysis
code-analysis:
needs: manage-dependencies
runs-on: ubuntu-latest
name: Static Code Analysis
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set Up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
- name: Maven Code Analysis with SpotBugs
run: mvn spotbugs:check -fn
continue-on-error: true # Allows this step to fail without failing the job
- name: Upload SpotBugs Report
if: always()
uses: actions/upload-artifact@v3
with:
name: spotbugs-report
path: target/spotbugs/
- name: Notify Code Analysis Issues
if: failure()
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.example.com
server_port: 587
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: 'Code Analysis Encountered Issues'
body: |
The static code analysis has completed with issues. Please check the workflow logs for details.
to: your-email@example.com
from: github-actions@example.com
# Job 6: Package the Application
package:
needs: [unit-tests, integration-tests, code-analysis]
runs-on: ubuntu-latest
name: Package Application
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set Up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
cache: maven
- name: Maven Package
run: mvn package -fn
- name: Upload Package Artifact
if: always()
uses: actions/upload-artifact@v3
with:
name: packaged-artifact
path: target/*.jar
- name: Notify Packaging Issues
if: failure()
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.example.com
server_port: 587
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: 'Packaging Encountered Issues'
body: |
The packaging step has completed with issues. Please check the workflow logs for details.
to: your-email@example.com
from: github-actions@example.com
# Job 7: Deploy the Application
deploy:
needs: package
runs-on: ubuntu-latest
name: Deploy Application
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set Up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
- name: Download Packaged Artifact
uses: actions/download-artifact@v3
with:
name: packaged-artifact
path: deploy/
- name: Deploy to Server
env:
DEPLOYMENT_SERVER: ${{ secrets.DEPLOYMENT_SERVER }}
DEPLOYMENT_USER: ${{ secrets.DEPLOYMENT_USER }}
DEPLOYMENT_KEY: ${{ secrets.DEPLOYMENT_KEY }}
run: |
# Ensure SSH key has proper permissions
mkdir -p ~/.ssh
echo "$DEPLOYMENT_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
# Add server to known hosts to prevent prompt
ssh-keyscan $DEPLOYMENT_SERVER >> ~/.ssh/known_hosts
# Securely copy the JAR to the deployment server
scp deploy/*.jar $DEPLOYMENT_USER@$DEPLOYMENT_SERVER:/path/to/deploy/
# Execute deployment commands on the server
ssh -i ~/.ssh/id_rsa $DEPLOYMENT_USER@$DEPLOYMENT_SERVER 'bash -s' <<'ENDSSH'
cd /path/to/deploy/
pkill -f your-application.jar || true
nohup java -jar your-application.jar > application.log 2>&1 &
ENDSSH || echo "Deployment commands failed, but continuing"
- name: Notify Deployment Success
if: success()
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.example.com
server_port: 587
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: 'Deployment Successful'
body: |
The application has been successfully deployed to ${{ secrets.DEPLOYMENT_SERVER }}.
to: your-email@example.com
from: github-actions@example.com
- name: Notify Deployment Failure
if: failure()
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.example.com
server_port: 587
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: 'Deployment Failed'
body: |
The deployment to ${{ secrets.DEPLOYMENT_SERVER }} has failed. Please check the workflow logs for details.
to: your-email@example.com
from: github-actions@example.com