Skip to content

Instantly share code, notes, and snippets.

@limcheekin
Last active April 9, 2025 02:11
Show Gist options
  • Select an option

  • Save limcheekin/f3417d24e173cc52e6feca6b27c0da24 to your computer and use it in GitHub Desktop.

Select an option

Save limcheekin/f3417d24e173cc52e6feca6b27c0da24 to your computer and use it in GitHub Desktop.
pre-push with success callback script to trigger webhook for local coolify deployment
#!/bin/bash
# Store the original command
original_command="$@"
# Let the push happen first
eval "$original_command"
push_status=$?
# Only proceed if push was successful
if [ $push_status -eq 0 ]; then
# Check if environment variables are set
if [ -z "$COOLIFY_WEBHOOK" ]; then
echo "Error: COOLIFY_WEBHOOK environment variable is not set"
exit 1
fi
if [ -z "$COOLIFY_TOKEN" ]; then
echo "Error: COOLIFY_TOKEN environment variable is not set"
exit 1
fi
# Get the current branch name
current_branch=$(git symbolic-ref --short HEAD)
# Only trigger deployment on main branch
if [ "$current_branch" != "main" ]; then
echo "Skipping deployment: Not on main branch"
exit 0
fi
echo "Triggering Coolify deployment..."
# Execute curl command with error handling
response=$(curl -s -w "\n%{http_code}" --request GET "$COOLIFY_WEBHOOK" \
--header "Authorization: Bearer $COOLIFY_TOKEN")
# Extract status code and body
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed \$d)
if [ "$http_code" -eq 200 ]; then
echo "Deployment triggered successfully!"
echo "Response: $body"
else
echo "Error: Deployment failed with status code $http_code"
echo "Response: $body"
fi
fi
exit $push_status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment