-
Notifications
You must be signed in to change notification settings - Fork 0
178 lines (162 loc) · 6.6 KB
/
deploy_executables.yml
File metadata and controls
178 lines (162 loc) · 6.6 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: Build and Deploy Executables # 워크플로우의 전체 이름
# GitHub 웹사이트의 'Releases' 탭에서 'Publish release' 버튼을 눌렀을 때만 파이프라인이 실행
on:
release:
types: [published]
workflow_dispatch:
jobs:
# ==================================
# 1. 파이프라인 시작 알림
# ==================================
start:
if: github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- name: Send Pipeline Start Notification
run: |
curl -X POST -H "Content-Type: application/json" \
-d '{
"username": "AI 배포 봇",
"embeds": [{
"description": "**${{ github.ref_name }}** AI 배포를 시작합니다.",
"color": 2243312
}]
}' \
${{ secrets.DISCORD_WEBHOOK_URL }}
# 1단계: 각 OS에서 실행 파일을 빌드하는 잡
build:
strategy:
matrix:
os: [macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
# 1. Git 리포지토리의 소스 코드를 가져옵니다.
- name: Checkout code
uses: actions/checkout@v4
# 2. 워크플로우에서 사용할 파이썬 버전을 설정합니다.
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
# 3. 의존성 캐싱으로 빌드 속도를 향상시킵니다.
- name: Cache pip dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
# 4. requirements.txt에 명시된 라이브러리를 설치합니다.
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# 5. OS에 따라 실행 파일의 이름(.exe 확장자 등)을 결정합니다.
- name: Set executable name
id: set_name
shell: bash
run: |
if [ "${{ runner.os }}" == "macOS" ]; then
echo "EXE_NAME=qgenie-ai" >> $GITHUB_ENV
elif [ "${{ runner.os }}" == "Windows" ]; then
echo "EXE_NAME=qgenie-ai.exe" >> $GITHUB_ENV
fi
# 6. PyInstaller를 사용해 파이썬 코드를 실행 파일로 만듭니다.
- name: Build executable with PyInstaller
run: pyinstaller --clean --onefile --name ${{ env.EXE_NAME }} src/main.py
# 7. 빌드된 실행 파일을 다음 단계(deploy)에서 사용할 수 있도록 아티팩트로 업로드합니다.
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: executable-${{ runner.os }}
path: dist/${{ env.EXE_NAME }}
retention-days: 1
# 2단계: 빌드된 실행 파일들을 Front 레포지토리에 배포하는 잡
deploy:
# build 잡이 성공해야 실행됨
needs: build
if: github.event_name == 'release'
runs-on: ubuntu-latest
steps:
# 1. 배포 대상인 Front 리포지토리의 코드를 가져옵니다.
- name: Checkout App Repository
uses: actions/checkout@v4
with:
repository: Queryus/QGenie_app
token: ${{ secrets.PAT_FOR_FRONT_REPO }}
# 배포할 브랜치를 develop으로 변경
ref: develop
# 2. 이전 build 단계에서 업로드한 모든 실행 파일(mac, win)을 다운로드합니다.
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
# 3. 다운로드한 실행 파일들을 정해진 폴더(resources/mac, resources/win)로 이동시킵니다.
- name: Organize files
run: |
mkdir -p resources/mac resources/win
mv artifacts/executable-macOS/qgenie-ai resources/mac/
mv artifacts/executable-Windows/qgenie-ai.exe resources/win/
# 4. 변경된 파일들을 Front 리포지토리에 커밋하고 푸시합니다.
- name: Commit and push changes
run: |
git config --global user.name 'github-actions'
git config --global user.email 'actions@github.com'
git add .
# 변경 사항이 있을 때만 커밋 및 푸시
if git diff-index --quiet HEAD; then
echo "No changes to commit."
else
git commit -m "feat: Update AI executable (${{ github.ref_name }})"
git push
fi
# ==================================
# 파이프라인 최종 결과 알림
# ==================================
finish:
needs: deploy
runs-on: ubuntu-latest
if: always() && github.event_name == 'release'
steps:
- name: Send Success Notification
if: needs.deploy.result == 'success'
run: |
curl -X POST -H "Content-Type: application/json" \
-d '{
"username": "AI 배포 봇",
"embeds": [{
"title": "New AI Release: ${{ github.ref_name }}",
"url": "${{ github.event.release.html_url }}",
"description": "**${{ github.ref_name }}** AI 배포가 성공적으로 완료되었습니다!",
"color": 5167473
}]
}' \
${{ secrets.DISCORD_WEBHOOK_URL }}
- name: Send Failure Notification
if: contains(needs.*.result, 'failure')
run: |
curl -X POST -H "Content-Type: application/json" \
-d '{
"username": "AI 배포 봇",
"embeds": [{
"title": "AI 배포 실패",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"description": "**${{ github.ref_name }}** AI 배포 중 오류가 발생했습니다.",
"color": 15219495
}]
}' \
${{ secrets.DISCORD_WEBHOOK_URL }}
- name: Send Skipped or Cancelled Notification
if: contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped')
run: |
curl -X POST -H "Content-Type: application/json" \
-d '{
"username": "AI 배포 봇",
"embeds": [{
"title": "AI 배포 미완료",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"description": "**${{ github.ref_name }}** AI 배포가 완료되지 않았습니다. (상태: 취소 또는 건너뜀)\n이전 단계에서 문제가 발생했을 수 있습니다.",
"color": 16577629
}]
}' \
${{ secrets.DISCORD_WEBHOOK_URL }}