-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·65 lines (52 loc) · 1.63 KB
/
deploy.sh
File metadata and controls
executable file
·65 lines (52 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
set -euo pipefail
#
# --- Parse arguments ---
VERBOSE=0
for arg in "$@"; do
if [[ "$arg" == "-v" || "$arg" == "--verbose" ]]; then
VERBOSE=1
fi
done
# --- Utility function to indent subcommand output (only if verbose) ---
run() {
if [[ "$VERBOSE" == "1" ]]; then
echo "▶ $*"
"$@" 2>&1 | sed 's/^/ /'
else
"$@" > /dev/null 2>&1
fi
}
SCRIPT_PATH="$(readlink -f "$0")"
REPO_DIR="$(dirname "$SCRIPT_PATH")"
WORKTREE_DIR="$REPO_DIR/../deploy-flipper-temp"
DEPLOY_BRANCH="deploy_flipper"
DIST_DIR="$REPO_DIR/dist"
cd "$REPO_DIR"
echo "🔧 Building project with Vite..."
run rm -rf dist
run npx vite build
# If the worktree directory already exists, remove it first
if [ -d "${WORKTREE_DIR}" ]; then
echo "⚠️ Worktree directory already exists at ${WORKTREE_DIR} - removing..."
run git worktree remove --force "${WORKTREE_DIR}"
fi
echo "🌿 Adding worktree for ${DEPLOY_BRANCH}..."
run git worktree add "${WORKTREE_DIR}" "${DEPLOY_BRANCH}"
echo "🧹 Cleaning old files in ${DEPLOY_BRANCH}..."
cd "${WORKTREE_DIR}"
run rm -rf *
echo "📦 Copying build output from dist/..."
run cp -r "${DIST_DIR}"/* .
echo "📄 Adding .nojekyll to disable GitHub Jekyll processing..."
run touch .nojekyll
echo "✅ Committing and pushing changes..."
run git add .
GIT_HASH=$(git rev-parse --short HEAD)
COMMIT_MSG="Deploy Vite build from ${GIT_HASH} on $(date +'%Y-%m-%d %H:%M:%S')"
run git commit -m "${COMMIT_MSG}" || run echo "No changes to commit"
run git push
echo "🧼 Cleaning up worktree..."
cd "${REPO_DIR}"
run git worktree remove "${WORKTREE_DIR}"
echo "🚀 Deployment to branch '${DEPLOY_BRANCH}' complete!"