Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIS-23 & SIS-25: Updated CI to generate and save test reports #5

Merged
merged 11 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 56 additions & 24 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,93 @@
# This workflow will build a Java Spring Boot Application with Maven, and run test cases.
# This workflow will build a Java Spring Boot Application with Maven then run test cases.
name: Build and Test Java Spring Boot Application

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
run-unit-tests:
build-and-run-tests:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:latest
image: postgres:latest

env:
POSTGRES_USER: postgres
# POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_DB: smart_inventory
# Set health checks to wait until postgres has started.

# Set health checks to wait until Postgres has started.
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

ports:
# Maps tcp port 5432 on service container to the host.
# Maps the TCP port 5432 on the service container to the host.
- 5432:5432

steps:
- name: Pull repository
uses: actions/[email protected]

- name: Set up JDK
uses: actions/[email protected]
with:
java-version: '21'
distribution: 'temurin'
# cache: maven # Uncomment and configure if needed.

- name: Run unit tests
run: mvn test

# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive.
java-version: "17"
distribution: "temurin"
# Uncomment and configure if needed.
# cache: maven

# The Maven basic phases in order: Validate, Compile, Test, Package, Verify, Install, Deploy.
# The verify command executes each default lifecycle phase in order (validate, compile, package, etc.), before executing verify.
# In most cases the effect is the same as package. However, in case there are integration tests, these will be executed as well.
# During the verify phase some additional checks can be done, e.g. if your code is written according to the predefined checkstyle rules.
# If you want to run your integration tests and check it, use verify. If you only want to run unit tests, use test.
# This does not seem to generate HTML reports, just the normal text reports.
- name: Build and run unit tests
# run: mvn test
run: mvn verify

- name: Generate HTML test report
# This does not rebuild, and uses the last successful build, to the test cases might not be updated.
run: mvn surefire-report:report

# Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive (Optional).
# - name: Update dependency graph
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6

- name: Build Jar file
run: mvn package -DskipTests # Skip tests since they were already run.

- name: Save Jar file
# - name: Build Jar file
# # Skip tests since they were already run.
# run: mvn package -DskipTests

- name: Save the Jar file test artifact
uses: actions/[email protected]
with:
name: smart-inventory-0.0.1-SNAPSHOT
path: target/smart-inventory-0.0.1-SNAPSHOT.jar
retention-days: 1
retention-days: 7

- name: Upload the test artifacts
uses: actions/[email protected]
if: ${{ always() }}
with:
name: test-report
# path: '**/target/*-reports/TEST*.xml'
path: "**/target/*-reports/**"
if-no-files-found: error
retention-days: 7

- name: Upload the HTML report test artifacts
uses: actions/[email protected]
if: ${{ always() }}
with:
name: html-test-report
path: "**/target/site/**"
if-no-files-found: error
retention-days: 7
67 changes: 42 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.3</version>
<relativePath/> <!-- lookup parent from repository -->
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>sg.com.smartinventory</groupId>
<artifactId>smart-inventory</artifactId>
Expand All @@ -21,7 +22,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand All @@ -30,7 +30,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<!-- <dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand All @@ -39,40 +38,58 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> </dependencies>

</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
</project>
21 changes: 18 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
spring.application.name=smart-inventory

# The default server port is 8080.
server.port=9090
# PostgreSQL
spring.datasource.url=jdbc:postgresql://localhost:5432/smart_inventory
Expand All @@ -9,7 +10,21 @@ spring.datasource.username=postgres
# Password can be blank if we set it to trust in pg_hba.conf
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
# this will drop and create tables again
# This will drop and create tables again.
spring.jpa.hibernate.ddl-auto=create
# this can be used to update tables
# spring.jpa.hibernate.ddl-auto=update
# This can be used to update tables.
# spring.jpa.hibernate.ddl-auto=update
# SpringDoc Configuration.
# The OpenAPI descriptions are at /v3/api-docs, which is the default path: http://localhost:8080/v3/api-docs.
# For a custom path of the OpenAPI documentation in Json format,
# add the custom springdoc property /api-docs endpoint custom path to get the path: http://localhost:8080/api-docs.
springdoc.api-docs.path=/api-docs
# The OpenAPI definitions are in JSON format by default. For yaml format, we can obtain the definitions at: http://localhost:8080/api-docs.yaml.
# To disable api-docs springdoc-openapi endpoints.
# springdoc.api-docs.enabled=false
# The springdoc-openapi dependency already includes Swagger UI, to integrate springdoc-openapi with Swagger UI to interact with our API specification and exercise the endpoints.# We can access the API documentation at: http://localhost:8080/swagger-ui/index.html.
# Using swagger-ui properties, to customize the path of the swagger-ui API documentation swagger-ui-custom.html to get the path: http://localhost:8080/swagger-ui-custom.html.
# springdoc.swagger-ui.path=/swagger-ui-custom.html
springdoc.swagger-ui.path=/swagger-ui.html
# To sort the API paths according to their HTTP methods with the springdoc.swagger-ui.operationsSorter property.
# springdoc.swagger-ui.operationsSorter=method