Skip to content

Commit 816e2f1

Browse files
author
River@devbox
committed
Add deploy script for gh-pages
- Add deploy.sh to automate deployment to gh-pages branch - Script builds site and pushes to origin/gh-pages
1 parent 21527e6 commit 816e2f1

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

deploy.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
3+
# Deploy script for QPython documentation
4+
# Builds the site and deploys to gh-pages branch
5+
6+
set -e
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
cd "$SCRIPT_DIR"
10+
11+
# Run build first
12+
echo "Building site..."
13+
./build.sh
14+
15+
# Check if git repository
16+
if [ ! -d .git ]; then
17+
echo "Error: Not a git repository"
18+
exit 1
19+
fi
20+
21+
# Get current branch
22+
CURRENT_BRANCH=$(git branch --show-current)
23+
echo "Current branch: $CURRENT_BRANCH"
24+
25+
# Check if there are uncommitted changes
26+
if ! git diff-index --quiet HEAD --; then
27+
echo "Warning: You have uncommitted changes. Please commit them first."
28+
echo "Uncommitted files:"
29+
git status --short
30+
read -p "Do you want to continue anyway? (y/N) " -n 1 -r
31+
echo
32+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
33+
echo "Aborted."
34+
exit 1
35+
fi
36+
fi
37+
38+
# Deploy to gh-pages
39+
echo ""
40+
echo "Deploying to gh-pages branch..."
41+
42+
# Create a temporary directory for the site
43+
TEMP_DIR=$(mktemp -d)
44+
cp -r site/* "$TEMP_DIR/"
45+
46+
# Switch to gh-pages branch (create if doesn't exist)
47+
if git show-ref --verify --quiet refs/heads/gh-pages; then
48+
git checkout gh-pages
49+
else
50+
git checkout --orphan gh-pages
51+
git rm -rf .
52+
fi
53+
54+
# Remove old files (except .git)
55+
find . -maxdepth 1 ! -name '.git' ! -name '.' ! -name '..' -exec rm -rf {} \;
56+
57+
# Copy new site content
58+
cp -r "$TEMP_DIR"/* .
59+
60+
# Add all files
61+
git add -A
62+
63+
# Commit
64+
COMMIT_MSG="Deploy site - $(date '+%Y-%m-%d %H:%M:%S')"
65+
if git diff --cached --quiet; then
66+
echo "No changes to commit"
67+
else
68+
git commit -m "$COMMIT_MSG"
69+
echo "Committed: $COMMIT_MSG"
70+
fi
71+
72+
# Push to remote
73+
read -p "Push to origin/gh-pages? (y/N) " -n 1 -r
74+
echo
75+
if [[ $REPLY =~ ^[Yy]$ ]]; then
76+
git push origin gh-pages
77+
echo ""
78+
echo "Deployed successfully!"
79+
echo "Site will be available at: https://qpython-android.github.io/qpython.org/"
80+
else
81+
echo "Push aborted. You can push manually with: git push origin gh-pages"
82+
fi
83+
84+
# Cleanup
85+
rm -rf "$TEMP_DIR"
86+
87+
# Switch back to original branch
88+
git checkout "$CURRENT_BRANCH"
89+
90+
echo ""
91+
echo "Done!"

0 commit comments

Comments
 (0)