Skip to content

Instantly share code, notes, and snippets.

@mdzhang
Created August 7, 2023 18:25
Show Gist options
  • Save mdzhang/d60803148b06b53e3b335eb90576539b to your computer and use it in GitHub Desktop.
Save mdzhang/d60803148b06b53e3b335eb90576539b to your computer and use it in GitHub Desktop.
Deploy a ZAF app in CI
#!/bin/bash
set -o errexit
set -e
COLOR='\033[1;36m'
RED='\033[0;31m'
NC='\033[0m' # No Color
die()
{
BASE=$(basename -- "$0")
echo -e "${RED} $BASE: error: $@ ${NC}" >&2
exit 1
}
# Checking dependencies
command -v curl >/dev/null 2>&1 || die "curl is required but not installed. Aborting."
command -v jq >/dev/null 2>&1 || die "jq is required but not installed. Aborting."
command -v npx >/dev/null 2>&1 || die "node is required but not installed. Aborting."
command -v npx zcli >/dev/null 2>&1 || die "zcli is required but not installed. Aborting."
if ! [ -d "./dist" ]; then
die "No build target. Run 'yarn build && zcli apps:validate dist' first."
fi
echo -e "${COLOR}Manifest is:${NC}"
< dist/manifest.json jq
echo -e "${COLOR}Packaging app...${NC}"
npx zcli apps:package dist
pkg=$(ls -tp dist/tmp | grep -v /$ | head -1)
echo -e "${COLOR}Uploading app...${NC}"
res=$(curl -X POST "https://$ZENDESK_SUBDOMAIN.zendesk.com/api/v2/apps/uploads.json" \
-F "uploaded_data=@dist/tmp/$pkg" \
-u "$ZENDESK_EMAIL/token:$ZENDESK_API_TOKEN")
upload_id=$(echo "$res" | jq '.id')
echo ""
echo "$res" | jq
if [ "$upload_id" == "null" ]; then
die "Upload failed."
fi
echo -e "${COLOR}Created upload $upload_id.${NC}"
app_id=$(< zcli.apps.config.json jq '.app_id')
curl -X PUT "https://$ZENDESK_SUBDOMAIN.zendesk.com/api/v2/apps/$app_id" \
-u "$ZENDESK_EMAIL/token:$ZENDESK_API_TOKEN" -d '{"upload_id":'"$upload_id"'}' | jq
echo -e "${COLOR}Installed app.${NC}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment