From 77786e54125cfd0a46432183284f8c8f171091ff Mon Sep 17 00:00:00 2001 From: Yong woo Song Date: Wed, 24 Jan 2024 14:46:42 +0900 Subject: [PATCH 01/15] feat: add ci workflow using sonarqube --- .github/workflows/build.yml | 38 +++++++++++++++++++++++++++++++++++++ build.gradle | 7 +++++++ 2 files changed, 45 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..758a901 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,38 @@ +name: Build + +on: + push: + branches: + - main + + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 17 + uses: actions/setup-java@v1 + with: + java-version: 17 + - name: Cache SonarQube packages + uses: actions/cache@v1 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache Gradle packages + uses: actions/cache@v1 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Build and analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + run: ./gradlew build sonar --info \ No newline at end of file diff --git a/build.gradle b/build.gradle index 7fcdbba..e7e666f 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id 'java' id 'org.springframework.boot' version '3.2.1' id 'io.spring.dependency-management' version '1.1.4' + id "org.sonarqube" version "3.5.0.2730" } group = 'org.dnd' @@ -45,3 +46,9 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + +sonar { + properties { + property "sonar.projectKey", "dnd-10th-2-backend" + } +} \ No newline at end of file From 349965559d58a2771596004b1f45f6f4223a6bf3 Mon Sep 17 00:00:00 2001 From: Yong woo Song Date: Thu, 25 Jan 2024 00:26:39 +0900 Subject: [PATCH 02/15] feat: add test profile and in-memory h2 db --- .github/workflows/build.yml | 13 +++++++++---- .gitignore | 1 + build.gradle | 3 ++- .../dnd/modutimer/ModutimerApplicationTests.java | 2 ++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 758a901..6142d39 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,9 +1,6 @@ name: Build -on: - push: - branches: - - main +on: [pull_request] jobs: @@ -18,6 +15,14 @@ jobs: uses: actions/setup-java@v1 with: java-version: 17 + - name: Make application-prod.yml + run: | + touch src/main/resources/application-prod.yml + echo "${{ secrets.APPLICATION_PROD }}" > src/main/resources/application-prod.yml + - name: Make application-test.yml + run: | + touch src/main/resources/application-test.yml + echo "${{ secrets.APPLICATION_TEST }}" > src/main/resources/application-test.yml - name: Cache SonarQube packages uses: actions/cache@v1 with: diff --git a/.gitignore b/.gitignore index 8300fc8..401c4ee 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ build/ **/application-local.yml **/application-prod.yml +**/application-test.yml ### IntelliJ IDEA ### .idea diff --git a/build.gradle b/build.gradle index e7e666f..544ea1e 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java' id 'org.springframework.boot' version '3.2.1' id 'io.spring.dependency-management' version '1.1.4' - id "org.sonarqube" version "3.5.0.2730" + id "org.sonarqube" version "4.0.0.2929" } group = 'org.dnd' @@ -37,6 +37,7 @@ dependencies { annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' + testRuntimeOnly 'com.h2database:h2' // third-party implementation group: 'com.auth0', name: 'java-jwt', version: '4.3.0' diff --git a/src/test/java/org/dnd/modutimer/ModutimerApplicationTests.java b/src/test/java/org/dnd/modutimer/ModutimerApplicationTests.java index 4b7a3d8..1064116 100644 --- a/src/test/java/org/dnd/modutimer/ModutimerApplicationTests.java +++ b/src/test/java/org/dnd/modutimer/ModutimerApplicationTests.java @@ -2,8 +2,10 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; @SpringBootTest +@TestPropertySource(properties = {"spring.config.location = classpath:application-test.yml"}) class ModutimerApplicationTests { @Test From 3068c57744de53fdd85a4cffc1564df9d79c85df Mon Sep 17 00:00:00 2001 From: Yong woo Song Date: Thu, 25 Jan 2024 00:29:36 +0900 Subject: [PATCH 03/15] chore: add workflow-dispatch for triggering manually --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6142d39..b620654 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,6 @@ name: Build -on: [pull_request] +on: [pull_request, workflow_dispatch] jobs: From fa0d3b0d08613e042730f50e5f6a85ce90029210 Mon Sep 17 00:00:00 2001 From: Yong woo Song Date: Thu, 25 Jan 2024 00:50:45 +0900 Subject: [PATCH 04/15] chore: fix user table name for h2 db reserved word --- src/main/java/org/dnd/modutimer/user/domain/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/dnd/modutimer/user/domain/User.java b/src/main/java/org/dnd/modutimer/user/domain/User.java index 4510392..5f7c525 100644 --- a/src/main/java/org/dnd/modutimer/user/domain/User.java +++ b/src/main/java/org/dnd/modutimer/user/domain/User.java @@ -11,7 +11,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter @Entity -@Table(name = "user") +@Table(name = "users") @Where(clause = "is_deleted=0") @AttributeOverride(name = "id", column = @Column(name = "user_id")) public class User extends AbstractJpaEntity { From 7f6e2888c83243b34cf4023fda14e9b8d9389e9f Mon Sep 17 00:00:00 2001 From: Yong woo Song Date: Thu, 25 Jan 2024 01:22:39 +0900 Subject: [PATCH 05/15] chore: update build workflow for gradle clean --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b620654..a663206 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,4 +40,4 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} - run: ./gradlew build sonar --info \ No newline at end of file + run: ./gradlew clean build sonar --info From 9b7c934cfa431004df4e053edd1020ac0e0b29a7 Mon Sep 17 00:00:00 2001 From: Yong woo Song Date: Thu, 25 Jan 2024 01:31:42 +0900 Subject: [PATCH 06/15] chore: fix profile for ci/cd testing --- src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d963877..6b0116f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,4 +1,4 @@ spring: profiles: active: - - local + - test From 77fc23887844c8db88f5d277dfa667daa1dd3b60 Mon Sep 17 00:00:00 2001 From: Yong woo Song Date: Thu, 25 Jan 2024 01:36:41 +0900 Subject: [PATCH 07/15] chore: fix profile for ci/cd testing --- src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d963877..6b0116f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,4 +1,4 @@ spring: profiles: active: - - local + - test From 21751f3066f9008dd1b16bd6699f465710bfe730 Mon Sep 17 00:00:00 2001 From: Yong woo Song Date: Thu, 25 Jan 2024 01:44:26 +0900 Subject: [PATCH 08/15] feat: update build workflow for base64 encode --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a663206..cf02042 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,11 +18,11 @@ jobs: - name: Make application-prod.yml run: | touch src/main/resources/application-prod.yml - echo "${{ secrets.APPLICATION_PROD }}" > src/main/resources/application-prod.yml + echo "${{ secrets.APPLICATION_PROD }}" | base64 --decode > src/main/resources/application-prod.yml - name: Make application-test.yml run: | touch src/main/resources/application-test.yml - echo "${{ secrets.APPLICATION_TEST }}" > src/main/resources/application-test.yml + echo "${{ secrets.APPLICATION_TEST }}" | base64 --decode > src/main/resources/application-test.yml - name: Cache SonarQube packages uses: actions/cache@v1 with: From 90d8347f3df02484914027abed5ff57ccce1c4f4 Mon Sep 17 00:00:00 2001 From: Yong woo Song Date: Thu, 25 Jan 2024 01:57:14 +0900 Subject: [PATCH 09/15] chore: update build workflow for debug --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cf02042..663d62a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,6 +23,7 @@ jobs: run: | touch src/main/resources/application-test.yml echo "${{ secrets.APPLICATION_TEST }}" | base64 --decode > src/main/resources/application-test.yml + cat src/main/resources/application-test.yml - name: Cache SonarQube packages uses: actions/cache@v1 with: From 65a5049e24891473b8fdd443b817181f2478acc1 Mon Sep 17 00:00:00 2001 From: Yong woo Song Date: Thu, 25 Jan 2024 02:06:46 +0900 Subject: [PATCH 10/15] chore: update build workflow for debug --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 663d62a..798665e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: run: | touch src/main/resources/application-test.yml echo "${{ secrets.APPLICATION_TEST }}" | base64 --decode > src/main/resources/application-test.yml - cat src/main/resources/application-test.yml + echo "cat src/main/resources/application-test.yml" - name: Cache SonarQube packages uses: actions/cache@v1 with: From aa9e5af898d12b8a40c38ef9257e4608e9e22cae Mon Sep 17 00:00:00 2001 From: Yong woo Song Date: Thu, 25 Jan 2024 02:20:20 +0900 Subject: [PATCH 11/15] chore: update build workflow for debug --- .github/workflows/build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 798665e..89cef03 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,11 @@ jobs: run: | touch src/main/resources/application-test.yml echo "${{ secrets.APPLICATION_TEST }}" | base64 --decode > src/main/resources/application-test.yml - echo "cat src/main/resources/application-test.yml" + cat src/main/resources/application-test.yml >> "$GITHUB_OUTPUT" + - uses: actions/upload-artifact@v2 + with: + name: application-test.yml + path: src/main/resources/application-test.yml - name: Cache SonarQube packages uses: actions/cache@v1 with: From b7b697ca1a0ea5f70d16fdd81d5fafa1bab56ef6 Mon Sep 17 00:00:00 2001 From: Yong woo Song Date: Thu, 25 Jan 2024 02:28:04 +0900 Subject: [PATCH 12/15] chore: update build workflow for debug --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 89cef03..b5235ce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,6 @@ jobs: run: | touch src/main/resources/application-test.yml echo "${{ secrets.APPLICATION_TEST }}" | base64 --decode > src/main/resources/application-test.yml - cat src/main/resources/application-test.yml >> "$GITHUB_OUTPUT" - uses: actions/upload-artifact@v2 with: name: application-test.yml From a62ae8976de05e2e4d5771eb0aaa896dba00ed68 Mon Sep 17 00:00:00 2001 From: Yong woo Song Date: Thu, 25 Jan 2024 02:34:32 +0900 Subject: [PATCH 13/15] chore: fix profile for ci/cd testing --- src/main/java/org/dnd/modutimer/user/domain/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/dnd/modutimer/user/domain/User.java b/src/main/java/org/dnd/modutimer/user/domain/User.java index 5f7c525..4510392 100644 --- a/src/main/java/org/dnd/modutimer/user/domain/User.java +++ b/src/main/java/org/dnd/modutimer/user/domain/User.java @@ -11,7 +11,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter @Entity -@Table(name = "users") +@Table(name = "user") @Where(clause = "is_deleted=0") @AttributeOverride(name = "id", column = @Column(name = "user_id")) public class User extends AbstractJpaEntity { From 72df53feefdccba232097e427ccd5d1ef5f18782 Mon Sep 17 00:00:00 2001 From: Yong woo Song Date: Thu, 25 Jan 2024 02:39:34 +0900 Subject: [PATCH 14/15] chore: remove unused build workflow task --- .github/workflows/build.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b5235ce..cf02042 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,10 +23,6 @@ jobs: run: | touch src/main/resources/application-test.yml echo "${{ secrets.APPLICATION_TEST }}" | base64 --decode > src/main/resources/application-test.yml - - uses: actions/upload-artifact@v2 - with: - name: application-test.yml - path: src/main/resources/application-test.yml - name: Cache SonarQube packages uses: actions/cache@v1 with: From ae847b4a8d963ec4157afa7c93226a9cc1cbe362 Mon Sep 17 00:00:00 2001 From: FacerAin Date: Sat, 27 Jan 2024 17:12:18 +0900 Subject: [PATCH 15/15] chore: update table name user to member for reserved word --- src/main/java/org/dnd/modutimer/user/domain/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/dnd/modutimer/user/domain/User.java b/src/main/java/org/dnd/modutimer/user/domain/User.java index 4510392..1d108f0 100644 --- a/src/main/java/org/dnd/modutimer/user/domain/User.java +++ b/src/main/java/org/dnd/modutimer/user/domain/User.java @@ -11,7 +11,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter @Entity -@Table(name = "user") +@Table(name = "member") @Where(clause = "is_deleted=0") @AttributeOverride(name = "id", column = @Column(name = "user_id")) public class User extends AbstractJpaEntity {