File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : CI
2+
3+ on :
4+ push :
5+ branches : [ master ]
6+ pull_request :
7+ branches : [ master ]
8+
9+ jobs :
10+ build :
11+ runs-on : ubuntu-latest
12+
13+ steps :
14+ - name : Checkout code
15+ uses : actions/checkout@v4
16+
17+ - name : Set up JDK 17
18+ uses : actions/setup-java@v4
19+ with :
20+ distribution : ' adopt'
21+ java-version : ' 17'
22+
23+ - name : Build with Gradle
24+ run : gradle build
25+
26+ - name : Upload Build Artifacts
27+ uses : actions/upload-artifact@v4
28+ with :
29+ name : build-artifacts
30+ path : build/libs/**
31+
32+ - name : Run Unit Test
33+ run : gradle test
34+
35+ - name : Upload Test Reports
36+ uses : actions/upload-artifact@v4
37+ with :
38+ name : test-reports
39+ path : build/reports/tests/**
40+ - name : Generate code coverage report
41+ run : gradle jacocoTestReport
42+
43+ - name : Upload code coverage report
44+ uses : actions/upload-artifact@v4
45+ with :
46+ name : code-coverage-report
47+ path : build/reports/jacoco/test/html/**
48+
49+ - name : Run Deployment
50+ run : java -jar build/libs/hello-world-java-V1.jar
Original file line number Diff line number Diff line change 1+ apply plugin : ' java'
2+ apply plugin :' jacoco'
3+ jacoco {
4+ toolVersion = " 0.8.7"
5+ }
6+ java {
7+ sourceCompatibility = JavaVersion . VERSION_1_8
8+ targetCompatibility = JavaVersion . VERSION_1_8
9+ }
10+ group = ' com.example'
11+ version = ' V1'
12+
13+ repositories {
14+ mavenCentral()
15+ }
16+
17+ dependencies {
18+ testImplementation ' junit:junit:4.13.2'
19+ }
20+
21+ test {
22+ // Specify the directory containing test classes
23+ testClassesDirs = sourceSets. test. output. classesDirs
24+
25+ // Optionally configure test options
26+ testLogging {
27+ // Configure which events to log during test execution
28+ events ' passed' , ' skipped' , ' failed'
29+ }
30+ finalizedBy jacocoTestReport
31+ }
32+
33+ jar {
34+ manifest {
35+ attributes ' Main-Class' : ' com.example.HelloWorld'
36+ }
37+
38+ from sourceSets. main. output // Include compiled classes in the JAR
39+ archiveBaseName = ' hello-world-java' // Name of the JAR file
40+ destinationDirectory = file(' build/libs' ) // Output directory for the JAR file
41+ }
42+
43+ jacocoTestReport {
44+ dependsOn test
45+ reports {
46+ xml. required = true
47+ html. required = true
48+ }
49+ }
Original file line number Diff line number Diff line change 1+ package com .example ;
2+
3+ public class HelloWorld {
4+ public static void main (String [] args ) {
5+ System .out .println ("Hello, World!" ); //comment
6+ }
7+
8+ public String getGreeting () {
9+ return "Hello, World!" ;
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ just sample
Original file line number Diff line number Diff line change 1+ package com .example ;
2+
3+ import org .junit .Test ;
4+ import static org .junit .Assert .*;
5+ public class HelloWorldTest {
6+ @ Test
7+ public void testGetGreeting () {
8+ HelloWorld helloWorld = new HelloWorld ();
9+ assertEquals ("Hello, World!" , helloWorld .getGreeting ());
10+ }
11+ }
You can’t perform that action at this time.
0 commit comments