Repository navigation
[14-45] 브랜치·커밋·PR 규칙 #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c0dfade
chore(14-45): 브랜치·커밋·PR 이름 규칙과 PR 검사 추가
platanus-kr f2ad0b4
chore(14-45): PR 템플릿 추가, 이슈 키 표기 통일
platanus-kr 963adf8
fix(14-45): 커밋 검사에서 git log 실패를 실패로 처리
platanus-kr 39c1174
chore(14-45): CodeRabbit 리뷰 오류를 체크 실패로 처리
platanus-kr 8442402
chore(14-45): 디스코드 알림 워크플로 추가
platanus-kr 07647a8
chore(14-45): 승격 FF 봇(/ff) 추가
platanus-kr c45e6c7
fix(14-45): /ff 봇이 리뷰·체크를 모든 페이지에서 확인하고 PR을 닫지 않음
platanus-kr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| ## 이슈 | ||
|
|
||
| 14-00 | ||
|
|
||
| ## 변경 내용 | ||
|
|
||
| - | ||
|
|
||
| ## 리뷰 포인트 | ||
|
|
||
| - | ||
|
|
||
| ## 체크리스트 | ||
|
|
||
| - [ ] API를 추가·변경했으면 mock 컨트롤러도 맞췄다 | ||
| - [ ] 테이블을 추가했으면 README 테이블 쓰기 담당 표에 적었다 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.