Skip to content

Instantly share code, notes, and snippets.

@vegaasen
Created June 29, 2022 05:39
Show Gist options
  • Save vegaasen/d0e77cbbaf9e8a3711b84847d7cbb841 to your computer and use it in GitHub Desktop.
Save vegaasen/d0e77cbbaf9e8a3711b84847d7cbb841 to your computer and use it in GitHub Desktop.
Azure Static Web App (SWA) Deployer πŸŽ‰
#!/bin/bash
# In the future, when Azure fixes its `swa deploy build` command, we have to rely on this style (unfortunately)
# Whilst we're waiting for this to be fixed, lets rely on this script instead
apiTokenFile=.api-token
you=$(git config --get user.name)
theGitBranch=$(git branch --show-current)
theGitCommit=$(git rev-parse --short HEAD)
applicationName=$(pwd | awk -F/ '{print $NF}')
if [ ! "$(command -v swa)" ]; then
echo "πŸ’©β›”οΈ Oh no! No swa <command> found! Install this tool first using e.g npm i -g @azure/static-web-apps-cli"
exit 1
fi
echo "⏳ Building application"
npm run build
echo "⏳ Choose environment"
swa deploy --print-token | tee ${apiTokenFile}
if [ ! -f ${apiTokenFile} ]; then
echo "😒 No token-file on ${apiTokenFile}"
exit 1
fi
apiToken=$(tail -n 1 ${apiTokenFile})
rm ${apiTokenFile}
if [ -z "${apiToken}" ]; then
echo "😒 No token"
exit 1
fi
echo "⏳ Deploying using token ${apiToken}"
docker run -it --rm -e APP_LOCATION="/frontend" -e SKIP_APP_BUILD=true -e DEPLOYMENT_TOKEN="${apiToken}" -v "${PWD}/build:/frontend" mcr.microsoft.com/appsvc/staticappsclient:latest ./bin/staticsites/StaticSitesClient upload
echo "πŸŽ‰ Application deployed on $(date)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment