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

[OING-26] chore: CI/CD 파이프라인 워크플로우 개선 #15

Merged
merged 2 commits into from
Nov 26, 2023
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
41 changes: 41 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ on:
required: true
REMOTE_SSH_PORT:
required: true
SLACK_WEBHOOK_URL:
required: true
inputs:
environment:
required: true
Expand All @@ -32,6 +34,7 @@ on:
env:
IMAGE_TAG: ${{ inputs.image-tag || 'latest' }}
ACTIVE_PROFILE: ${{ inputs.spring-profile || 'local' }}
ENVIRONMENT: ${{ inputs.environment || 'local' }}

jobs:
deploy:
Expand All @@ -57,3 +60,41 @@ jobs:
port: ${{ secrets.REMOTE_SSH_PORT }}
script: |
docker service update --image ${{ inputs.image-name }}:${{ inputs.image-tag }} ${{ inputs.service-name }}

- name: 배포 완료 슬랙 알림 보내기
uses: 8398a7/action-slack@v3
with:
status: custom
fields: author, workflowRun, pullRequest
custom_payload: |
{
attachments: [{
color: '#59f764',
title: '백엔드 배포 알림',
text: `NO5ING 서버 새 리비전 배포 성공!`,
fields: [
{
title: '배포 환경',
value: `${process.env.ENVIRONMENT}`,
short: true,
},
{
title: '배포자',
value: `${process.env.AS_AUTHOR}`,
short: true,
},
{
title: '워크플로 링크',
value: `${process.env.AS_WORKFLOW_RUN}`,
short: true,
},
{
title: 'PR 링크',
value: `${process.env.AS_PULL_REQUEST}`,
short: true,
}
]
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
1 change: 1 addition & 0 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
REMOTE_SSH_KEY: ${{ secrets.REMOTE_SSH_KEY }}
REMOTE_SSH_PASSPHRASE: ${{ secrets.REMOTE_SSH_PASSPHRASE }}
REMOTE_SSH_PORT: ${{ secrets.REMOTE_SSH_PORT }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
image-tag: ${{ needs.prepare-variables.outputs.image-tag }}
spring-profile: ${{ needs.prepare-variables.outputs.spring-profile }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
REMOTE_SSH_KEY: ${{ secrets.REMOTE_SSH_KEY }}
REMOTE_SSH_PASSPHRASE: ${{ secrets.REMOTE_SSH_PASSPHRASE }}
REMOTE_SSH_PORT: ${{ secrets.REMOTE_SSH_PORT }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
image-tag: ${{ needs.prepare-variables.outputs.image-tag }}
spring-profile: ${{ needs.prepare-variables.outputs.spring-profile }}
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: 테스트 커버리지 워크플로우
on:
pull_request:
branches:
- master
- dev
- 'release/**'

env:
COVERAGE_PERCENT: 30

jobs:
measure:
runs-on: [ ubuntu-latest ]
steps:
- name: GitHub 에서 레포 받아오기
uses: actions/checkout@v3

- name: JDK17 준비하기
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Gradle 애드온 준비하기
uses: gradle/gradle-build-action@v2

- name: 커버리지 측정하기
run: |
chmod +x gradlew
./gradlew --info testCodeCoverageReport

- name: 테스트 결과 업로드
uses: EnricoMi/publish-unit-test-result-action@v2
if: ${{ always() }}
with:
files: |
common/build/test-results/**/*.xml
config/build/test-results/**/*.xml
member/build/test-results/**/*.xml

- name: 커버리지 결과 PR에 업로드
id: jacoco
uses: madrapps/[email protected]
with:
paths: ${{ github.workspace }}/config/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: ${{ env.COVERAGE_PERCENT }}
debug-mode: false
title: Code Coverage
update-comment: true

- name: 테스트 커버리지 미달시 워크플로우 블로킹
if: ${{ steps.jacoco.outputs.coverage-overall < env.COVERAGE_PERCENT }}
uses: actions/github-script@v6
with:
script: |
core.setFailed('전체 커버리지가 ${{ env.COVERAGE_PERCENT }}% 미만입니다!')
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.1.5'
id 'io.spring.dependency-management' version '1.1.3'
id 'jacoco-report-aggregation'
}

repositories {
Expand All @@ -17,6 +18,7 @@ subprojects {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'jacoco'
apply plugin: 'jacoco-report-aggregation'

configurations {
compileOnly {
Expand Down Expand Up @@ -72,6 +74,7 @@ subprojects {

violationRules {
rule {
failOnViolation = false
enabled = true
element = 'CLASS'

Expand Down
3 changes: 3 additions & 0 deletions config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ dependencies {
implementation project(':common')
implementation project(':member')

jacocoAggregation project(':common')
jacocoAggregation project(':member')

implementation 'org.flywaydb:flyway-core'
implementation 'org.flywaydb:flyway-mysql'
runtimeOnly 'com.h2database:h2'
Expand Down