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
5 changes: 5 additions & 0 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ language: ko-KR
reviews:
profile: chill
poem: false
fail_commit_status: true
auto_review:
enabled: true
# develop, production, 그리고 기본 브랜치 main 으로 오는 PR 을 리뷰한다. 승격 PR(고정 제목)은 리뷰하지 않는다.
base_branches:
- develop
- production
ignore_title_keywords:
- Develop to production
- Production to main
path_instructions:
- path: "src/main/java/**/*.java"
instructions: |
Expand Down
16 changes: 16 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/promotion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!-- 머지 버튼 대신 `/ff` 댓글로 반영한다. -->

## 포함된 PR

- #

## 배포 영향

- DB 마이그레이션:
- 설정·시크릿:
- API 변경:

## 체크리스트

- [ ] 마이그레이션이 있으면 운영 DB에 적용해도 되는지 봤다
- [ ] 새 설정·시크릿을 production 환경에 넣었다
15 changes: 15 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## 이슈

14-00

## 변경 내용

-

## 리뷰 포인트

-

## 체크리스트

- [ ] API를 추가·변경했으면 mock 컨트롤러도 맞췄다
3 changes: 1 addition & 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 Down
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]
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"
151 changes: 151 additions & 0 deletions .github/workflows/fast-forward.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
name: 승격 FF

# 승격 PR(develop → production, production → main)과 핫픽스 PR(hotfix/{이슈 키} → production)에 "/ff" 댓글을 달면
# base 브랜치를 PR head 로 FF 한다. 핫픽스는 develop 에도 합친다.
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 }}
PROMOTION_APPROVALS: 0
HOTFIX_APPROVALS: 2
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 한다"
if [ "$head>$base" = "develop>production" ] || [ "$head>$base" = "production>main" ]; then
kind=promotion; required=$PROMOTION_APPROVALS; need_checks="check"
elif printf '%s' "$head" | grep -Eq '^hotfix/[0-9]+-[0-9]+$' && { [ "$base" = production ] || [ "$base" = develop ]; }; then
kind=hotfix; required=$HOTFIX_APPROVALS; need_checks="check naming CodeRabbit"
else
fail "승격 PR(develop → production, production → main)과 핫픽스 PR(hotfix/{이슈 키} → production, develop)만 FF 한다: $head → $base"
fi
# develop 으로 오는 핫픽스 PR 은 production 을 합친 브랜치(되합치기 충돌을 푼 것)만 받는다.
if [ "$kind>$base" = "hotfix>develop" ]; then
prod_sha=$(gh api "repos/$REPO/git/ref/heads/production" --jq .object.sha) || fail "production 을 읽지 못했다"
st=$(gh api "repos/$REPO/compare/$prod_sha...$head_sha" --jq .status) || st=error
case "$st" in
ahead | identical) ;;
*) fail "develop 으로는 production 을 합친 핫픽스 브랜치만 FF 한다" ;;
esac
fi

reviews=$(gh api --paginate "repos/$REPO/pulls/$PR/reviews?per_page=100" \
--jq '.[] | select(.state != "COMMENTED" and (.author_association | IN("OWNER", "MEMBER", "COLLABORATOR")))
| [.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" ] || fail "승인 ${approvals}명, ${required}명 필요"

# 리뷰 대화는 앞 100개만 본다.
unresolved=$(gh api graphql -f owner="${REPO%/*}" -f name="${REPO#*/}" -F number="$PR" -f query='
query($owner: String!, $name: String!, $number: Int!) {
repository(owner: $owner, name: $name) {
pullRequest(number: $number) { reviewThreads(first: 100) { nodes { isResolved } } }
}
}' --jq '[.data.repository.pullRequest.reviewThreads.nodes[] | select(.isResolved | not)] | length')
[ "$unresolved" = 0 ] || fail "해결하지 않은 대화가 ${unresolved}개 있다"

# 같은 이름의 체크는 가장 최근 것만 본다. 디스코드 알림(notify)은 반영 조건이 아니다.
runs=$(gh api --paginate --slurp "repos/$REPO/commits/$head_sha/check-runs?per_page=100" \
| jq '[.[].check_runs[] | select(.name != "notify")] | group_by([.app.id, .name]) | map(max_by(.id))')
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' ' ')"
for c in $need_checks; do
[ "$(printf '%s' "$runs" | jq --arg c "$c" '[.[] | select(.name == $c and .conclusion == "success")] | length')" -ge 1 ] \
|| fail "$c 가 이 커밋에서 통과한 기록이 없다"
done
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 갱신이 거부됐다"

msg="FF 했다: $base → $(printf '%s' "$head_sha" | cut -c1-7)"

# production 에 들어간 핫픽스는 develop 에도 합친다. 다음 승격이 FF 되도록 핫픽스 커밋은 그대로 둔다.
if [ "$kind>$base" = "hotfix>production" ]; then
dev_sha=$(gh api "repos/$REPO/git/ref/heads/develop" --jq .object.sha) || dev_sha=
sync=$(gh api "repos/$REPO/compare/$dev_sha...$head_sha" --jq .status) || sync=error
synced=true
case "$sync" in
ahead) gh api -X PATCH "repos/$REPO/git/refs/heads/develop" -f sha="$head_sha" -F force=false > /dev/null || synced=false ;;
diverged) gh api -X POST "repos/$REPO/merges" -f base=develop -f head="$head_sha" \
-f commit_message="Merge $head into develop" > /dev/null || synced=false ;;
behind | identical) ;;
*) synced=false ;;
esac
if [ "$synced" = false ]; then
gh pr comment "$PR" -R "$REPO" --body "$msg. develop 에는 합치지 못했다. develop 에서 $head 를 다시 만들어 production 을 merge 하고, develop 으로 PR 을 올려 /ff 한다."
echo "::error::develop 에 합치지 못했다"
exit 1
fi
msg="$msg. develop 에도 합쳤다"
fi
gh pr comment "$PR" -R "$REPO" --body "$msg"
53 changes: 53 additions & 0 deletions .github/workflows/naming.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: 이름 규칙

# develop 으로 오는 PR 과 production 으로 오는 핫픽스 PR 의 브랜치 이름, PR 제목, 커밋 메시지를 검사한다.
# 커밋마다 이슈 키를 넣는다. 머지 커밋은 검사하지 않는다. PR 제목을 고치면 다시 검사한다.
on:
pull_request:
types: [opened, edited, synchronize, reopened]

permissions:
contents: read

concurrency:
group: naming-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
naming:
if: github.base_ref == 'develop' || (github.base_ref == 'production' && startsWith(github.head_ref, 'hotfix/'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: false
- name: 브랜치·PR 제목·커밋 이름 규칙
# 브랜치 이름과 PR 제목은 환경변수로만 넘긴다.
env:
HEAD_REF: ${{ github.head_ref }}
PR_TITLE: ${{ github.event.pull_request.title }}
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|hotfix)/[0-9]+-[0-9]+$'; then
echo "브랜치 이름이 규칙과 다르다: $HEAD_REF (feature/{이슈 키} 또는 hotfix/{이슈 키}, 예: feature/14-38)"; exit 1
fi
key=${HEAD_REF#*/}
case "$PR_TITLE" in
"[$key] "?*) ;;
*) echo "PR 제목이 규칙과 다르다: $PR_TITLE ([{이슈 키}] 요약, 예: [$key] 요약)"; exit 1 ;;
esac
# CodeRabbit 은 이 문구가 든 제목을 승격 PR 로 보고 리뷰하지 않는다.
if printf '%s' "$PR_TITLE" | grep -Eqi 'develop to production|production to main'; then
echo "PR 제목에 승격 PR 제목(Develop to production, Production to main)을 넣지 않는다: $PR_TITLE"; exit 1
fi
log=$(git log --no-merges --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 "브랜치·PR 제목·커밋 이름 규칙 통과"
Loading