|
| 1 | +name: Deploy to RunPod |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +env: |
| 8 | + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/topic-worker |
| 9 | + |
| 10 | +jobs: |
| 11 | + lint-and-test: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - uses: astral-sh/setup-uv@v4 |
| 17 | + with: |
| 18 | + version: "latest" |
| 19 | + |
| 20 | + - uses: actions/setup-python@v5 |
| 21 | + with: |
| 22 | + python-version: "3.11" |
| 23 | + |
| 24 | + - name: Install dependencies |
| 25 | + run: uv sync |
| 26 | + |
| 27 | + - name: Lint |
| 28 | + run: | |
| 29 | + uv run ruff check src/ tests/ |
| 30 | + uv run ruff format --check src/ tests/ |
| 31 | +
|
| 32 | + - name: Test |
| 33 | + run: uv run pytest tests/ -v |
| 34 | + |
| 35 | + build-and-push: |
| 36 | + needs: lint-and-test |
| 37 | + runs-on: ubuntu-latest |
| 38 | + steps: |
| 39 | + - name: Notify Discord deployment started |
| 40 | + uses: Ilshidur/action-discord@0.4.0 |
| 41 | + env: |
| 42 | + DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }} |
| 43 | + DISCORD_USERNAME: "IShowSpeed" |
| 44 | + DISCORD_AVATAR: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTumYcOCdUsVMQj9L_eYWlZDe-9MR_R42jp5Q&s" |
| 45 | + with: |
| 46 | + args: "CHAT CHAT CHAT!!! 🏃💨 si ${{github.actor}} kay nag deploy sa Topic Worker to PRODUCTION!!! Hold on let me cook 🔥🔥🔥" |
| 47 | + |
| 48 | + - uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Set up Docker Buildx |
| 51 | + uses: docker/setup-buildx-action@v3 |
| 52 | + |
| 53 | + - name: Log in to Docker Hub |
| 54 | + uses: docker/login-action@v3 |
| 55 | + with: |
| 56 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 57 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 58 | + |
| 59 | + - name: Extract version from release tag |
| 60 | + id: version |
| 61 | + run: echo "tag=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" |
| 62 | + |
| 63 | + - name: Build and push |
| 64 | + uses: docker/build-push-action@v6 |
| 65 | + with: |
| 66 | + context: . |
| 67 | + push: true |
| 68 | + platforms: linux/amd64 |
| 69 | + tags: | |
| 70 | + ${{ env.IMAGE_NAME }}:${{ steps.version.outputs.tag }} |
| 71 | + ${{ env.IMAGE_NAME }}:latest |
| 72 | + cache-from: type=gha |
| 73 | + cache-to: type=gha,mode=max |
| 74 | + |
| 75 | + update-runpod: |
| 76 | + needs: build-and-push |
| 77 | + runs-on: ubuntu-latest |
| 78 | + steps: |
| 79 | + - name: Extract version from release tag |
| 80 | + id: version |
| 81 | + run: echo "tag=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" |
| 82 | + |
| 83 | + - name: Update RunPod template image |
| 84 | + run: | |
| 85 | + response=$(curl -s -w "\n%{http_code}" -X PATCH \ |
| 86 | + "https://rest.runpod.io/v1/templates/${{ secrets.RUNPOD_TEMPLATE_ID }}" \ |
| 87 | + -H "Authorization: Bearer ${{ secrets.RUNPOD_API_KEY }}" \ |
| 88 | + -H "Content-Type: application/json" \ |
| 89 | + -d "{\"imageName\": \"docker.io/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.tag }}\"}") |
| 90 | + http_code=$(echo "$response" | tail -1) |
| 91 | + body=$(echo "$response" | head -n -1) |
| 92 | + echo "Response: $body" |
| 93 | + if [ "$http_code" -ge 400 ]; then |
| 94 | + echo "::error::Failed to update RunPod template (HTTP $http_code)" |
| 95 | + exit 1 |
| 96 | + fi |
| 97 | + echo "Template updated to ${{ env.IMAGE_NAME }}:${{ steps.version.outputs.tag }}" |
| 98 | +
|
| 99 | + - name: Notify Discord deployment failed |
| 100 | + if: failure() |
| 101 | + uses: Ilshidur/action-discord@0.4.0 |
| 102 | + env: |
| 103 | + DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }} |
| 104 | + DISCORD_USERNAME: "IShowSpeed" |
| 105 | + DISCORD_AVATAR: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTumYcOCdUsVMQj9L_eYWlZDe-9MR_R42jp5Q&s" |
| 106 | + with: |
| 107 | + args: "Bro... 💀 ang Topic Worker deployment ni ${{github.actor}} FAILED!!! This is NOT speed chat, this is NOT speed 😭🔴" |
| 108 | + |
| 109 | + - name: Notify Discord deployment succeeded |
| 110 | + if: success() |
| 111 | + uses: Ilshidur/action-discord@0.4.0 |
| 112 | + env: |
| 113 | + DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }} |
| 114 | + DISCORD_USERNAME: "IShowSpeed" |
| 115 | + DISCORD_AVATAR: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTumYcOCdUsVMQj9L_eYWlZDe-9MR_R42jp5Q&s" |
| 116 | + with: |
| 117 | + args: "WWWWWW Topic Worker deployed to Production!!! ⚡🚀 si ${{github.actor}} ikaw na jud dawg, SUUUUIIII ✅🐐" |
0 commit comments