|
1 | 1 | #!/usr/bin/env bash |
2 | | -# Deploy Jekyll site to gh-pages branch using git worktree |
| 2 | +# Lightweight Jekyll deploy script |
3 | 3 | set -euo pipefail |
4 | 4 |
|
5 | | -BRANCH="gh-pages" |
6 | | -DEPLOY_DIR=".deploy" |
| 5 | +# Config |
| 6 | +REMOTE=origin |
| 7 | +BRANCH=gh-pages |
| 8 | +BUILD_DIR=_site |
7 | 9 |
|
8 | | -echo "==> Cleaning up any stale worktrees..." |
9 | | -git worktree prune |
10 | | -rm -rf "$DEPLOY_DIR" |
11 | | - |
12 | | -# Ensure gh-pages branch exists |
13 | | -if ! git show-ref --quiet refs/heads/$BRANCH; then |
14 | | - echo "==> Creating $BRANCH branch..." |
15 | | - git branch $BRANCH |
16 | | -fi |
| 10 | +echo "Building Jekyll site..." |
| 11 | +bundle exec jekyll build |
17 | 12 |
|
18 | | -echo "==> Adding worktree for $BRANCH..." |
19 | | -git worktree add -B $BRANCH "$DEPLOY_DIR" origin/$BRANCH || git worktree add -B $BRANCH "$DEPLOY_DIR" |
| 13 | +echo "Preparing temporary git repo in $BUILD_DIR..." |
| 14 | +cd "$BUILD_DIR" |
20 | 15 |
|
21 | | -echo "==> Building Jekyll site..." |
22 | | -bundle exec jekyll build |
| 16 | +# Init repo if needed |
| 17 | +if [ ! -d ".git" ]; then |
| 18 | + git init |
| 19 | + git remote add $REMOTE "$(git -C .. config --get remote.$REMOTE.url)" |
| 20 | +fi |
23 | 21 |
|
24 | | -echo "==> Syncing built site into $DEPLOY_DIR..." |
25 | | -rsync -av --delete _site/ "$DEPLOY_DIR/" |
| 22 | +# Reset state each deploy |
| 23 | +git checkout -B $BRANCH |
26 | 24 |
|
27 | | -echo "==> Committing and pushing..." |
28 | | -cd "$DEPLOY_DIR" |
29 | | -git add --all |
30 | | -git commit -m "Deploy site $(date)" || echo "Nothing to commit" |
31 | | -git push origin $BRANCH |
32 | | -cd - |
| 25 | +echo "Committing build..." |
| 26 | +git add -A |
| 27 | +git commit -m "Deploy site $(date)" || echo "No changes to commit." |
33 | 28 |
|
34 | | -echo "==> Cleaning up temporary worktree..." |
35 | | -git worktree remove "$DEPLOY_DIR" --force |
36 | | -rm -rf "$DEPLOY_DIR" |
| 29 | +echo "Pushing to $REMOTE/$BRANCH..." |
| 30 | +git push -f $REMOTE HEAD:$BRANCH |
37 | 31 |
|
38 | | -echo "==> Deployment complete!" |
| 32 | +echo "Deployment complete!" |
0 commit comments