|
1 | | -name: CI Pipeline |
| 1 | +name: CI Pipeline |
2 | 2 |
|
3 | | -on: |
| 3 | +on: |
4 | 4 | push: |
5 | | - branches: [ main, master, develop ] |
| 5 | + branches: [ "main" ] |
6 | 6 | pull_request: |
7 | | - branches: [ main, master, develop ] |
| 7 | + branches: [ "main" ] |
8 | 8 |
|
9 | 9 | jobs: |
10 | 10 | build: |
11 | 11 | runs-on: ubuntu-latest |
12 | | - |
13 | 12 | steps: |
14 | | - - name: Checkout code |
15 | | - uses: actions/checkout@v4 |
16 | | - |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + |
17 | 15 | - name: Set up JDK 17 |
18 | 16 | uses: actions/setup-java@v4 |
19 | 17 | with: |
20 | 18 | java-version: '17' |
21 | 19 | distribution: 'temurin' |
22 | 20 | cache: maven |
23 | | - |
24 | | - - name: Cache Maven dependencies |
25 | | - uses: actions/cache@v3 |
26 | | - with: |
27 | | - path: ~/.m2 |
28 | | - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} |
29 | | - restore-keys: ${{ runner.os }}-m2 |
30 | | - |
31 | | - - name: Build with Maven |
32 | | - run: mvn clean compile |
33 | | - working-directory: OtmTodoApp-master/OtmTodoApp-master |
34 | | - |
35 | | - - name: Run Tests |
36 | | - run: mvn test |
37 | | - working-directory: OtmTodoApp-master/OtmTodoApp-master |
38 | | - |
39 | | - - name: Generate Coverage Report |
40 | | - run: mvn jacoco:report |
41 | | - working-directory: OtmTodoApp-master/OtmTodoApp-master |
42 | | - |
43 | | - - name: Package Application |
44 | | - run: mvn package |
45 | | - working-directory: OtmTodoApp-master/OtmTodoApp-master |
46 | | - |
47 | | - - name: Build Docker image |
48 | | - run: docker build -t todoapp:${{ github.sha }} . |
| 21 | + |
| 22 | + - name: Build + Test + Package |
49 | 23 | working-directory: OtmTodoApp-master/OtmTodoApp-master |
50 | | - |
51 | | - - name: Test Docker image |
52 | | - run: | |
53 | | - docker run --rm todoapp:${{ github.sha }} --version || echo "Docker image built successfully" |
54 | | - |
55 | | - - name: Upload Test Results |
56 | | - uses: actions/upload-artifact@v3 |
57 | | - if: always() |
58 | | - with: |
59 | | - name: test-results |
60 | | - path: OtmTodoApp-master/OtmTodoApp-master/target/surefire-reports/ |
61 | | - |
62 | | - - name: Upload Coverage Reports |
63 | | - uses: actions/upload-artifact@v3 |
64 | | - if: always() |
65 | | - with: |
66 | | - name: coverage-reports |
67 | | - path: OtmTodoApp-master/OtmTodoApp-master/target/site/jacoco/ |
68 | | - |
69 | | - - name: Upload JAR Artifacts |
70 | | - uses: actions/upload-artifact@v3 |
71 | | - with: |
72 | | - name: jar-artifacts |
73 | | - path: OtmTodoApp-master/OtmTodoApp-master/target/*.jar |
74 | | - |
75 | | - - name: Comment PR with Test Results |
76 | | - if: github.event_name == 'pull_request' |
77 | | - uses: actions/github-script@v6 |
| 24 | + run: mvn -B clean test jacoco:report package |
| 25 | + |
| 26 | + - name: Update dependency graph (optional) |
| 27 | + uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 |
78 | 28 | with: |
79 | | - script: | |
80 | | - const fs = require('fs'); |
81 | | - const path = require('path'); |
82 | | - |
83 | | - // Read test results if available |
84 | | - let testSummary = '## 🧪 Test Results\n\n'; |
85 | | - try { |
86 | | - const surefireDir = 'OtmTodoApp-master/OtmTodoApp-master/target/surefire-reports'; |
87 | | - if (fs.existsSync(surefireDir)) { |
88 | | - const files = fs.readdirSync(surefireDir).filter(f => f.endsWith('.txt')); |
89 | | - if (files.length > 0) { |
90 | | - testSummary += '✅ All tests passed successfully!\n\n'; |
91 | | - testSummary += '**Test Summary:**\n'; |
92 | | - files.forEach(file => { |
93 | | - const content = fs.readFileSync(path.join(surefireDir, file), 'utf8'); |
94 | | - const lines = content.split('\n'); |
95 | | - const testCount = lines.filter(line => line.includes('Tests run:')).length; |
96 | | - if (testCount > 0) { |
97 | | - testSummary += `- ${file.replace('.txt', '')}: ${lines.find(line => line.includes('Tests run:'))}\n`; |
98 | | - } |
99 | | - }); |
100 | | - } |
101 | | - } |
102 | | - } catch (error) { |
103 | | - testSummary += '⚠️ Could not read test results\n'; |
104 | | - } |
105 | | - |
106 | | - github.rest.issues.createComment({ |
107 | | - issue_number: context.issue.number, |
108 | | - owner: context.repo.owner, |
109 | | - repo: context.repo.repo, |
110 | | - body: testSummary |
111 | | - }); |
| 29 | + directory: OtmTodoApp-master/OtmTodoApp-master |
0 commit comments