Update commit status on successful / failed deployment #1671
Replies: 4 comments
-
Would love to see this in a future |
Beta Was this translation helpful? Give feedback.
-
This would be really nice to have. I'm not sure if this is exactly what I was thinking, but I will attach a image of what CloudFlare Pages does. |
Beta Was this translation helpful? Give feedback.
-
Any update on this? |
Beta Was this translation helpful? Give feedback.
-
I managed to do it with a post deployment command (partially, it only calls the deployment api with success) Human readable version: # Update the package list and install jq
apt update && apt install -y jq
# Create a deployment on GitHub and capture the deployment ID
DEPLOYMENT_ID=$(curl -s \
-X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/<REPO_OWNER>/<REPO>/deployments \
-d '{
"ref": "main",
"environment": "production",
"description": "Finalizing deployment",
"auto_merge": false,
"required_contexts": []
}' | jq -r ".id")
# Check if the deployment creation failed
if [ -z "$DEPLOYMENT_ID" ] || [ "$DEPLOYMENT_ID" = "null" ]; then
echo "Failed to create deployment on GitHub"
exit 1
fi
# Post a successful deployment status to GitHub
curl -s \
-X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/<REPO_OWNER>/<REPO>/deployments/$DEPLOYMENT_ID/statuses \
-d '{
"state": "success",
"description": "Deployment completed successfully",
"environment_url": "<YOUR_ENDPOINT_URL>",
}' one-liner version to paste directly into the Post-deployment input area inside your Project->Configuration apt update && apt install -y jq && DEPLOYMENT_ID=$(curl -s -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" https://api.github.com/repos/<REPO_OWNER>/<REPO>/deployments -d "{\"ref\": \"main\", \"environment\": \"production\", \"description\": \"Finalizing deployment\", \"auto_merge\": false, \"required_contexts\": []}" | jq -r ".id") && [ -z "$DEPLOYMENT_ID" ] || [ "$DEPLOYMENT_ID" = "null" ] && echo "Failed to create deployment on GitHub" && exit 1 || curl -s -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" https://api.github.com/repos/<REPO_OWNER>/<REPO>/deployments/$DEPLOYMENT_ID/statuses -d "{\"state\": \"success\", \"description\": \"Deployment completed successfully\", \"environment_url\": \"<YOUR_ENDPOINT_URL>"}" Change:
Get an access token from Github settings -> developer settings ... and add it to your environment variables as $GITHUB_TOKEN. I couldn't find a way to get if the deployment was success or not so I only call the api with success. |
Beta Was this translation helpful? Give feedback.
-
I was thinking it could be very helpful if Coolify updated the commit status shown in GitHub. This is something that many CI playforms do (like GitHub Actions and Jenkins) as well as CD platforms (such as Vercel).
Basically what it does is add a check or cross icon to the commit if the deployment was successful or failed respectively. Something Vercel does is also comment on the commit, I don't think this is needed as it introduces email spam (so if it can be turned off it's fine). But something like those notifications can be discussed in this other discussion: #503
Why is this helpful?
Well you do not want your entire team to have access to your Coolify instance, but it is important for them to know if their latest commit was deployed to production for example.
I think it can be updated using a GitHub App. Here is some information about how to implement this using the REST API: https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28
Beta Was this translation helpful? Give feedback.
All reactions