Last active
August 2, 2021 19:12
-
-
Save pipex/e795d779a8823c7b65c6be36dc1c6adf to your computer and use it in GitHub Desktop.
Invalidate a release on balenaCloud
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 -e | |
if [[ $# -lt 1 ]]; then | |
echo "USAGE:" | |
echo " $0 COMMIT [INVALIDATE default true]" | |
exit 1; | |
fi | |
COMMIT=$1 | |
BALENARC_BALENA_URL=${BALENARC_BALENA_URL:-"balena-cloud.com"} | |
API_TOKEN=${API_TOKEN:-`cat $HOME/.balena/token`} | |
INVALIDATE=${2:-"true"} | |
if [ "$INVALIDATE" != "true" ]; then | |
INVALIDATE="false" | |
fi | |
RES=$(curl -q -X PATCH -H "Content-type: application/json" -H "Authorization: Bearer ${API_TOKEN}" "https://api.${BALENARC_BALENA_URL}/v6/release?\$filter=commit%20eq%20'${COMMIT}'" -d "{\"is_invalidated\": $INVALIDATE}" 2>/dev/null) | |
SUCCESS=$? | |
IS_INVALIDATED=$(curl -q -H "Authorization: Bearer ${API_TOKEN}" "https://api.${BALENARC_BALENA_URL}/v6/release?\$filter=commit%20eq%20'${COMMIT}'" 2>/dev/null | jq ".d[].is_invalidated") | |
if [ $? -eq 0 ] && [ "$RES" == "OK" ] && [ "$IS_INVALIDATED" == "$INVALIDATE" ]; then | |
echo "Successfully change validation status of release $COMMIT to $INVALIDATE in $BALENARC_BALENA_URL" | |
else | |
echo "Failed to change validation status release $COMMIT: server responded $RES" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment