-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·130 lines (112 loc) · 3.39 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·130 lines (112 loc) · 3.39 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
# Deploy script for documentation
# This script follows the steps outlined in ./deploy.md
set -ea
source .env
source scripts/.helpers
# Validate required environment variables
if [ -z "$PROJECT_ROOT" ]; then
echo "Error: PROJECT_ROOT is not set in .env"
exit 1
fi
if [ -z "$BUILD_REPO" ]; then
echo "Error: BUILD_REPO is not set in .env"
exit 1
fi
if [ -z "$PRODUCT_VERSION" ]; then
echo "Error: PRODUCT_VERSION is not set in .env"
exit 1
fi
if [ -z "$PRODUCT_DISPLAY_NAME" ]; then
echo "Error: PRODUCT_DISPLAY_NAME is not set in .env"
exit 1
fi
if [ -z "$BUILD_LATEST" ]; then
echo "Error: BUILD_LATEST is not set in .env"
exit 1
fi
if [ -z "$BUILD_BRANCH" ]; then
echo "Error: BUILD_BRANCH is not set in .env"
exit 1
fi
echo "=== Step 1: Build documentation site ==="
if [ -d .build ]; then
use_existing=$(_read "⚠️ Do you want to use the existing build? (y/n): " "y")
if [ "$use_existing" != "y" ]; then
echo "💡 (Re)building documentation site..."
yarn run docs:build
echo "💡 Generating the PDF Manual"
yarn run docs:generate-manual
else
echo "💡 Using existing .build directory."
fi
else
echo "💡 Building documentation site..."
yarn run docs:build
echo "💡 Generating the PDF Manual"
yarn run docs:generate-manual
fi
echo ""
echo "=== Step 2: Clone documentation repository ==="
if [ "$(ls -A .repo)" ]; then
use_repo=$(_read "⚠️ .repo directory already exists and is not empty. Do you want to use it? (y/n): " "y")
if [ "$use_repo" != "y" ]; then
echo "💡 Removing existing .repo directory..."
rm -rf .repo
git clone $BUILD_REPO --branch $BUILD_BRANCH .repo
cd .repo
else
echo "💡 Using existing .repo directory."
cd .repo
git fetch origin $BUILD_BRANCH
git reset --hard origin/$BUILD_BRANCH
fi
else
echo "💡 Cloning documentation repository..."
rm -rf .repo || true
git clone $BUILD_REPO --branch $BUILD_BRANCH .repo
cd .repo
fi
echo ""
echo "=== Step 3: Update versions.json ==="
COMMIT_HASH=$(git rev-parse HEAD) BUILD_REPO_COMMIT_HASH=$(cd ..; git rev-parse HEAD) node ../scripts/update-versions.cjs
echo ""
echo "=== Step 4: Copy build files ==="
BUILD_DIR="../.build"
# Copy versioned directory
rm -rf $PRODUCT_VERSION/
cp -R $BUILD_DIR/$PRODUCT_VERSION/ $PRODUCT_VERSION/
echo "💡 Copied $PRODUCT_VERSION/ directory"
# Copy latest directory if BUILD_LATEST is true
if [ "$BUILD_LATEST" = "true" ]; then
rmDirOrLink ./latest
if git ls-files --error-unmatch latest >/dev/null 2>&1; then
git rm -rf latest
fi
if [ -d "$BUILD_DIR/latest" ]; then
cp -R "$BUILD_DIR/latest" latest/
echo "💡 Copied latest/ from $BUILD_DIR/latest"
else
echo "❌ Error: resolved latest target is not a directory"
exit 1
fi
fi
echo ""
echo "=== Step 5: Commit and push changes ==="
confirm_push=$(_read "⚠️ Are you sure you want to commit and push changes to the $BUILD_BRANCH branch? (y/n): " "y")
if [ "$confirm_push" != "y" ]; then
echo "💡 Deployment aborted by user."
exit 0
fi
git add .
if git diff --staged --quiet; then
echo "💡 No changes to commit"
else
git commit -m "[NETLOGO-BOT] Deploy documentation for version $PRODUCT_VERSION"
git push origin $BUILD_BRANCH
echo "🚀 Successfully pushed changes to $BUILD_BRANCH branch"
fi
echo ""
echo "=== Deployment complete ==="
echo "💬 Version: $PRODUCT_VERSION"
echo "💬 Built latest: $BUILD_LATEST"