name: deploy on: push: branches: - main workflow_dispatch: permissions: contents: read jobs: deploy: if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main') runs-on: ubuntu-latest timeout-minutes: 30 steps: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 with: dotnet-version: '10.0.x' - run: dotnet restore KArtSell.sln - run: dotnet build KArtSell.sln --no-restore -c Release - name: Publish Release Build run: | dotnet publish -c Release -o ./publish src/KArtSell.Host dotnet publish -c Release -o ./publish src/KArtSell.DbMigrator - name: Deploy to Gitea server (local filesystem) env: KARTSELL_POSTGRES: ${{ secrets.KARTSELL_POSTGRES }} KRX_OPENAPI: ${{ secrets.KRX_OPENAPI }} OPENDART_API: ${{ secrets.OPENDART_API }} KIS_APP_KEY: ${{ secrets.KIS_APP_KEY }} KIS_APP_SECRET: ${{ secrets.KIS_APP_SECRET }} run: | # Gitea 서버 동일 파일시스템으로 배포 DEPLOY_PATH="/app/kartsell" echo "📦 Deploying to $DEPLOY_PATH..." # 배포 디렉토리 생성 (sudo 사용) if [ ! -d "$DEPLOY_PATH" ]; then sudo mkdir -p "$DEPLOY_PATH" sudo chown -R $USER:$USER "$DEPLOY_PATH" echo "✅ Created $DEPLOY_PATH" fi # 기존 백업 if [ -d "$DEPLOY_PATH/current" ]; then BACKUP_DIR="$DEPLOY_PATH/backup-$(date +%s)" sudo mv "$DEPLOY_PATH/current" "$BACKUP_DIR" echo "✅ Backed up previous version to $BACKUP_DIR" fi # 새 버전 배포 sudo cp -r ./publish "$DEPLOY_PATH/current" sudo chown -R $USER:$USER "$DEPLOY_PATH/current" sudo chmod +x "$DEPLOY_PATH/current/KArtSell.Host" echo "✅ Files deployed successfully" echo "✅ Release build deployed to $DEPLOY_PATH/current" echo "" echo "📋 Next steps on server:" echo " 1. SSH: ssh kjh2064@178.104.200.7" echo " 2. Migrate: cd $DEPLOY_PATH/current && export KARTSELL_POSTGRES='$KARTSELL_POSTGRES' && dotnet KArtSell.DbMigrator.dll" echo " 3. Restart: sudo systemctl restart kartsell" echo " 4. Check: curl https://kartsell.taxbaik.com/" echo "" echo "✅ Deployment completed" notify: if: always() needs: deploy runs-on: ubuntu-latest steps: - name: Notify deployment status env: TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} run: | STATUS="${{ needs.deploy.result }}" if [ "$STATUS" = "success" ]; then MESSAGE="✅ K-ArtSell Aegis deployed successfully to production" else MESSAGE="❌ K-ArtSell Aegis deployment failed" fi curl -X POST "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage" \ -d "chat_id=$TELEGRAM_CHAT_ID" \ -d "text=$MESSAGE" \ -d "parse_mode=HTML" || echo "Telegram notification failed"