[Github Action] PR(Pull Request) ์์ฑ ๋ฐ ๋ณํฉ ์๋ํ ํ๊ธฐ
ํ๊ทธ: Github
์นดํ ๊ณ ๋ฆฌ: Github
Github Action ์ ์ด์ฉํด Pull Request ๋ฅผ ์๋์ผ๋ก ์์ฑํ๊ณ auto-merge ํ๋ ๋ฐฉ๋ฒ๊ณผ ์ ์ฉํ๋ฉด์ ๊ฒช์๋ ์ค๋ฅ ์ํฉ๊ณผ ํด๊ฒฐ๋ฐฉ๋ฒ์ ๋ค๋ฃน๋๋ค.
PR ์์ฑ์ ๊ท์ฐฎ์..
github flow ๋ฅผ ์ด์ฉํด ๊ฐ๋ฐํ๊ฒ ๋๋ฉด Pull Request ์์ฑ์ด ํ์๋ค. ๋ฌธ์ ๋ ๋ก์ปฌ์์ push ๋ฅผ ํ ํ, github ์ ์ ์ํด PR ์ ์ง์ ์์ฑํด์ผ ํ๋ค๋ ๊ฒ์ด๋ค.
๋ฌผ๋ก , ์ด ๊ณผ์ ์์ ์์ ๋ด์ฉ์ ์์ฑํ๋ฉด์ ํ๋ฒ ๋ ์ ๊ฒํ ์๋ ์์ด ์๋์ผ๋ก ์ง์ ๋ง๋๋ ๊ฒ๋ ์๋ฏธ๊ฐ ์๋ค๊ณ ์๊ฐํ์ง๋ง, ๊ฐ๋จํ ์คํฐ๋ ์ฉ์ผ๋ก ์ฌ์ฉํ๋ ๊ฒฝ์ฐ์ ์ผ์ผ์ด ์๋์ผ๋ก ๋ง๋๋ ๊ณผ์ ์์ฒด๊ฐ ๋จ์ ๋ฐ๋ณต์ ์ธ ๊ณผ์ ์ผ๋ก ๋๊ปด์ก๋ค.
PR ์ ์๋์ผ๋ก ์์ฑํ๋ Action
์ญ์๋.. ์ด๋ฏธ Github Action marketplace ์๋ PR ์ ์๋์ผ๋ก ์์ฑํด์ฃผ๋ workflow ๊ฐ ์ค๋์ ๋ถํฐ ์ฌ์ฉ๋๊ณ ์์๋ค.
๊ทธ ์ค star ์๊ฐ ๊ฐ์ฅ ๋ง๊ณ , Github staff ๊ฐ ์ง์ ๋ง๋ Crate Pull Request ๋ฅผ ์ฌ์ฉํด๋ณด๊ธฐ๋ก ํ๋ค.
๊ธฐ๋ณธ์ ์ธ ์์ฑ๋ฒ์ ๋ค์๊ณผ ๊ฐ๋ค. ์ฌ๊ธฐ์ ์ต์ ์ผ๋ก branch, base, title, body, labels, assignees, reviewers ๋ฑ์ ์ถ๊ฐํ ์ ์๋๋ก ์ง์ํ๊ณ ์๋ค.
- branch: pr ์ ์์ ๋ธ๋์น (feature ๋ธ๋์น ๋ฑ)
- base: ์์ค๋ฅผ ํตํฉํ ๋ธ๋์น (main ๋ธ๋์น ๋ฑ)
- title: PR ์ ์ ๋ชฉ
- body: PR ์ ๋ด์ฉ
- labels: PR ๋ผ๋ฒจ
- assignees: PR ์ ์์ฑํ ์ฌ๋
- reviewers: PR ๋ฆฌ๋ทฐํ ์ฌ๋
1
2
3
4
5
6
- uses: actions/checkout@v4
# Make changes to pull request here
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
๋ค๋ฅธ ๋ธ๋ก๊ทธ๋ workflow ๊ฐ์ด๋๋ฅผ ๋ด๋ ๊ต์ฅํ ์ฌ์ฉ๋ฒ์ด ๊ต์ฅํ ๊ฐ๋จํด ๋ณด์ธ๋ค. ๋ฐ๋ก ํ๋ก์ ํธ์ ์ ์ฉํด ๋ดค๋ค.
๋ฌธ์
title ์ ๋จ์ํ ์์
๋ธ๋์น์์ main ๋ธ๋์น๋ก ํธ์ํ๋ค๋ ๊ฒ์ ํ์ํ๊ณ , body ์ ๋ด์ฉ์ผ๋ก๋ ๋ธ๋์น ํธ์ ์ํ์ ์ปค๋ฐ ๋ฉ์์ง๋ฅผ ๊ทธ๋๋ก ์ถ๋ ฅํ๊ณ ์ถ์๋ค.
assignees ์ ๊ฒฝ์ฐ ๋ก์ปฌ์์ push ํ ์ฌ๋์ github ๊ณ์ ์ด ์ฐํ์ผ ํ๊ธฐ ๋๋ฌธ์ ${{ github.actor }}
๋ก ์์ฑํ๊ณ , reviewers ๋ ํ์ ์ ์ฒด๊ฐ ์ ํ๋์ด์ผ ํ๋ฏ๋ก github var ์ ์ง์ REVIEWERS ๋ผ๋ ์ด๋ฆ์ผ๋ก ์ธ์์์ ๋ง๊ฒ ,
๋ก ๊ตฌ๋ถํด ๋ฑ๋กํ๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
name: Auto PR and Merge
on:
push:
branches:
- 'sw**'
- 'cm**'
jobs:
create-pull-request:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: main
branch: ${{ github.ref_name }}
title: "[auto] ${{github.ref_name}} โ main"
body: |
- ์๋ PR: `${{ github.ref_name }} โ main`
- ์ปค๋ฐ ๋ฉ์์ง: `${{ github.event.head_commit.message }}`
labels: auto-merge
assignees: ${{ github.actor }}
reviewers: ${{ vars.REVIEWERS }}
draft: false
์ด๋๋ก ๋ง๋ค๊ณ ๋ก์ปฌ์์ push ํ๋ฉด github ์ ์๋์ผ๋ก PR ์ด ์์ฑ๋ ์ค ์์๋๋ฐ, ์๋์ผ๋ก ์์ฑ๋์ง๋ ์์ ๋ฟ๋๋ฌ ์๋์ผ๋ก ์์ฑํด๋ ์๋ฌด๋ฐ ๋ณ๊ฒฝ์ฌํญ์ด ์์ด main ๋ธ๋์น์ ๋ณํฉ์ ํ ์ ์๋ ์ํฉ์ด์๋ค.
actions setting ๋ฌธ์
์ฐพ์๋ณด๋ github action ๊ถํ ๋ฌธ์ ์ผ ์ ์๋ค๊ณ ๋์์ ์ค์ ์ ๋ค์ ํด์คฌ๋ค.
Repository
> Settings
> Actions
> General
๋ก ๋ค์ด๊ฐ๊ฒ ๋๋ฉด ๋งจ ์๋ ๋ถ๋ถ์ Workflow permissions
๋ถ๋ถ์ด ์๋ค.
Read and Write
๊ถํ์ ์ฒดํฌํ๊ณ , ์๋์ Github Actions ๊ฐ PR ์ ๋ง๋ค ์ ์๋ ๊ถํ๋ ์ฒดํฌํ๋ค.
์๋ชป๋ branch ์ต์ ์ฌ์ฉ
์ด๋ฒ์ action ์ ์๋ํ์ง๋ง ์ฌ์ ํ PR ์๋ ์์ฑ์ ๋์ง ์์๋ค. workflow ๋ก๊ทธ ๋ด์ญ์ ๋ณด๋ ๊ณ์ main ๊ณผ feature ๋ธ๋์น๊ฐ ๋ณ๊ฒฝ์ฌํญ์ด ์์ด ๋ณํฉ์ด ์๋๋ค๊ณ ๋์๋ค. ๋ถ๋ช ๋ก์ปฌ์์๋ ์์ ํ ๋ด์ฉ์ด ์๊ณ , ์ด๋ฅผ push ํ์์๋ ๋ถ๊ตฌํ๊ณ ๋ณ๊ฒฝ์ฌํญ์ด ์๋ค๊ณ ํ๋ ๋์ ํ ์์ธ์ ์ฐพ์ ์๊ฐ ์์๋ค.
1
2
3
fatal: remotes/origin/main...remotes/origin/sw-test4: no merge base
[INFO] Both branches are the same. No action needed.
๊ต์ฅํ ๋ง์ ์๋์ ์์ ์ ๊ฑฐ๋ญํ์ง๋ง ์ฌ์ ํ PR ์ด ์์ฑ๋์ง ์์๋ค.. ๊ฒฐ๊ตญ ๊ฐ๋ฐ์์๊ฒ ์ง์ ์ด์๋ฅผ ๋จ๊ฒจ ๋ฌผ์ด๋ณด๊ธฐ๋ก ํ๋ค. issues ์ ๋ค์ด๊ฐ๋ณด๋ ๋ญ๊ฐ ๋น์ทํ ์ํฉ์ ๊ฒช๊ณ ์๋ ๊ฐ๋ฐ์๋ค์ด ๊ฝค ์๋๊ฒ ์ฒ๋ผ ๋ณด์ฌ์ ๋จผ์ ํด๋น ๊ธ๋ค์ ํ์ธํด ๋ดค๋ค. ๋ญ๊ฐ branch ์ค์ ์ ๋ํ ์ด์ ๊ฐ์๋ค. ๋๋ ๋ด ๋ฌธ์ ๋ฅผ ์ด์๋ก ๋จ๊ฒจ๋ณด๊ธฐ๋ก ํ๋ค.
๋คํํ ๋ต๋ณ์ด ํ๋ฃจ๋ง์ ๋์ฐฉํด ํ์ธํด๋ดค๋ค.
์ญ์
branch
์ต์
์ ์ฌ์ฉ ๋ฐฉ๋ฒ์ด ์๋ชป๋์๋ค. github.ref_name
์ผ๋ก ์ฌ์ฉํ๊ฒ ๋ ๊ฒฝ์ฐ branch ์ ์ด๋ฆ์ ๊ฐ์ ธ์ค๊ฒ ๋๋ค.
์๋ฅผ ๋ค์ด ๋ก์ปฌ์์ sw-test
๋ผ๋ ๋ธ๋์น ๋ช
์ผ๋ก push ํ๊ฒ ๋๋ฉด sw-test
๋ผ๋ ๊ฐ์ด ์ ๋ณ์ ๋์ ๋ค์ด๊ฐ๊ฒ ๋๋ค.
๋ค๋ฅธ ๋ธ๋ก๊ทธ ๊ธ์ด๋ Crate Pull Request action ๋ฉ๋ด์ผ์ ๋ด๋ ๋ธ๋์น ๋ช ์ ์ง์ ๋ช ์ํด์ ์ฌ์ฉํ๋ ๊ฒ์ผ๋ก ๋์ ์์ด, ๊ทธ๋ฅ ๋ธ๋์น ๋ช ๋ง ์ ์ผ๋ฉด ๋๋ ์ค ์์๋ค. ์ ๊ฒ ๋ฌธ์ ๊ฐ ๋ ๊ฒ ์ด๋ผ๋ ์๊ฐ์ ์ ํ ํ์ง ๋ชปํ๋ค.
์๋ง workflow ๊ฐ ๋์ํ๋ฉด์ ๋ด๋ถ์ ์ผ๋ก github ์ก์
์ ํธ๋ฆฌ๊ฑฐ ํ branch ์ ์ ์ฒด ๊ฒฝ๋ก๋ฅผ ํ์๋ก ํ๋ ๊ฒ ๊ฐ์๋ค. GPT ์ ๋ฌผ์ด๋ณด๋ github.event.ref
๋ฐฉ์์ผ๋ก ์ ์ฒด ๊ฒฝ๋ก๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๋ค๊ณ ํด์ ํด๋น ๋ฐฉ๋ฒ์ผ๋ก ๋ค์ ์์ฑํด ๋ดค๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
jobs:
auto-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Create Pull Request to main
id: create_pr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: main
branch: ${{ github.event.ref }} # refs/heads/sw-test
title: "[auto] ${{ github.event.head_commit.message }}"
body: |
์๋ PR ์์ฑ: `${{ github.ref_name }} โ main`
์ปค๋ฐ ๋ฉ์์ง: `${{ github.event.head_commit.message }}`
labels: auto-merge
assignees: ${{ github.actor }}
reviewers: ${{ vars.REVIEWERS }}
draft: false
github token ๋ฌธ์
์ด๋ฒ์ ๋๋์ด ์๋์ผ๋ก PR ์ด ์์ฑ๋์๋ค!
๊ทธ๋ฌ๋ ์ด๋ฒ์๋ GitHub Actions Bot์ด PR์ ์์ฑํ๋ฉด์, ์ฝ๋๋ฅผ pushํ ์์ฑ์์กฐ์ฐจ๋ ์ค์ค๋ก approve(์น์ธ)ํ ์ ์๋ ์ํฉ์ด ๋ฐ์ํ๊ฒ ๋์๋ค. ํ์ฌ branch protection rule ์ 1๋ช ์ด ์น์ธํ ๊ฒฝ์ฐ merge ํ ์ ์๋๋ก ์ค์ ์ด ๋์ด ์์ด, ์ด๋ ๊ฒ ๋ ๊ฒฝ์ฐ ์๋์ ๋ค๋ฅด๊ฒ ์๋๋ฐฉ์ ์ฝ๋ ๋ฆฌ๋ทฐ ์์ด ์ฝ๋ ์์ฑ์๊ฐ ์ค์ค๋ก ๋ณํฉํ๊ฒ ๋๋ ์ํฉ์ด ๋ฐ์ํ ์ ์๋ค. ํผ์์ ์์ ํ๋ ์ ์ฅ์์ ๊ฒฝ์ฐ์๋ ์ ๊ฒฝ์ฐ์ง ์์๋ ๋์ง๋ง, ๊ณต๋ ์์ ํ๋ ๊ฒฝ์ฐ์๋ ์ค์ํ ๋ฌธ์ ๊ฐ ๋ ์ ์๋ค.
์ token ์ต์
์ secrets.GITHUB_TOKEN
๋ฅผ ์ฌ์ฉํ๊ฒ ๋๋ฉด ๊ฐ๋ฐ์๋ ๋ฐ๋ก secrets ์ ์ ์ํ ํ์์์ด github ์ด ๋ด๋ถ์ ์ผ๋ก ํ ํฐ์ ๋ง๋ค์ด ์ฌ์ฉํ๊ฒ ๋๋ฉฐ, PR ์์ฑ์ ์ฃผ์ฒด๋ Bot ์ผ๋ก ๋์ํ๊ฒ ๋๋ค.
โ Personal Access Token (PAT) ์ฌ์ฉ
Create Pull Request ๋ฉ๋ด์ผ์ Personal Access Token (PAT) ์ฌ์ฉ ์ ๊ถํ ์ค์ ์ ๋ํด ์ ๋์ ์์ด GH_TOKEN
์ด๋ผ๋ ์ด๋ฆ์ผ๋ก ํ ํฐ์ ๋ง๋ค๊ณ secrets ์ ๋ฑ๋กํด ์คฌ๋ค.
๊ทธ๋ฆฌ๊ณ yml ํ์ผ token ๋ถ๋ถ๋ secrets.GH_TOKEN
์ผ๋ก ์์ ํ ๋ค์ ํ
์คํธ ํด๋ดค๋ค.
๊ทธ๋ฌ๋ ์ ์ฌ์ง์ฒ๋ผ ์๋๋ฐฉ์ด ์์ฑํ PR ์ด ๋ด ๋๋ค์(zhtmr) ์ผ๋ก ์ฌ๋ผ๊ฐ๋ค. ๋ด ๊ณ์ ์์ ๋ง๋ ํ ํฐ(GH_TOKEN)์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ด๋ค. ๋ํ ์ Reviewer ๋ ๋ง์ง ์๊ฒ ์ถ๋ ฅ๋๋ค.
โ Assignees ์ Reviewer ๊ฐ ๋์ ์ผ๋ก ๋ณํด์ผ ํ๋ค.
์์ฑ์ ๊ณ์ ์ PAT ๋ฅผ ๋ง๋ ๊ณ์ ์ ๋ฐ๋ผ๊ฐ๋ค๋ ๊ฒ์ ์ดํดํ๋ค. ์ ์์ ์ผ๋ก ์๋ํ๋ ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด ์๋ํด์ผ ํ๋ค.
- PR ์ ์์ฑ์ ๋๋ค์์ ์ค์ ๋ก push ํ ๊ณ์ ๋๋ค์์ด ํ์๋์ด์ผ ํ๋ค.
- Assignees ์ ์ค์ ์์ฑ์๊ฐ ํ์๋์ด์ผ ํ๊ณ , Reviewers ์๋ ์์ฑ์๋ฅผ ์ ์ธํ ๋๋จธ์ง ์ธ์์ด ํ์๋์ด์ผ ํ๋ค.
token ํ์ฑ
๋จผ์ PR ์์ฑ์ ๋๋ค์์ ์ค์ ์ฝ๋๋ฅผ push ํ ๊ณ์ ์ผ๋ก ํ์ํ๊ธฐ ์ํด์ ํ๋ก์ ํธ์ ์ฐธ์ฌ ์ค์ธ ๋ชจ๋๊ฐ PAT ๋ฅผ ๋ฐ๊ธ ๋ฐ์์ผ ํ๋ค๊ณ ์๊ฐํ๋ค. github ์์ ๋ฐ๊ธ๋ฐ์ ํ์๋ค์ ํ ํฐ์ secrets ์ ๋ชจ๋ ๋ฑ๋กํด ์ค๋ค. (GH_TOKEN, GH_TOKEN_CM)
๊ทธ๋ฆฌ๊ณ ์ด๋ฅผ push ํ๋ ๊ณ์ ์ ๋ฐ๋ผ ๋์ ์ผ๋ก ์ ํํด์ผ ํ๋ค. push ๋ฅผ ํ๋ ๊ณ์ ์์ github action workflow ๊ฐ ๋์ํ๊ธฐ ๋๋ฌธ์ ํ์ฑํ๋ ๋ก์ง์ด ํ์ํ๋ค. steps ๋ถ๋ถ์ ์๋ ์ฝ๋๋ฅผ ์ถ๊ฐํ๋ค.
1
2
3
4
5
6
7
8
9
10
11
steps:
- name: Install yq
run: sudo apt-get update && sudo apt-get install -y yq
- name: Load token map
id: token-map
run: |
ACTOR="${{ github.actor }}"
TOKEN_VAR=$(yq ".\"$ACTOR\"" .github/workflows/user-token-map.yml | tr -d '"') # ์๋ฐ์ดํ ์ ๊ฑฐ!
echo "token_var=$TOKEN_VAR"
echo "token_var=$TOKEN_VAR" >> $GITHUB_OUTPUT
user-token-map.yml
๋ด๋ถ์๋ ์๋์ ๊ฐ์ด assignees ๊ฐ ๋ ๋๋ค์๊ณผ token secrets ๋ณ์๊ฐ ์ ์๋์ด ์๋ค. ๊ผญ yml ์ ์ ์ํ ํ์๋ ์๋ค. ๋ค๋ฅธ ํ์์ ํ์ผ๋ก ์ ์ํด๋ ๋๊ณ , ํ์ด์ฌ ๊ฐ์ ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๊ฒ ๋ง๋ค์ด๋ ์๊ด์๋ค.
1
2
cmnowhere: GH_TOKEN_CM
zhtmr: GH_TOKEN
Load token map
๋จ๊ณ์์ TOKEN_VAR
๋ณ์๊ฐ ๋ง๋ค์ด ์ง๋๋ฐ ํด๋น ๋ณ์๋ฅผ ์ดํ create pull request ํ๋ ๋จ๊ณ์ token ์ต์
์์ ์ฌ์ฉ๋ ์์ ์ด๋ค.
์ฃผ์ํ ์ ์ ๊ธฐ์กด์ ํ ํฐ ๊ฐ์ ์
๋ ฅํ ๋ secrets.GH_TOKEN
๋ฐฉ์์ผ๋ก ์
๋ ฅ ํ๋ฏ์ด secrets ๋ค์์ .
(๋ง์นจํ)๊ฐ ํ์ํ๊ธฐ ๋๋ฌธ์ ๋ง์นจํ๊น์ง ๊ฒฐ๊ณผ์ ๊ฐ์ด ํฌํจ์์ผ์ผ ํ๋ค. (".\"$ACTOR\""
)
Reviewer ํ์ฑ
๊ธฐ์กด์ ์ด๋ฏธ github var ์ REVIEWER ๋ ๋ฑ๋กํด ๋์์ผ๋ ์ด๋ฅผ ์ด์ฉํ๋ฉด ๋๋ค.
1
2
3
4
5
6
7
- name: Set reviewers except self
id: reviewers
run: |
ALL_REVIEWERS="${{ vars.REVIEWERS }}"
ACTOR="${{ github.actor }}"
FILTERED=$(echo "$ALL_REVIEWERS" | tr ',' '\n' | grep -v "^$ACTOR$" | paste -sd "," -)
echo "filtered=$FILTERED" >> $GITHUB_OUTPUT
๋ชจ๋ ๋ฆฌ๋ทฐ์ด(์์ฑ์ ํฌํจ)์์ ์์ฑ์๋ฅผ ์ ์ธํ๋ ๋ฐฉ์(grep -v
)์ผ๋ก FILTERED ๋ผ๋ ๋ณ์๋ฅผ ๋ง๋ ๋ค. ์ดํ create pull request ๋จ๊ณ์์ reviewers ๊ฐ์ผ๋ก ์ฌ์ฉ๋ ์์ ์ด๋ค.
๊ฐ์
create pull request
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- name: Create Pull Request to main
id: create_pr
uses: peter-evans/create-pull-request@v7
with:
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
committer: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
token: ${{ secrets[steps.token-map.outputs.token_var] }}
base: main
branch: ${{ github.event.ref }}
title: "[auto] ${{ github.event.head_commit.message }}"
body: |
์๋ PR ์์ฑ: `${{ github.ref_name }} โ main`
์ปค๋ฐ ๋ฉ์์ง: `${{ github.event.head_commit.message }}`
labels: auto-merge
assignees: ${{ github.actor }}
reviewers: ${{ steps.reviewers.outputs.filtered }}
draft: false
token ๋ถ๋ถ๊ณผ reviewers ๋ถ๋ถ์ ์์์ ์์
ํ ๋ณ์ ๊ฐ์ ๋ฃ์ผ๋ฉด ๋๋ค.
reviewer ์ ๊ฒฝ์ฐ ๊ฐ ์์ฒด๊ฐ ์นํ๋๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ${{ steps.reviewers.outputs.filtered }}
์ด๋ฐ์์ผ๋ก ๋ฐ๋ก ๋ณ์๊ฐ์ ์ฌ์ฉํ๋ฉด ๋๋ค.
๊ทธ๋ฌ๋ token ์ ๊ฒฝ์ฐ secrets ์ดํ ๋ถ๋ถ๋ง ๋ฐ๋์ด์ผ ํ๊ธฐ ๋๋ฌธ์ ์ ๋ฐฉ์์ผ๋ก๋ ์ฌ์ฉํ๊ธฐ ์ด๋ ต๋ค. ( ${{ secrets.์ด๋ถ๋ถ }} )
(์๋๋ฉด token ํ์ฑ ์ ์ ์ด์ secrets ๋ผ๋ ๋จ์ด๊น์ง ํ์ฑํด์ ๊ฐ์ ธ์๋ ๋ ๋ฏ)
๋์ ์ผ๋ก ์์ฑ๋ ์ด๋ฆ์ secrets ์ ๊ฐ์ผ๋ก ์ฐธ์กฐํ๊ธฐ ์ํด ๋๊ดํธ์์ ์ ์ํ๋ค.
1
${{ secrets[steps.token-map.outputs.token_var] }}
์ ์์ ์ผ๋ก ์ ์๋ํ๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
auto-merge
ํ๋ ๋ ์๋ํ ํ ์ ์๋ ๋ถ๋ถ์ด ์๋๋ฐ ๋ฐ๋ก merge ๋ฒํผ์ ํด๋ฆญํ๋ ํ์๋ค. ๋ณดํ merge ์กฐ๊ฑด์ ๋ง์กฑํ๊ฒ ๋๋ฉด PR ์์ฑ์๊ฐ Merge pull Request
๋ฒํผ์ ์ง์ ๋๋ฌ ๋ณํฉ์ ์๋ฃํ๋ค.
github ์์ ์์ฒด์ ์ผ๋ก PR ์ ์๊ตฌ์ฌํญ์ ๋ง์กฑํ๋ ๊ฒฝ์ฐ auto-merge ๋ฅผ ์ํํ๊ฒ ํ๋ ์ต์
์ด ์๋ค.
ํด๋น ์ต์
์ด ํ์ฑํ๋ ์ํ์์ PR์ ์์ฑํ๊ฒ ๋๋ ๊ฒฝ์ฐ Enable auto-merge
๋ผ๋ ๋ฒํผ์ด ๋ณด์ธ๋ค.
์ด ๋ฒํผ์ ๋๋ฅด๋ฉด ๋ ์ด์ merge ๋ฅผ ํ๊ธฐ์ํด
Merge pull Request
๋ฒํผ์ด ํ์ฑํ ๋ ๋๊น์ง ๊ธฐ๋ค๋ฆด ํ์ ์์ด github ๊ฐ ์์์ merge ์กฐ๊ฑด์ ๋ง์กฑํ๋ ๊ฒฝ์ฐ merge ์์ผ ์ค๋ค. ์กฐ๊ฑด์ ๋ง์กฑํ์ง ๋ชปํ๋ฉด ๋ณํฉํ์ง ์๋๋ค. (๋น์ฐํจ..)
workflow ๋ฅผ ์ด์ฉํ๋ฉด ์ด Enable auto-merge
๋ฅผ ๋๋ฅด๋ ํ์๋ฅผ ์๋ํ ํ ์ ์๋ค.
github actions marketplace ์ ๊ฐ์ ๊ฐ๋ฐ์๊ฐ ๋ง๋ automerge ์ ๋ํ workflow๋ ์๊ธธ๋ ๊ฐ์ด ์ ์ฉํด ๋ดค๋ค.
์ฐ์ ์๋ ๋ณํฉ ๊ธฐ๋ฅ์ ์ฌ์ฉํ๊ธฐ ์ํด์ ๋ค์ ์กฐ๊ฑด์ด ์ถฉ์กฑ๋์ด์ผ ํ๋ค.
- ๋์ ์ ์ฅ์ ์ค์ ์์
Allow auto-merge
์ต์ ์ด ํ์ฑํ ๋์ด ์์ด์ผ ํ๋ค. - base ๋ธ๋์น(๋์ ๊ฒฝ์ฐ main)์ ํ๋ ์ด์์ branch protection rule ์ด ์์ด์ผ ํ๋ค.
- ์๊ตฌ์ฌํญ(ex. 1 approve)์ด ์ถฉ์กฑ๋์ง ์์ ๊ฒฝ์ฐ auto merge ์ํํ๋ค. ์ด๋ฏธ ์๊ตฌ์ฌํญ์ด ์ถฉ์กฑ๋๋ ๊ฒฝ์ฐ์ ์ฆ์ ๋ณํฉํ๋ค.
create pull request
๋จ๊ณ ์ดํ์ ๋ค์ ๋จ๊ณ๋ฅผ ์ถ๊ฐํ๋ฉด ๋๋ค. ๋ฉ๋ด์ผ์์ ์ฒ๋ผ create pull request ์ auto merge ๋ฅผ ํตํฉํด ์ฌ์ฉํ๊ธฐ ์ํด์ ๊ฐ์ธ ์์ธ์ค ํ ํฐ(PAT) ์ ์ฌ์ฉํด์ผ ํ๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
- name: Create Pull Request to main
id: create_pr
uses: peter-evans/create-pull-request@v7
with:
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
committer: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
token: ${{ secrets[steps.token-map.outputs.token_var] }}
base: main
branch: ${{ github.event.ref }}
title: "[auto] ${{ github.event.head_commit.message }}"
body: |
์๋ PR ์์ฑ: `${{ github.ref_name }} โ main`
์ปค๋ฐ ๋ฉ์์ง: `${{ github.event.head_commit.message }}`
labels: auto-merge
assignees: ${{ github.actor }}
reviewers: ${{ steps.reviewers.outputs.filtered }}
draft: false
- name: Enable Auto Merge
if: steps.create_pr.outputs.pull-request-operation == 'created' || steps.create_pr.outputs.pull-request-operation == 'updated'
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets[steps.token-map.outputs.token_var] }}
pull-request-number: ${{ steps.create_pr.outputs.pull-request-number }}
merge-method: squash
env:
GH_TOKEN: ${{ secrets[steps.token-map.outputs.token_var] }}
reference
- https://github.com/peter-evans/create-pull-request
- https://github.com/marketplace/actions/enable-pull-request-automerge#enable-pull-request-auto-merge
- https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/automatically-merging-a-pull-request
๋๊ธ๋จ๊ธฐ๊ธฐ