|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +echo "[--Build: Started--]" |
| 6 | + |
| 7 | +# Clean up the dist directory |
| 8 | +echo "Cleaning up the dist directory..." |
| 9 | +rm -rf dist |
| 10 | + |
| 11 | +# Build the frontend |
| 12 | +echo "Compiling frontend..." |
| 13 | +npm install -f # force because there is a known mismatch of shadcn and react 19 - https://ui.shadcn.com/docs/react-19 |
| 14 | +npm run build |
| 15 | + |
| 16 | +# Build the backend |
| 17 | +echo "Compiling backend..." |
| 18 | +npm --prefix server install |
| 19 | +npm --prefix server run build |
| 20 | + |
| 21 | +echo "Copying extra files..." |
| 22 | +cp ./server/package.json ./dist/package.json |
| 23 | + |
| 24 | +echo "[--Build: Complete--]" |
| 25 | +echo "Executing the deployment upload script" |
| 26 | +echo "[--Deployment: Started--]" |
| 27 | + |
| 28 | +# Check if GITHUB_RUNTIME_PERMANENT_NAME is empty. |
| 29 | +# This will be set when you run with the `copilot_workbench_kv_aca` flag. |
| 30 | +if [ -z "$GITHUB_RUNTIME_PERMANENT_NAME" ]; then |
| 31 | + echo "GITHUB_RUNTIME_PERMANENT_NAME is empty. Falling back to CODESPACE_NAME." |
| 32 | + |
| 33 | + GITHUB_RUNTIME_PERMANENT_NAME=${CODESPACE_NAME} |
| 34 | + size=${#GITHUB_RUNTIME_PERMANENT_NAME} |
| 35 | + # if size is > 20, then truncate the name. |
| 36 | + # this is a limitation that's also enforced by the dotcom API |
| 37 | + # but I'd rather ensure that the command succeeds. |
| 38 | + if [ $size -gt 20 ]; then |
| 39 | + GITHUB_RUNTIME_PERMANENT_NAME=${GITHUB_RUNTIME_PERMANENT_NAME:0:20} |
| 40 | + fi |
| 41 | +fi |
| 42 | + |
| 43 | +echo "Deploying as ${GITHUB_USER} to ${GITHUB_RUNTIME_PERMANENT_NAME}" |
| 44 | + |
| 45 | +gh runtime create \ |
| 46 | + --app ${GITHUB_RUNTIME_PERMANENT_NAME} \ |
| 47 | + --env "GITHUB_RUNTIME_PERMANENT_NAME=${GITHUB_RUNTIME_PERMANENT_NAME}" \ |
| 48 | + --secret "GITHUB_TOKEN=${GITHUB_TOKEN}" \ |
| 49 | + |
| 50 | +gh runtime deploy \ |
| 51 | + --app ${GITHUB_RUNTIME_PERMANENT_NAME} \ |
| 52 | + --dir dist |
| 53 | + |
| 54 | +DEPLOYED_URL="$(gh runtime get --app ${GITHUB_RUNTIME_PERMANENT_NAME})" |
| 55 | + |
| 56 | +echo "[--URL-App=[https://${DEPLOYED_URL}]--]" |
| 57 | +echo "[--Deployment: Complete--]" |
0 commit comments