Skip to content

Commit 790f7e1

Browse files
committed
refactor: extract GitHub API client and remove code duplication
- Extract shared GitHub API client (internal/github/client.go) - Consolidate file staging logic into shared package - Remove duplicate PR validation (delegate to config.Validate) - Remove unused executor package - Replace magic string error check with proper type assertion - Extract hardcoded values to named constants
1 parent 9a9317c commit 790f7e1

15 files changed

Lines changed: 369 additions & 942 deletions

File tree

.github/workflows/ci.yml

Lines changed: 25 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- '.github/workflows/**'
1010
- '**/*.md'
1111
- 'test/**'
12-
- 'backup/**/*'
12+
- 'backup/**'
1313
workflow_dispatch:
1414

1515
permissions:
@@ -131,11 +131,6 @@ jobs:
131131
uses: actions/checkout@v6
132132
with:
133133
fetch-depth: 10
134-
# token: ${{ secrets.ACCESS_TOKEN }}
135-
136-
# - name: Create Test File
137-
# run: |
138-
# echo "$(date +%s)-$RANDOM" > test/test2.txt
139134

140135
- name: Test Auto Branch Local Action (auto_branch false)
141136
uses: ./
@@ -186,22 +181,6 @@ jobs:
186181
github_token: ${{ secrets.PAT_TOKEN }}
187182
pr_closed: true
188183

189-
# - name: Create Test File
190-
# run: |
191-
# echo "$(date +%s)-$RANDOM" > test/test3.txt
192-
193-
# - name: Test User Branch Local Action
194-
# uses: ./
195-
# with:
196-
# user_email: actions@github.com
197-
# user_name: GitHub Actions
198-
# create_pr: true
199-
# auto_branch: false
200-
# branch: feature/pr-test-branch
201-
# pr_base: main
202-
# repository_path: test
203-
# file_pattern: .
204-
205184
test-skip-if-empty:
206185
name: Test Skip If Empty
207186
runs-on: ubuntu-latest
@@ -231,7 +210,7 @@ jobs:
231210
github_token: ${{ secrets.PAT_TOKEN }}
232211
pr_closed: true
233212

234-
# 변경사항이 있을 때는 skip되지 않는지 확인
213+
# Verify skip does not happen when changes exist
235214
- name: Create Test File
236215
run: |
237216
echo "$(date +%s)-$RANDOM" > test/skip-test.txt
@@ -288,113 +267,18 @@ jobs:
288267
This PR will be automatically closed after creation.
289268
github_token: ${{ secrets.PAT_TOKEN }}
290269

291-
# test-multi-file-pattern:
292-
# name: Test Multiple File Pattern
293-
# runs-on: ubuntu-latest
294-
# needs: [test-pr-auto-close-pr-body]
295-
296-
# steps:
297-
# - name: Checkout
298-
# uses: actions/checkout@v6
299-
# with:
300-
# fetch-depth: 10
301-
# token: ${{ secrets.PAT_TOKEN }}
302-
303-
# - name: Setup Git User
304-
# run: |
305-
# git config --global user.email "actions@github.com"
306-
# git config --global user.name "GitHub Actions"
307-
308-
# - name: Create Test Files and Add to Git
309-
# run: |
310-
# # 테스트 디렉토리 생성
311-
# mkdir -p test/multi-pattern
312-
# cd test/multi-pattern
313-
314-
# # 테스트 파일 생성
315-
# echo "Test file 1 - $(date +%s)" > file1.txt
316-
# echo "Test file 2 - $(date +%s)" > file2.md
317-
# echo "Test file 3 - $(date +%s)" > file3.json
318-
# echo "Test file 4 - $(date +%s)" > file4.txt
319-
320-
# # 파일 확인
321-
# echo "디렉토리 내용:"
322-
# ls -la
323-
324-
# # 경로 돌아가기
325-
# cd ../..
326-
327-
# - name: Test Commit with Multiple File Pattern (space separated)
328-
# uses: ./
329-
# with:
330-
# user_email: actions@github.com
331-
# user_name: GitHub Actions
332-
# commit_message: "test: commit multiple files with space-separated pattern"
333-
# branch: main # 메인 브랜치 사용
334-
# repository_path: "test/multi-pattern" # 상대 경로 수정
335-
# file_pattern: "file1.txt file2.md"
336-
337-
# - name: Verify Files Added
338-
# run: |
339-
# git log -1 --name-status
340-
# # Verify txt and md files were added but json was not
341-
# if git log -1 --name-status | grep -q "test/multi-pattern/file1.txt" && \
342-
# git log -1 --name-status | grep -q "test/multi-pattern/file2.md" && \
343-
# ! git log -1 --name-status | grep -q "test/multi-pattern/file3.json"; then
344-
# echo "✅ Test passed: Only specified patterns were committed"
345-
# else
346-
# echo "❌ Test failed: Incorrect files were committed"
347-
# exit 1
348-
# fi
349-
350-
# - name: Test Commit with Another Multiple Pattern
351-
# uses: ./
352-
# with:
353-
# user_email: actions@github.com
354-
# user_name: GitHub Actions
355-
# commit_message: "test: commit JSON file with separate pattern"
356-
# branch: main # 메인 브랜치 사용
357-
# repository_path: "test/multi-pattern" # 상대 경로 수정
358-
# file_pattern: "file3.json file4.txt"
359-
360-
# - name: Verify Second Pattern
361-
# run: |
362-
# git log -1 --name-status
363-
# # Verify json and specific txt file were added
364-
# if git log -1 --name-status | grep -q "test/multi-pattern/file3.json" && \
365-
# git log -1 --name-status | grep -q "test/multi-pattern/file4.txt"; then
366-
# echo "✅ Test passed: Second pattern correctly committed files"
367-
# else
368-
# echo "❌ Test failed: Second pattern did not commit correct files"
369-
# exit 1
370-
# fi
371-
372270
test-pr-dry-run:
373271
name: Test PR Dry Run
374272
runs-on: ubuntu-latest
375273
needs: [test-pr-auto-close-pr-body]
376-
# needs: [test-multi-file-pattern]
377274

378275
steps:
379276
- name: Checkout
380277
uses: actions/checkout@v6
381278
with:
382279
fetch-depth: 10
383280
token: ${{ secrets.PAT_TOKEN }}
384-
385-
# - name: Create Test File for PR and Add to Git
386-
# run: |
387-
# mkdir -p test
388-
# echo "Test file for PR dry run - $(date +%s)" > test/pr-dry-run-test.txt
389-
390-
# # 파일 확인
391-
# echo "생성된 PR 테스트 파일:"
392-
# ls -la test/
393-
394-
# # 경로 돌아가기
395-
# cd ../..
396-
397-
281+
398282
- name: Test PR Dry Run (auto_branch false)
399283
uses: ./
400284
with:
@@ -411,4 +295,25 @@ jobs:
411295
file_pattern: "pr-dry-run-test.txt"
412296
github_token: ${{ secrets.PAT_TOKEN }}
413297
pr_dry_run: true
414-
298+
299+
ci-result:
300+
name: CI Result
301+
if: always()
302+
needs:
303+
- unit-tests
304+
- build-and-push-docker
305+
- test-action-auto-branch-false
306+
- test-action-auto-branch-true
307+
- test-skip-if-empty
308+
- test-pr-auto-close-pr-body
309+
- test-pr-dry-run
310+
runs-on: ubuntu-latest
311+
steps:
312+
- name: Check all jobs
313+
run: |
314+
if [ "${{ contains(needs.*.result, 'failure') }}" = "true" ] || \
315+
[ "${{ contains(needs.*.result, 'cancelled') }}" = "true" ]; then
316+
echo "[FAIL]Some jobs failed or were cancelled"
317+
exit 1
318+
fi
319+
echo "[PASS]All CI jobs passed"

.github/workflows/use-action.yml

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Example Workflow using Go Git Commit Action
1+
name: Smoke Test (Released Action)
22

33
on:
44
workflow_dispatch:
@@ -8,19 +8,22 @@ on:
88
required: true
99
default: 'true'
1010
workflow_run:
11-
workflows: ["Generate changelog"]
11+
workflows: ["Create release"]
1212
types:
1313
- completed
1414

1515
permissions:
1616
contents: write
1717

1818
jobs:
19-
acton-module-tag-reference:
20-
name: acton-module-tag-reference
19+
smoke-test-tag-reference:
20+
name: Smoke Test (Tag Reference)
2121
runs-on: ubuntu-latest
22+
if: >
23+
github.event_name == 'workflow_dispatch' ||
24+
github.event.workflow_run.conclusion == 'success'
2225
steps:
23-
- name: Checkout infrastructure repository
26+
- name: Checkout
2427
uses: actions/checkout@v6
2528
with:
2629
fetch-depth: 0
@@ -59,12 +62,12 @@ jobs:
5962
delete_tag: true
6063
github_token: ${{ secrets.PAT_TOKEN }}
6164

62-
acton-module-auto-branch-false:
63-
name: acton-module-auto-branch-false
64-
needs: [acton-module-tag-reference]
65+
smoke-test-auto-branch-false:
66+
name: Smoke Test (Auto Branch False)
67+
needs: [smoke-test-tag-reference]
6568
runs-on: ubuntu-latest
6669
steps:
67-
- name: Checkout infrastructure repository
70+
- name: Checkout
6871
uses: actions/checkout@v6
6972
with:
7073
token: ${{ secrets.PAT_TOKEN }}
@@ -85,12 +88,12 @@ jobs:
8588
github_token: ${{ secrets.PAT_TOKEN }}
8689
pr_labels: "test,automated,auto-branch-false-test"
8790

88-
acton-module-auto-branch-true:
89-
name: acton-module-auto-branch-true
90-
needs: [acton-module-auto-branch-false]
91+
smoke-test-auto-branch-true:
92+
name: Smoke Test (Auto Branch True)
93+
needs: [smoke-test-auto-branch-false]
9194
runs-on: ubuntu-latest
9295
steps:
93-
- name: Checkout infrastructure repository
96+
- name: Checkout
9497
uses: actions/checkout@v6
9598
with:
9699
token: ${{ secrets.PAT_TOKEN }}
@@ -114,10 +117,10 @@ jobs:
114117
github_token: ${{ secrets.PAT_TOKEN }}
115118
pr_labels: "test,automated,auto-branch-true-test"
116119

117-
test-skip-if-empty:
118-
name: Test Skip If Empty
120+
smoke-test-skip-if-empty:
121+
name: Smoke Test (Skip If Empty)
119122
runs-on: ubuntu-latest
120-
needs: [acton-module-auto-branch-true]
123+
needs: [smoke-test-auto-branch-true]
121124
steps:
122125
- name: Checkout
123126
uses: actions/checkout@v6
@@ -143,7 +146,7 @@ jobs:
143146
github_token: ${{ secrets.PAT_TOKEN }}
144147
pr_closed: true
145148

146-
# 변경사항이 있을 때는 skip되지 않는지 확인
149+
# Verify skip does not happen when changes exist
147150
- name: Create Test File
148151
run: |
149152
echo "$(date +%s)-$RANDOM" > test/skip-test.txt
@@ -166,10 +169,10 @@ jobs:
166169
github_token: ${{ secrets.PAT_TOKEN }}
167170
pr_closed: true
168171

169-
test-pr-auto-close-pr-body:
170-
name: Test PR Auto Close
172+
smoke-test-pr-auto-close:
173+
name: Smoke Test (PR Auto Close)
171174
runs-on: ubuntu-latest
172-
needs: [test-skip-if-empty]
175+
needs: [smoke-test-skip-if-empty]
173176
steps:
174177
- name: Checkout
175178
uses: actions/checkout@v6
@@ -196,32 +199,18 @@ jobs:
196199
This PR will be automatically closed after creation.
197200
github_token: ${{ secrets.PAT_TOKEN }}
198201

199-
test-pr-dry-run:
200-
name: Test PR Dry Run
202+
smoke-test-pr-dry-run:
203+
name: Smoke Test (PR Dry Run)
201204
runs-on: ubuntu-latest
202-
needs: [test-pr-auto-close-pr-body]
203-
# needs: [test-multi-file-pattern]
205+
needs: [smoke-test-pr-auto-close]
204206

205207
steps:
206208
- name: Checkout
207209
uses: actions/checkout@v6
208210
with:
209211
fetch-depth: 10
210212
token: ${{ secrets.PAT_TOKEN }}
211-
212-
# - name: Create Test File for PR and Add to Git
213-
# run: |
214-
# mkdir -p test
215-
# echo "Test file for PR dry run - $(date +%s)" > test/pr-dry-run-test.txt
216-
217-
# # 파일 확인
218-
# echo "생성된 PR 테스트 파일:"
219-
# ls -la test/
220-
221-
# # 경로 돌아가기
222-
# cd ../..
223-
224-
213+
225214
- name: Test PR Dry Run (auto_branch false)
226215
uses: somaz94/go-git-commit-action@v1
227216
with:

0 commit comments

Comments
 (0)