Created
September 5, 2023 10:34
-
-
Save b-bot/cfc4bd0e14bb16f4334eb499cf6d40c6 to your computer and use it in GitHub Desktop.
Flightcontrol Webhook GitHub Action
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: Flightcontrol Webhook Deployment | |
env: | |
DEPLOYMENT_URL: "" | |
on: workflow_dispatch | |
jobs: | |
backend-deploy: | |
runs-on: ubuntu-latest | |
timeout-minutes: 25 | |
steps: | |
- name: Trigger Backend Deployment | |
id: deployment-id | |
run: | | |
RESPONSE=$(curl -s -X GET "${{ secrets.FLIGHTCONTROL_WEBHOOK }}") | |
curl_exit_code=$? | |
if [ $curl_exit_code -ne 0 ]; then | |
echo "Failed to retrieve response. curl command exited with code $curl_exit_code." | |
exit 1 | |
fi | |
DEPLOYMENT_ID=$(echo "$RESPONSE" | jq -r '.deploymentId') | |
if [ -z "$DEPLOYMENT_ID" ]; then | |
echo "Failed to retrieve deployment ID" | |
exit 1 | |
fi | |
echo "INFO: Deployment ID is $DEPLOYMENT_ID" | |
echo "DEPLOYMENT_ID=$DEPLOYMENT_ID" >> $GITHUB_OUTPUT | |
# Poll server for 10 x 150 = 1500 seconds for deployment status | |
# Loops should be increased if deployment takes longer than 25 minutes | |
- name: Poll Deployment Status | |
id: deployment-status | |
run: | | |
success=false | |
for i in {1..150}; do | |
echo "Attempt $i of 150: Checking deployment status..." | |
RESPONSE=$(curl -s -X GET "https://app.flightcontrol.dev/api/deployments/${{ steps.deployment-id.outputs.DEPLOYMENT_ID }}" -H "Authorization: ${{ secrets.FLIGHTCONTROL_API_KEY }}") | |
STATUS=$(echo "$RESPONSE" | jq -r '.status') | |
if [ "$STATUS" == "SUCCESS" ] || [ "$STATUS" == "NO_CHANGE" ]; then | |
echo "STATUS=SUCCESS" >> $GITHUB_OUTPUT | |
echo "OK: Deployment status is $STATUS" | |
success=true | |
break | |
elif [ "$STATUS" == "BUILDING" ] || [ "$STATUS" == "DEPLOYING" ] || [ "$STATUS" == "PENDING" ] || [ "$STATUS" == "INPROGRESS" ] || [ "$STATUS" == "PROVISIONING" ] || [ "$STATUS" == "PENDING_DEPENDENCY" ]; then | |
echo "INFO: Deployment status is $STATUS. Sleeping for 10 seconds..." | |
sleep 10 | |
elif [ -z "$STATUS" ] || [ "$STATUS" == "ERROR" ] || [ "$STATUS" == "ERROR_CONFIG" ] || [ "$STATUS" == "CANCELLED" ] || [ "$STATUS" == "GIT_CLONE_ERROR" ] || [ "$STATUS" == "BUILD_ERROR" ] || [ "$STATUS" == "DEPLOY_ERROR" ]; then | |
echo "ERROR: Deployment status is $STATUS" | |
exit 1 | |
else | |
echo "ERROR: Deployment status is $STATUS" | |
exit 1 | |
fi | |
done | |
if [ "$success" = false ]; then | |
echo "ERROR: Deployment status is $STATUS" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment