Created
January 13, 2025 17:28
-
-
Save lazuee/fb053ffd8729a52ad42d45c20f145aef to your computer and use it in GitHub Desktop.
Remove deployment for non-existent commits
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
#!/bin/bash | |
OWNER="lazuee" | |
REPO="react-router" | |
BRANCH="main" | |
deployment_shas=$(gh api repos/$OWNER/$REPO/deployments --jq '.[].sha') | |
existing_shas=$(gh api repos/$OWNER/$REPO/commits?sha=$BRANCH --jq '.[].sha') | |
for deployment_sha in $deployment_shas; do | |
if ! echo "$existing_shas" | grep -q "$deployment_sha"; then | |
echo "Deactivating and deleting deployment for non-existent commit SHA: $deployment_sha" | |
deployment_id=$(gh api repos/$OWNER/$REPO/deployments --jq ".[] | select(.sha == \"$deployment_sha\") | .id") | |
gh api --method POST /repos/$OWNER/$REPO/deployments/$deployment_id/statuses -f "state=inactive" | |
gh api --method DELETE /repos/$OWNER/$REPO/deployments/$deployment_id | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment