18
18
with :
19
19
repository : ${{ github.repository }}
20
20
token : ${{ secrets.GITHUB_TOKEN }}
21
- fetch-depth : 0 # 모든 히스토리 가져오기
21
+ fetch-depth : 0 # 모든 히스토리 가져오기
22
22
23
23
- name : Configure Git
24
24
run : |
@@ -34,22 +34,26 @@ jobs:
34
34
run : |
35
35
git checkout -B master origin/master
36
36
37
+ # ***********************
38
+ # 충돌 자동 해결을 위해 -X theirs 추가
39
+ # ***********************
37
40
- name : Merge Upstream/master into master
38
41
run : |
39
- git merge upstream/master --no-edit
42
+ # 업스트림 변경을 우선으로(충돌 발생 시 upstream/master 변경사항 사용)
43
+ git merge upstream/master -X theirs --no-edit
40
44
41
45
# .github 디렉토리 하위 모든 파일 삭제
42
46
git rm -r --cached .github || true
43
47
rm -rf .github
44
48
45
- # 변경 사항 스테이지
49
+ # 변경 사항 스테이징
46
50
git add .
47
51
48
- # 로그 출력: 현재 스테이지에 있는 파일 확인
52
+ # 로그 출력: 현재 스테이지에 있는 파일
49
53
echo "Staged files:"
50
54
git diff --cached --name-only
51
55
52
- # 커밋 ( 변경 사항이 있을 경우)
56
+ # 변경 사항이 있을 경우에만 커밋
53
57
git commit -m "Sync with upstream (removing .github directory)" || echo "No changes to commit"
54
58
shell : bash
55
59
@@ -67,28 +71,24 @@ jobs:
67
71
cat changes.diff
68
72
shell : bash
69
73
70
- - name : Check Existing PRs
74
+ - name : Check Existing PRs for Master Sync
71
75
id : existing-prs
72
76
run : |
73
- # 기존 PR 가져오기
74
77
RESPONSE=$(curl -s \
75
78
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
76
79
-H "Accept: application/vnd.github.v3+json" \
77
80
https://api.github.com/repos/${{ github.repository }}/pulls)
78
-
79
- # "sync-upstream-"으로 시작하는 PR 필터링
80
81
EXISTING_PR=$(echo "$RESPONSE" | jq -r '.[] | select(.head.ref | startswith("sync-upstream-")) | .head.ref' | tr '\n' ' ')
81
-
82
82
if [[ -n "$EXISTING_PR" ]]; then
83
83
echo "existing_pr=true" >> $GITHUB_ENV
84
84
echo "existing_pr_ref=$EXISTING_PR" >> $GITHUB_ENV
85
85
else
86
86
echo "existing_pr=false" >> $GITHUB_ENV
87
87
fi
88
- echo "Existing PRs: $EXISTING_PR"
88
+ echo "Existing PRs for master sync : $EXISTING_PR"
89
89
shell : bash
90
90
91
- - name : Compare Changes with Existing PRs
91
+ - name : Compare Changes with Existing PRs for Master Sync
92
92
id : compare-changes
93
93
if : env.existing_pr == 'true' && env.changes == 'true'
94
94
run : |
@@ -116,14 +116,13 @@ jobs:
116
116
PR_NUMBER=$(curl -s \
117
117
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
118
118
-H "Accept: application/vnd.github.v3+json" \
119
- ${{ github.repository }}/pulls \
119
+ https://api.github.com/repos/ ${{ github.repository }}/pulls \
120
120
| jq -r '.[] | select(.head.ref=="'$pr_ref'") | .number')
121
-
122
121
echo "Closing PR #$PR_NUMBER"
123
122
curl -X PATCH \
124
123
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
125
124
-H "Accept: application/vnd.github.v3+json" \
126
- ${{ github.repository }}/pulls/$PR_NUMBER \
125
+ https://api.github.com/repos/ ${{ github.repository }}/pulls/$PR_NUMBER \
127
126
-d '{"state":"closed"}'
128
127
done
129
128
fi
@@ -152,26 +151,93 @@ jobs:
152
151
}'
153
152
shell : bash
154
153
155
- - name : Update master-ko Branch (excluding src)
154
+ # ===== master-ko 업데이트 파트 =====
155
+
156
+ - name : Check Existing PRs for master-ko Update
157
+ id : existing-prs-ko
158
+ run : |
159
+ RESPONSE=$(curl -s \
160
+ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
161
+ -H "Accept: application/vnd.github.v3+json" \
162
+ "https://api.github.com/repos/${{ github.repository }}/pulls")
163
+ EXISTING_KO_PR=$(echo "$RESPONSE" | jq -r '.[] | select(.head.ref | startswith("update-master-ko-")) | .head.ref' | tr '\n' ' ')
164
+ if [[ -n "$EXISTING_KO_PR" ]]; then
165
+ echo "existing_pr_ko=true" >> $GITHUB_ENV
166
+ echo "existing_pr_ko_ref=$EXISTING_KO_PR" >> $GITHUB_ENV
167
+ else
168
+ echo "existing_pr_ko=false" >> $GITHUB_ENV
169
+ fi
170
+ echo "Existing PRs for master-ko update: $EXISTING_KO_PR"
171
+ shell : bash
172
+
173
+ - name : Prepare master-ko Update
156
174
run : |
157
175
# 최신 master 브랜치 체크아웃
158
176
git checkout master
159
- # master-ko 브랜치가 원격에 존재하면 체크아웃 , 없으면 새로 생성
177
+ # 원격의 master-ko 브랜치가 있으면 가져오고 , 없으면 새로 생성
160
178
git fetch origin master-ko || true
161
179
git checkout -B master-ko origin/master-ko || git checkout -B master-ko
162
180
163
181
# master 브랜치의 모든 파일을 가져오되, src는 제외하고 master-ko의 기존 src 유지
164
- git checkout master -- .
165
- git checkout master-ko -- src
182
+ git checkout master -- . ":(exclude)src"
166
183
167
184
git add .
168
185
git commit -m "Update master-ko with upstream changes (excluding src)" || echo "No changes to commit"
186
+ shell : bash
169
187
170
- # 새로운 브랜치로 PR 생성
188
+ - name : Compare Changes with Existing master-ko PRs
189
+ id : compare-changes-ko
190
+ if : env.existing_pr_ko == 'true'
191
+ run : |
192
+ ALL_INCLUDED=true
193
+ EXISTING_BRANCH=""
194
+ for pr_ref in ${{ env.existing_pr_ko_ref }}
195
+ do
196
+ echo "Fetching branch: $pr_ref"
197
+ git fetch origin "$pr_ref:$pr_ref-branch"
198
+ echo "Comparing updated master-ko with existing PR branch (excluding src)"
199
+ if ! git diff --quiet master-ko "$pr_ref-branch" -- . ':(exclude)src'; then
200
+ ALL_INCLUDED=false
201
+ EXISTING_BRANCH=$pr_ref
202
+ break
203
+ fi
204
+ done
205
+
206
+ if [ "$ALL_INCLUDED" = true ]; then
207
+ echo "ko_diff=false" >> $GITHUB_ENV
208
+ else
209
+ echo "ko_diff=true" >> $GITHUB_ENV
210
+ if [ -n "$EXISTING_BRANCH" ]; then
211
+ PR_NUMBER=$(curl -s \
212
+ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
213
+ -H "Accept: application/vnd.github.v3+json" \
214
+ "https://api.github.com/repos/${{ github.repository }}/pulls" \
215
+ | jq -r '.[] | select(.head.ref=="'$EXISTING_BRANCH'") | .number')
216
+ echo "Closing master-ko PR #$PR_NUMBER"
217
+ curl -X PATCH \
218
+ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
219
+ -H "Accept: application/vnd.github.v3+json" \
220
+ https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER \
221
+ -d '{"state":"closed"}'
222
+ fi
223
+ fi
224
+ shell : bash
225
+
226
+ - name : Update Existing master-ko PR Branch
227
+ if : env.existing_pr_ko == 'true' && env.ko_diff == 'false'
228
+ run : |
229
+ # 기존 PR 브랜치(첫번째 값)를 사용하여 업데이트
230
+ EXISTING_BRANCH=$(echo "${{ env.existing_pr_ko_ref }}" | awk '{print $1}')
231
+ echo "Pushing updated changes to existing master-ko branch: $EXISTING_BRANCH"
232
+ git push origin master-ko:"$EXISTING_BRANCH" --force
233
+ shell : bash
234
+
235
+ - name : Create New PR for master-ko Update
236
+ if : env.ko_diff == 'true' || env.existing_pr_ko == 'false'
237
+ run : |
171
238
BRANCH_NAME=update-master-ko-$(date +%Y%m%d%H%M%S)
172
239
git checkout -b $BRANCH_NAME
173
240
git push origin $BRANCH_NAME
174
-
175
241
curl -X POST \
176
242
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
177
243
-H "Accept: application/vnd.github.v3+json" \
@@ -182,4 +248,4 @@ jobs:
182
248
"head": "'"${BRANCH_NAME}"'",
183
249
"base": "master-ko"
184
250
}'
185
- shell : bash
251
+ shell : bash
0 commit comments