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

Fj 2024 lesson 14 #12

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ed266fa
lesson 14: init GitHub action workflow for currency-app
Daniil-Vl Nov 14, 2024
6926b24
lesson 14: add working-directory to build step in currency-app-workfl…
Daniil-Vl Nov 14, 2024
3c82537
lesson 14: add read permission in currency-app-workflow.yml
Daniil-Vl Nov 14, 2024
4569c67
lesson 14: make gradlew file executable in currency-app-workflow.yml
Daniil-Vl Nov 14, 2024
4de0d27
lesson 14: fix CurrencyServiceImplTest
Daniil-Vl Nov 14, 2024
d11da74
lesson 14: add jacoco test coverage report to currency-app-workflow.yml
Daniil-Vl Nov 14, 2024
227b80c
lesson 14: remove update-comment: true option in jacoco test report i…
Daniil-Vl Nov 14, 2024
cf23852
lesson 14: change jacoco report version
Daniil-Vl Nov 14, 2024
da37a4f
lesson 14: add debug-mode in jacoco report
Daniil-Vl Nov 14, 2024
74bd806
lesson 14: add contents: write permission to build job in currency-ap…
Daniil-Vl Nov 14, 2024
e504d68
lesson 14: add post test comment job to test commenting in currency-a…
Daniil-Vl Nov 14, 2024
d3075c6
lesson 14: change jacoco report version to 1.7.1 in currency-app-wor…
Daniil-Vl Nov 14, 2024
3833f07
lesson 14: change event trigger from `push` to `pull_request`
Daniil-Vl Nov 14, 2024
7e920f6
lesson 14: clean currency-app-workflow.yml
Daniil-Vl Nov 14, 2024
fc489b0
lesson 14: create spring-app-workflow.yml with gradle build and jacoc…
Daniil-Vl Nov 14, 2024
728ba1d
lesson 14: add checkstyle.xml
Daniil-Vl Nov 14, 2024
eb5bc0b
lesson 14: add checkstyle plugin to currency-app
Daniil-Vl Nov 14, 2024
2005191
lesson 14: add checkstyle to currency-app-workflow.yml
Daniil-Vl Nov 14, 2024
e4fdf37
lesson 14: fix checkstyle in currency-app-workflow.yml
Daniil-Vl Nov 14, 2024
175f661
lesson 14: fix styles for currency-app
Daniil-Vl Nov 14, 2024
e64ccca
lesson 14: add checkstyle to spring-app-workflow.yml
Daniil-Vl Nov 14, 2024
653d85b
lesson 14: fix styles in currency-app tests
Daniil-Vl Nov 14, 2024
0077674
lesson 14: fix checkstyle command in both workflows
Daniil-Vl Nov 14, 2024
1774a35
lesson 14: remove checkstyleTest from workflows
Daniil-Vl Nov 14, 2024
58a1ee7
lesson 14: fix styles in spring app
Daniil-Vl Nov 14, 2024
d2664ff
lesson 14: add docker files and create docker image building procedur…
Daniil-Vl Nov 14, 2024
5717a8d
lesson 14: fix styles for spring-app
Daniil-Vl Nov 14, 2024
3ae1190
lesson 14: exclude checkstyle tasks from build task in workflows
Daniil-Vl Nov 14, 2024
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: 80 additions & 0 deletions .github/workflows/currency-app-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Currency App Build

on:
pull_request:
paths:
- .github/workflows/currency-app-workflow.yml
- currency-app/**

jobs:
build:
runs-on: ubuntu-latest
name: Build
permissions:
contents: write
packages: write
pull-requests: write

steps:
- uses: actions/checkout@v4
- name: Set up Jdk 21
uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "temurin"

- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582

- name: Make gradlew executable
working-directory: currency-app
run: chmod +x ./gradlew

- name: Build with Gradle Wrapper
working-directory: currency-app
run: ./gradlew build -x checkstyleMain -x checkstyleTest

- id: jacoco
uses: madrapps/jacoco-report@v1.7.1
with:
paths: ${{ github.workspace }}/currency-app/build/reports/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 50
min-coverage-changed-files: 50
title: Code Coverage

- name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build docker image
uses: docker/build-push-action@v5
with:
context: currency-app
push: true
tags: ghcr.io/daniil-vl/currency-app:latest

checkstyle:
name: checkstyle
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Jdk 21
uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "temurin"

- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582

- name: Make gradlew executable
working-directory: currency-app
run: chmod +x ./gradlew

- run: ./gradlew checkstyleMain
working-directory: currency-app
80 changes: 80 additions & 0 deletions .github/workflows/spring-app-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Spring App Build

on:
pull_request:
paths:
- .github/workflows/spring-app-workflow.yml
- spring-app/**

jobs:
build:
runs-on: ubuntu-latest
name: Build
permissions:
contents: write
packages: write
pull-requests: write

steps:
- uses: actions/checkout@v4
- name: Set up Jdk 21
uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "temurin"

- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582

- name: Make gradlew executable
working-directory: spring-app
run: chmod +x ./gradlew

- name: Build with Gradle Wrapper
working-directory: spring-app
run: ./gradlew build -x checkstyleMain -x checkstyleTest

- id: jacoco
uses: madrapps/jacoco-report@v1.7.1
with:
paths: ${{ github.workspace }}/spring-app/build/reports/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 50
min-coverage-changed-files: 50
title: Code Coverage

- name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build docker image
uses: docker/build-push-action@v5
with:
context: spring-app
push: true
tags: ghcr.io/daniil-vl/spring-app:latest

checkstyle:
name: checkstyle
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Jdk 21
uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "temurin"

- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582

- name: Make gradlew executable
working-directory: spring-app
run: chmod +x ./gradlew

- run: ./gradlew checkstyleMain
working-directory: spring-app
24 changes: 24 additions & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<!--
Checkstyle configuration
-->
<module name="Checker">

<property name="charset" value="UTF-8"/>
<property name="fileExtensions" value="java"/>

<module name="NewlineAtEndOfFile"/>

<module name="TreeWalker">
<module name="MissingOverride"/>

<!-- Imports -->
<module name="AvoidStarImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>
</module>

</module>
3 changes: 3 additions & 0 deletions currency-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM openjdk:21
ADD ./build/libs/currency-app-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT java -jar app.jar
35 changes: 35 additions & 0 deletions currency-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.3.4'
id 'io.spring.dependency-management' version '1.1.6'
id 'jacoco'
id 'checkstyle'
}

group = 'ru.tbank'
Expand Down Expand Up @@ -60,4 +62,37 @@ dependencies {

tasks.named('test') {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

checkstyle {
toolVersion = "10.12.4"
configFile file("../config/checkstyle/checkstyle.xml")
ignoreFailures = false
maxWarnings = 0
maxErrors = 0
}

checkstyleMain {
source = 'src/main/java'
}

checkstyleTest {
source = 'src/test/java'
}

jacocoTestReport {
dependsOn test

reports {
xml.required = true
}

afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect(({
fileTree(dir: it, exclude: [
"**/dto/**"
])
}))))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import ru.tbank.currencyapp.dto.CurrencyConvertRequestDTO;
import ru.tbank.currencyapp.dto.CurrencyConvertedDTO;
import ru.tbank.currencyapp.dto.CurrencyRateDTO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public record CurrencyRateDTO(
String currency,
BigDecimal rate
) {
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package ru.tbank.currencyapp.dto.cb;

import jakarta.xml.bind.annotation.*;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
import lombok.ToString;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import jakarta.validation.Payload;
import ru.tbank.currencyapp.validation.validators.CurrencyValidator;

import java.lang.annotation.*;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Documented
@Constraint(validatedBy = {CurrencyValidator.class})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@
import java.time.format.DateTimeFormatter;
import java.util.Map;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.any;
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;

//import static com.github.tomakehurst.wiremock.client.WireMock.*;

@SpringBootTest(properties = {"spring.main.allow-bean-definition-overriding=true"})
@WireMockTest
Expand Down Expand Up @@ -103,4 +110,4 @@ public WebClient webClient(WireMockServer server) {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,4 @@ void givenUnavailableCentralBankApi_whenConvertCurrency_thenReturnApiErrorWithSe
);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void givenValidCurrenciesAndValidAmount_whenConvertCurrencies_thenSuccessfullyCo
String fromCurrency = "USD";
String toCurrency = "RUB";
BigDecimal amount = new BigDecimal("3.0");
BigDecimal expected = new BigDecimal("90.0");
BigDecimal expected = new BigDecimal("90.000000");

CurrencyConvertedDTO actual = currencyService.convertCurrencies(fromCurrency, toCurrency, amount);

Expand All @@ -79,4 +79,4 @@ void givenNonExistentCurrencyCode_whenConvertCurrencies_thenThrowCurrencyNotFoun
Assertions.assertThrows(CurrencyNotFoundException.class, () -> currencyService.convertCurrencies(fromCurrency, toCurrency, amount));
}

}
}
3 changes: 3 additions & 0 deletions spring-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM openjdk:21
ADD ./build/libs/spring-app-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT java -jar app.jar
21 changes: 21 additions & 0 deletions spring-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'org.springframework.boot' version '3.3.4'
id 'io.spring.dependency-management' version '1.1.6'
id 'jacoco'
id 'checkstyle'
}

group = 'ru.tbank'
Expand Down Expand Up @@ -50,9 +51,29 @@ tasks.named('test') {
finalizedBy jacocoTestReport
}

checkstyle {
toolVersion = "10.12.4"
configFile file("../config/checkstyle/checkstyle.xml")
ignoreFailures = false
maxWarnings = 0
maxErrors = 0
}

checkstyleMain {
source = 'src/main/java'
}

checkstyleTest {
source = 'src/test/java'
}

jacocoTestReport {
dependsOn test

reports {
xml.required = true
}

afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect(({
fileTree(dir: it, exclude: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package ru.tbank.springapp.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ru.tbank.springapp.aspect.Timed;
import ru.tbank.springapp.dto.CategoryDTO;
import ru.tbank.springapp.model.Category;
Expand Down
Loading