Build and Deploy Executables #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Deploy Executables # 워크플로우의 전체 이름 | |
| # GitHub 웹사이트의 'Releases' 탭에서 'Publish release' 버튼을 눌렀을 때만 파이프라인이 실행 | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| jobs: | |
| # ================================== | |
| # 1. 파이프라인 시작 알림 | |
| # ================================== | |
| start: | |
| 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: | |
| needs: start | |
| 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 }} | |
| # 2단계: 빌드된 실행 파일들을 Front 레포지토리에 배포하는 잡 | |
| deploy: | |
| # build 잡이 성공해야 실행됨 | |
| needs: build | |
| 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 '[email protected]' | |
| git add . | |
| # 변경 사항이 있을 때만 커밋 및 푸시 | |
| if git diff-index --quiet HEAD; then | |
| echo "No changes to commit." | |
| else | |
| git commit -m "feat: AI 실행 파일 업데이트 (${{ github.ref_name }})" | |
| git push | |
| fi | |
| # ================================== | |
| # 파이프라인 최종 결과 알림 | |
| # ================================== | |
| finish: | |
| needs: deploy | |
| runs-on: ubuntu-latest | |
| if: always() | |
| 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 }} |