-
Notifications
You must be signed in to change notification settings - Fork 8
133 lines (113 loc) · 4.33 KB
/
Copy pathff-merge.yml
File metadata and controls
133 lines (113 loc) · 4.33 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: FF-Only Merge to Master
on:
pull_request:
types: [labeled]
check_suite:
types: [completed]
jobs:
ff-merge:
if: |
(github.event_name == 'pull_request' && github.event.label.name == 'ready-to-merge') ||
(github.event_name == 'check_suite' && github.event.check_suite.conclusion == 'success')
runs-on: ubuntu-latest
steps:
- name: PR 조회 및 조건 검증
id: validate
uses: actions/github-script@v7
with:
script: |
let prNumber, headSha;
if (context.eventName === 'pull_request') {
const pr = context.payload.pull_request;
if (pr.base.ref !== 'master' || pr.head.ref !== 'develop' || pr.state !== 'open') {
core.setOutput('ready', 'false');
return;
}
// 레이블을 부착한 주체의 저장소 권한 확인
const { data: perm } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: context.payload.sender.login,
});
if (!['admin', 'write'].includes(perm.permission)) {
core.setOutput('ready', 'false');
return;
}
prNumber = pr.number;
headSha = pr.head.sha;
} else {
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
base: 'master',
head: `${context.repo.owner}:develop`,
});
if (prs.length === 0) {
core.setOutput('ready', 'false');
return;
}
prNumber = prs[0].number;
headSha = prs[0].head.sha;
if (context.payload.check_suite.head_sha !== headSha) {
core.setOutput('ready', 'false');
return;
}
}
// ready-to-merge 레이블 확인
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
const hasLabel = pr.labels.some(l => l.name === 'ready-to-merge');
if (!hasLabel) {
core.setOutput('ready', 'false');
return;
}
// CI 상태 확인
const { data: { check_runs } } = await github.rest.checks.listForRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: headSha,
per_page: 100,
});
const ciRuns = check_runs.filter(r => r.name !== context.job);
const allPassed = ciRuns.length > 0 && ciRuns.every(r =>
r.status === 'completed' &&
['success', 'skipped', 'neutral'].includes(r.conclusion)
);
if (!allPassed) {
core.setOutput('ready', 'false');
return;
}
core.setOutput('ready', 'true');
core.setOutput('head_sha', headSha);
- name: Checkout
if: steps.validate.outputs.ready == 'true'
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
fetch-depth: 0
- name: Git 설정
if: steps.validate.outputs.ready == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: develop 변경 여부 검증
if: steps.validate.outputs.ready == 'true'
run: |
APPROVED_SHA="${{ steps.validate.outputs.head_sha }}"
CURRENT_SHA=$(git rev-parse origin/develop)
if [ "$APPROVED_SHA" != "$CURRENT_SHA" ]; then
echo "레이블 부착 이후 develop이 변경되었습니다."
echo " 레이블 시점 SHA: $APPROVED_SHA"
echo " 현재 SHA: $CURRENT_SHA"
exit 1
fi
- name: FF-Only merge develop → master
if: steps.validate.outputs.ready == 'true'
run: |
git checkout master
git merge --ff-only ${{ steps.validate.outputs.head_sha }}
git push origin master