Skip to content
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
1 change: 1 addition & 0 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: ko-KR
reviews:
profile: chill
poem: false
fail_commit_status: true
auto_review:
enabled: true
base_branches:
Expand Down
16 changes: 16 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## 이슈

14-00

## 변경 내용

-

## 리뷰 포인트

-

## 체크리스트

- [ ] API를 추가·변경했으면 mock 컨트롤러도 맞췄다
- [ ] 테이블을 추가했으면 README 테이블 쓰기 담당 표에 적었다
31 changes: 29 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
# 공개 PR 로 바뀐 gradle-wrapper.jar 가 실행되지 않게 먼저 검증한다.
# v6 부터 setup-gradle 캐시에 별도 약관이 붙어, 약관 변경 전 v5 의 검증만 쓰고 캐시는 setup-java 로 한다.
# gradle-wrapper.jar 를 먼저 검증하고, Gradle 캐시는 setup-java 로 한다.
- uses: gradle/actions/wrapper-validation@v5
- uses: actions/setup-java@v6
with:
Expand All @@ -23,3 +22,31 @@ jobs:
cache: gradle
# Checkstyle, ArchUnit, 테스트(Testcontainers), 실행 jar 빌드
- run: ./gradlew check bootJar

# develop 으로 오는 PR 의 브랜치 이름과 커밋 메시지를 검사한다. 커밋마다 이슈 키를 넣는다.
naming:
if: github.event_name == 'pull_request' && github.base_ref == 'develop'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: 브랜치·커밋 이름 규칙
# 브랜치 이름은 환경변수로만 넘긴다.
env:
HEAD_REF: ${{ github.head_ref }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -eu
if ! printf '%s' "$HEAD_REF" | grep -Eq '^feature/[0-9]+-[0-9]+$'; then
echo "브랜치 이름이 규칙과 다르다: $HEAD_REF (feature/{이슈 키}, 예: feature/14-38)"; exit 1
fi
log=$(git log --format='%h %s' "$BASE_SHA..$HEAD_SHA")
bad=$(printf '%s\n' "$log" | grep -Ev '^[0-9a-f]+ (feat|fix|refactor|test|docs|chore)\([0-9]+-[0-9]+\): .+' || [ $? -eq 1 ])
if [ -n "$bad" ]; then
echo "커밋 메시지가 규칙과 다르다 ({타입}({이슈 키}): 요약, 예: feat(14-38): 엔티티 공통 규칙 추가):"
echo "$bad"
exit 1
fi
echo "브랜치·커밋 이름 규칙 통과"
42 changes: 42 additions & 0 deletions .github/workflows/discord.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Discord 알림

# PR 생성, develop·production·main 반영(머지), v* 태그 생성만 보낸다.
on:
pull_request:
types: [opened]
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
push:
branches: [develop, production, main]
tags: ['v*']

permissions:
contents: read

jobs:
notify:
if: github.event_name != 'push' || !github.event.deleted
runs-on: ubuntu-latest
steps:
- name: 메시지 보내기
# 사용자 입력(PR 제목, 커밋 메시지)은 jq 로만 다룬다.
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
run: |
set -eu
if [ -z "${DISCORD_WEBHOOK_URL:-}" ]; then
echo "::notice::DISCORD_WEBHOOK_URL 시크릿이 없어 알림을 보내지 않는다"; exit 0
fi
ev="$GITHUB_EVENT_PATH"
if [ "$GITHUB_EVENT_NAME" = pull_request ]; then
content=$(jq -r '.pull_request as $p
| "[PR 생성] #\($p.number) \($p.title)\n\($p.head.ref) → \($p.base.ref), \($p.user.login)\n\($p.html_url)"' "$ev")
elif [ "$GITHUB_REF_TYPE" = tag ]; then
content=$(jq -r '(.ref | sub("^refs/tags/"; "")) as $t
| "[태그 생성] \($t) (\(.after[0:7])), \(.pusher.name)\n\(.repository.html_url)/tree/\($t)"' "$ev")
else
content=$(jq -r '(if (.commits | length) > 0 then .commits else [.head_commit] end) as $c
| "[\(.ref | sub("^refs/heads/"; "")) 머지] \(.pusher.name)\n"
+ ([$c[] | "- \(.id[0:7]) \(.message | split("\n")[0])"] | join("\n"))
+ "\n\(.compare)"' "$ev")
fi
jq -n --arg content "$content" '{content: ($content | .[0:1990]), allowed_mentions: {parse: []}}' \
| curl -fsS -H 'Content-Type: application/json' -d @- "$DISCORD_WEBHOOK_URL"
102 changes: 102 additions & 0 deletions .github/workflows/fast-forward.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: 승격 FF

# develop → production, production → main 승격 PR 에 "/ff" 댓글을 달면 base 브랜치를 PR head 로 FF 한다.
on:
issue_comment:
types: [created]

permissions: {}

jobs:
fast-forward:
if: >-
github.event.issue.pull_request && startsWith(github.event.comment.body, '/ff')
&& contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association)
runs-on: ubuntu-latest
concurrency:
group: fast-forward-${{ github.event.issue.number }}
cancel-in-progress: false
steps:
- name: GitHub App 토큰
id: app
uses: actions/create-github-app-token@v3
with:
client-id: ${{ vars.FF_APP_CLIENT_ID }}
private-key: ${{ secrets.FF_APP_PRIVATE_KEY }}
permission-contents: write
permission-workflows: write
permission-pull-requests: write
permission-checks: read
permission-statuses: read

- name: 확인 후 FF
# 댓글 본문과 작성자는 환경변수로만 넘긴다.
env:
GH_TOKEN: ${{ steps.app.outputs.token }}
REPO: ${{ github.repository }}
PR: ${{ github.event.issue.number }}
ACTOR: ${{ github.event.comment.user.login }}
COMMENT: ${{ github.event.comment.body }}
REQUIRED_APPROVALS: 0
run: |
set -euo pipefail
fail() {
gh pr comment "$PR" -R "$REPO" --body "FF 하지 않았다: $1"
echo "::error::$1"
exit 1
}

if [ "$(printf '%s\n' "$COMMENT" | head -n 1 | tr -d '[:space:]')" != "/ff" ]; then
echo "/ff 명령이 아니다"; exit 0
fi

perm=$(gh api "repos/$REPO/collaborators/$ACTOR/permission" --jq .permission 2>/dev/null || echo none)
case "$perm" in
admin|maintain|write) ;;
*) echo "::error::$ACTOR 에게 쓰기 권한이 없다"; exit 1 ;;
esac

pr=$(gh api "repos/$REPO/pulls/$PR")
state=$(printf '%s' "$pr" | jq -r .state)
base=$(printf '%s' "$pr" | jq -r .base.ref)
head=$(printf '%s' "$pr" | jq -r .head.ref)
head_sha=$(printf '%s' "$pr" | jq -r .head.sha)
head_repo=$(printf '%s' "$pr" | jq -r .head.repo.full_name)
[ "$state" = open ] || fail "열린 PR 이 아니다"
[ "$head_repo" = "$REPO" ] || fail "같은 저장소의 브랜치만 FF 한다"
case "$head>$base" in
"develop>production" | "production>main") ;;
*) fail "승격 PR(develop → production, production → main)만 FF 한다: $head → $base" ;;
esac

reviews=$(gh api --paginate "repos/$REPO/pulls/$PR/reviews?per_page=100" \
--jq '.[] | select(.state != "COMMENTED") | [.user.login, .state] | @tsv' \
| awk -F '\t' '{ last[$1] = $2 } END { for (u in last) print last[u] }')
if printf '%s\n' "$reviews" | grep -qx CHANGES_REQUESTED; then
fail "변경 요청이 남아 있다"
fi
approvals=$(printf '%s\n' "$reviews" | grep -cx APPROVED || true)
[ "$approvals" -ge "$REQUIRED_APPROVALS" ] || fail "승인 ${approvals}명, ${REQUIRED_APPROVALS}명 필요"

runs=$(gh api --paginate --slurp "repos/$REPO/commits/$head_sha/check-runs?per_page=100" | jq '[.[].check_runs[]]')
not_passed=$(printf '%s' "$runs" | jq -r '.[]
| select(.status != "completed" or ((.conclusion | IN("success", "neutral", "skipped")) | not))
| "\(.name)(\(.conclusion // .status))"')
[ -z "$not_passed" ] || fail "통과하지 않은 체크: $(printf '%s' "$not_passed" | tr '\n' ' ')"
[ "$(printf '%s' "$runs" | jq '[.[] | select(.name == "check" and .conclusion == "success")] | length')" -ge 1 ] \
|| fail "check(빌드·테스트)가 이 커밋에서 통과한 기록이 없다"
status=$(gh api "repos/$REPO/commits/$head_sha/status" --jq '"\(.total_count) \(.state)"')
[ "${status%% *}" = 0 ] || [ "${status#* }" = success ] || fail "커밋 상태가 ${status#* } 이다"

base_sha=$(gh api "repos/$REPO/git/ref/heads/$base" --jq .object.sha)
compare=$(gh api "repos/$REPO/compare/$base_sha...$head_sha" --jq '"\(.status) \(.behind_by)"')
case "$compare" in
"ahead 0") ;;
identical*) fail "$base 가 이미 같은 커밋이다" ;;
*) fail "FF 할 수 없다($compare). $base 가 $head 의 조상이 아니다" ;;
esac

gh api -X PATCH "repos/$REPO/git/refs/heads/$base" -f sha="$head_sha" -F force=false > /dev/null \
|| fail "$base 갱신이 거부됐다"

gh pr comment "$PR" -R "$REPO" --body "FF 했다: $base → $(printf '%s' "$head_sha" | cut -c1-7)"
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ docker compose --profile mock up --build
| `develop` | 개발 서버(`dev-api.moadream.kr`) |
| `production` | 운영 서버(`api.moadream.kr`). Swagger가 꺼진다 |

`develop`, `production`의 DB 접속 정보는 환경변수(`SPRING_DATASOURCE_URL` 등)로 넣는다. 공개 repo이므로 비밀값은 repo에 두지 않는다.
`develop`, `production`의 DB 접속 정보는 환경변수(`SPRING_DATASOURCE_URL` 등)로 넣는다. 비밀값은 repo에 두지 않는다.

## 규칙

Expand Down Expand Up @@ -79,7 +79,7 @@ public class FundingClosedException extends ErrorResponseException {

### mock

경로와 Swagger 설명은 `*Api` 인터페이스에 두고, 실제 컨트롤러와 mock 컨트롤러가 같은 인터페이스를 구현한다. 시그니처가 어긋나면 컴파일이 깨진다.
경로와 Swagger 설명은 `*Api` 인터페이스에 두고, 실제 컨트롤러와 mock 컨트롤러가 같은 인터페이스를 구현한다.

```java
@RequestMapping("/v1/fundings")
Expand All @@ -106,7 +106,7 @@ class FundingMockController implements FundingApi {
}
```

API를 만들 때 mock 컨트롤러도 함께 만들어 프론트가 먼저 붙을 수 있게 한다.
API를 만들 때 mock 컨트롤러도 함께 만든다.

### DB

Expand All @@ -125,7 +125,18 @@ API를 만들 때 mock 컨트롤러도 함께 만들어 프론트가 먼저 붙
| Checkstyle | 들여쓰기 4칸, 미사용·와일드카드 import |
| ArchUnit | DTO의 엔티티 의존, 컨트롤러의 Repository·엔티티 의존, 컨트롤러의 `@Transactional`, 패키지 순환, `@Query`·`@NativeQuery`, 문자열을 받는 jOOQ API, `LocalDateTime` |

### PR
### 브랜치·커밋·PR

- 피쳐 브랜치에서 `develop`으로 PR을 올린다. 사람 두 명이 approve하면 FF 머지한다.
| 항목 | 규칙 | 예 |
|---|---|---|
| 브랜치 | `feature/{이슈 키}` | `feature/14-38` |
| 커밋 | `{타입}({이슈 키}): 요약`. 타입은 `feat`, `fix`, `refactor`, `test`, `docs`, `chore` | `feat(14-38): 엔티티 공통 규칙 추가` |
| PR 제목 | `[{이슈 키}] 요약` | `[14-38] 엔티티 공통 규칙` |

- 피쳐 브랜치에서 `develop`으로 PR을 올린다. 사람 두 명이 approve하면 Rebase and merge로 합친다.
- PR 본문은 템플릿(`.github/pull_request_template.md`)을 채운다.
- 커밋마다 이슈 키를 넣는다. CI가 `develop`으로 오는 PR의 브랜치 이름과 모든 커밋 메시지를 검사한다.
- 배포는 `develop` → `production` PR, 그다음 `production` → `main` PR로 한다. 배포할 때 `production`에 태그 `v{YYYYMMDD}-{짧은 해시}`를 단다.
- 승격 PR은 머지 버튼 대신 `/ff` 댓글로 반영한다. 봇이 체크 통과와 FF 가능 여부를 확인하고 base 브랜치를 PR head 커밋으로 옮긴다(`.github/workflows/fast-forward.yml`, 변수 `FF_APP_CLIENT_ID`, 시크릿 `FF_APP_PRIVATE_KEY`).
- 디스코드 알림은 PR 생성, `develop`·`production`·`main` 반영, `v*` 태그 생성 때 간다(`.github/workflows/discord.yml`, 시크릿 `DISCORD_WEBHOOK_URL`).
- CodeRabbit이 1차 리뷰를 한다. 자동으로 돌지 않으면 PR에 `@coderabbitai review` 댓글을 단다.