Skip to content

Commit 21f8ffc

Browse files
Create main.yml
1 parent b50a3eb commit 21f8ffc

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

.github/workflows/main.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Maven CI Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch: # Allows for manual trigger
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest # GitHub-hosted runner (e.g., Ubuntu)
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
20+
- name: Set up JDK 11
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: '11' # Set to JDK 11
24+
distribution: 'adopt'
25+
26+
- name: Cache Maven dependencies
27+
uses: actions/cache@v3
28+
with:
29+
path: ~/.m2/repository
30+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
31+
restore-keys: |
32+
${{ runner.os }}-maven-
33+
34+
- name: Build with Maven
35+
run: mvn clean install
36+
37+
- name: Run Maven tests
38+
run: mvn test # Run all the test cases using Maven Surefire Plugin
39+
40+
- name: Convert Maven test reports to CSV
41+
run: |
42+
# Create a directory to store the CSV file
43+
mkdir -p test-results
44+
# Convert Surefire XML reports to CSV format
45+
# Using xmlstarlet to parse XML and convert it into CSV format
46+
xmlstarlet sel -T -t -m "//testcase" -v "concat(@classname, ',', @name, ',', string(testcase/@time), '\n')" -n target/surefire-reports/*.xml > test-results/test_results.csv
47+
# Display the generated CSV (for debugging)
48+
cat test-results/test_results.csv
49+
50+
- name: Upload CSV test results
51+
uses: actions/upload-artifact@v3
52+
with:
53+
name: test-results-csv
54+
path: test-results/test_results.csv # Upload the CSV test results file
55+
56+
- name: Upload JAR artifact
57+
uses: actions/upload-artifact@v3
58+
with:
59+
name: SampleCode-jar
60+
path: target/SampleCode.jar # Adjust path if needed
61+
62+
- name: Upload test results (Surefire)
63+
uses: actions/upload-artifact@v3
64+
with:
65+
name: surefire-reports
66+
path: target/surefire-reports # Upload Surefire test reports
67+
68+
- name: Add summary to download the test results CSV
69+
run: |
70+
echo "### [Download the test results CSV](https://github.com/${{ github.repository }}/suites/${{ github.run_id }}/artifacts)" >> $GITHUB_STEP_SUMMARY
71+

0 commit comments

Comments
 (0)