Skip to content

Commit

Permalink
Merge pull request #2 from asavershin/add-actions
Browse files Browse the repository at this point in the history
Add actions
  • Loading branch information
asavershin authored Apr 7, 2024
2 parents efa5e0c + 673ec01 commit ddde0e0
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 25 deletions.
114 changes: 114 additions & 0 deletions .github/workflows/JavaMavenCI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Java CI with Maven

on:
pull_request:

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Compile with maven
run: mvn clean compile

- name: Update dependency graph
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6

checkstyle:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Compile with maven
run: mvn checkstyle:check

testing:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Compile maven project
run: mvn clean compile
- name: Test maven project
run: mvn test
- name: Add coverage to PR
id: jacoco
uses: madrapps/[email protected]
with:
paths: |
${{ github.workspace }}/**/target/site/jacoco/*.xml
token: ${{ secrets.TEST_SECRET }}
min-coverage-overall: 50
min-coverage-changed-files: 50
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: jacoco-report
path: ${{ github.workspace }}/**/target/site/jacoco/

- name: Fail PR if overall coverage is less than 50%
if: ${{ steps.jacoco.outputs.coverage-overall < 50.0 }}
uses: actions/github-script@v6
with:
script: |
core.setFailed('Overall coverage is less than 50%!')
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
-
name: Package
run: mvn clean package
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
context: ./api/.
push: true
tags: asavershin/api:latest
2 changes: 1 addition & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:22
FROM openjdk:21

WORKDIR /app

Expand Down
4 changes: 2 additions & 2 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<artifactId>api</artifactId>

<properties>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jooq.version>3.19.3</jooq.version>
<springdoc.starter.version>2.1.0</springdoc.starter.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.io.Serializable;
import java.util.List;
import java.util.UUID;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -63,17 +62,15 @@ public ImageId storeImage(final UserId userId,
),
multipartFile.getSize()
);
// TODO Why minio service store before postgreSQL?
var imageId = new ImageId(
UUID.fromString(minioService.saveFile(multipartFile))
);
var imageId = ImageId.nextIdentity();
storeImageOfUser.storeImageOfUser(
new Image(
imageId,
metaInfo,
userId
)
);
minioService.saveFile(multipartFile, imageId.value().toString());
return imageId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import java.util.List;

public interface FileService<T, K> {
public interface FileService<K> {
/**
* Saves a file to the storage.
*
* @param file The file object to be saved.
* @return The saved file object.
* @param file The file object to be saved.
* @param filename The name of the file to be saved.
* Must be unique.
*/
T saveFile(K file);
void saveFile(K file, String filename);
/**
* Retrieves the content of a file from the storage.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

import org.springframework.web.multipart.MultipartFile;

public interface MinioService extends FileService<String, MultipartFile> {
public interface MinioService extends FileService<MultipartFile> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import java.io.InputStream;
import java.util.List;
import java.util.UUID;

@Service
public class MinioServiceIml implements MinioService {
Expand Down Expand Up @@ -47,7 +46,7 @@ public MinioServiceIml(final MinioClient aMinioClient,
* Not final to allow spring use proxy.
*/
@Override
public String saveFile(final MultipartFile image) {
public void saveFile(final MultipartFile image, final String filename) {

if (!bucketExists(minioProperties.getBucket())) {
throw new FileException(
Expand All @@ -58,16 +57,14 @@ public String saveFile(final MultipartFile image) {
if (image.isEmpty() || image.getOriginalFilename() == null) {
throw new FileException("File must have name");
}
var link = generateFileName();
InputStream inputStream;
try {
inputStream = image.getInputStream();
} catch (Exception e) {
throw new FileException("File upload failed: "
+ e.getMessage());
}
saveImage(inputStream, link);
return link;
saveFile(inputStream, filename);
}
/**
* Not final to allow spring use proxy.
Expand Down Expand Up @@ -124,7 +121,7 @@ private void createBucket() {
}

@SneakyThrows
private void saveImage(
private void saveFile(
final InputStream inputStream,
final String fileName
) {
Expand All @@ -135,10 +132,6 @@ private void saveImage(
.build());
}

private String generateFileName() {
return UUID.randomUUID().toString();
}

@SneakyThrows(Exception.class)
private boolean bucketExists(final String bucketName) {
return minioClient.bucketExists(
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</modules>

<properties>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.projectlombok.version>1.18.30</org.projectlombok.version>
<maven-checkstyle-plugin.version>3.3.1</maven-checkstyle-plugin.version>
Expand Down

0 comments on commit ddde0e0

Please sign in to comment.