Skip to content

Commit

Permalink
ci: 2명 이상이 approve한 PR을 자동으로 merge하는 workflow 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
minjungw00 committed Nov 10, 2024
1 parent d5bd75a commit 7dd1d35
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/auto_merge_approved_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Auto Merge Approved PRs"

on:
pull_request_review:
types: [submitted]

jobs:
auto_merge:
runs-on: ubuntu-latest
steps:
- name: "Get Pull Request"
id: pr
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const { data: pr } = await github.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
});
return JSON.stringify(pr);
- name: "Check Approvals"
id: check
uses: actions/github-script@v6
with:
script: |
const pr = JSON.parse(steps.pr.outputs.result);
const reviews = await github.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
});
const approvals = reviews.data.filter(review => review.state === 'APPROVED');
return approvals.length >= 2;
- name: "Merge PR"
if: steps.check.outputs.result == 'true'
uses: actions/github-script@v6
with:
script: |
await github.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
});
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
steps:
# 1. 레포지토리 클론
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# 2. Docker Compose로 서비스 빌드 및 재시작
- name: Set up Docker
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Build and Deploy Docker Images
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- dev

jobs:
lint-and-test:
lint_and_test:
name: Lint and Test
runs-on: ubuntu-latest

Expand Down

0 comments on commit 7dd1d35

Please sign in to comment.