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 environment: name: production url: https://kartsell.taxbaik.com 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 - run: dotnet publish -c Release -o /tmp/kartsell-publish src/KArtSell.Host - name: Deploy to production server env: DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} DEPLOY_USER: ${{ secrets.DEPLOY_USER }} DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} 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: | mkdir -p ~/.ssh echo "$DEPLOY_KEY" > ~/.ssh/deploy_key chmod 600 ~/.ssh/deploy_key ssh-keyscan -H $DEPLOY_HOST >> ~/.ssh/known_hosts 2>/dev/null || true # Copy published app to server scp -i ~/.ssh/deploy_key -r /tmp/kartsell-publish/* $DEPLOY_USER@$DEPLOY_HOST:/app/kartsell/ # Stop old service, deploy new, start new ssh -i ~/.ssh/deploy_key $DEPLOY_USER@$DEPLOY_HOST << 'EOF' set -e cd /app/kartsell # Stop running instance (if any) sudo systemctl stop kartsell || true sleep 2 # Run migrations export KARTSELL_POSTGRES="$KARTSELL_POSTGRES" dotnet KArtSell.DbMigrator.dll || echo "Migration completed with warnings" # Restart service sudo systemctl start kartsell # Health check sleep 5 if curl -f http://127.0.0.1:5002/health || true; then echo "✅ Deployment successful" else echo "⚠️ Health check inconclusive (service may still be starting)" fi EOF rm ~/.ssh/deploy_key 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"