Last active
December 8, 2022 03:19
-
-
Save andrewloux/ef5eae7f0784a687d19591ef45627128 to your computer and use it in GitHub Desktop.
Hasura wrapper that pins a specific version
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 | |
set -e | |
set -o pipefail | |
# This is a simple wrapper script for the "hasura" command that enforces the version | |
# and bails out if the hasura version is incorrect. | |
# Replace "hasura" with the actual path to the hasura binary, if necessary. | |
HASURA_BINARY="hasura" | |
# Set the required version of the hasura binary. | |
HASURA_REQUIRED_VERSION="v2.7.0" | |
RED='\033[1;91m' | |
GREEN='\033[4;32m' | |
NC='\033[0m' # No Color | |
# Check if jq is installed. If not, install it. | |
if ! type "jq" > /dev/null; then | |
echo "jq is not installed. Installing..." | |
brew install jq | |
fi | |
# Check if hasura is installed. If not, install it. | |
if ! type "$HASURA_BINARY" > /dev/null; then | |
echo "Hasura is not installed. Installing..." | |
curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh --output get-hasura.sh | |
chmod +x get-hasura.sh | |
VERSION=$HASURA_REQUIRED_VERSION ./get-hasura.sh | |
rm get-hasura.sh | |
chmod u+w $(which hasura) | |
else | |
# If hasura is already installed, check if it's the required version. | |
# If not, print a warning message and exit with an error code. | |
if ! $HASURA_BINARY version 2> /dev/null | jq -e ".version == \"$HASURA_REQUIRED_VERSION\"" > /dev/null; then | |
printf "${RED}Uninstall your current version of the Hasura CLI${NC} and run again.\n\n" | |
printf "This wrapper will install & configure the required version ${GREEN}$HASURA_REQUIRED_VERSION${NC}\n" | |
exit 1 | |
fi | |
fi | |
# Run the hasura command with the "version --skip-update-check" arguments. | |
$HASURA_BINARY "$@" --skip-update-check |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment