Restart Northflank Service #24
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: Restart Northflank Service | |
| on: | |
| workflow_run: | |
| workflows: ["Build and push Docker images"] | |
| types: | |
| - completed | |
| jobs: | |
| northflank: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Restart Northflank Service | |
| env: | |
| NORTHFLANK_API_TOKEN: ${{ secrets.NORTHFLANK_API_TOKEN }} | |
| NORTHFLANK_PROJECT_ID: ${{ secrets.NORTHFLANK_PROJECT_ID }} | |
| NORTHFLANK_SERVICE_ID: ${{ secrets.NORTHFLANK_SERVICE_ID }} | |
| run: | | |
| echo "🚀 Preparing to restart Northflank service..." | |
| REQUIRED=(NORTHFLANK_API_TOKEN NORTHFLANK_PROJECT_ID NORTHFLANK_SERVICE_ID) | |
| for var in "${REQUIRED[@]}"; do | |
| if [ -z "${!var}" ]; then | |
| echo "❌ Error: $var environment variable is missing, please check repository Secrets." | |
| exit 1 | |
| fi | |
| done | |
| echo "Calling Northflank API to send restart request..." | |
| RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}\n" -X POST "https://api.northflank.com/v1/projects/$NORTHFLANK_PROJECT_ID/services/$NORTHFLANK_SERVICE_ID/restart" \ | |
| -H "Authorization: Bearer $NORTHFLANK_API_TOKEN" \ | |
| -H "Content-Type: application/json") | |
| HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS" | tail -n 1 | awk -F":" '{print $2}') | |
| if [ "$HTTP_STATUS" -eq 200 ] || [ "$HTTP_STATUS" -eq 204 ]; then | |
| echo "✅ Successfully triggered Northflank service restart!" | |
| else | |
| echo "❌ Failed to trigger Northflank service restart! (HTTP Status: $HTTP_STATUS)" | |
| exit 1 | |
| fi |