Last active
August 2, 2026 19:10
-
-
Save SamuelDavis/171fc3c1fd2ea000477f9ca0768d728c to your computer and use it in GitHub Desktop.
Deploy to gh-pages for projects with `npm run build` to `dist/` (e.g. Vite)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| REMOTE_ORIGIN=$(git config --get remote.origin.url) | |
| if [ $? -ne 0 ]; then | |
| echo "Git repository not found." >&2 | |
| exit 1 | |
| fi | |
| REPO_NAME=$(basename -s .git "$REMOTE_ORIGIN") | |
| DOMAIN=${1:-"$REPO_NAME.sdavis.online"} | |
| HOST=${2:-'git@github.com:SamuelDavis'} | |
| OUT_DIR='dist' | |
| if [ -f project.godot ]; then | |
| BUILD=(godot --headless --export-release 'Web' "$OUT_DIR/index.html") | |
| elif [ -f deno.lock ] || [ -f deno.json ] || [ -f deno.jsonc ]; then | |
| BUILD=(deno task build --outDir "$OUT_DIR") | |
| elif [ -f package.json ]; then | |
| BUILD=(npm run build -- --outDir "$OUT_DIR") | |
| else | |
| echo "No project.godot, deno.json, or package.json found." >&2 | |
| exit 1 | |
| fi | |
| SOURCE_COMMIT=$(git rev-parse HEAD 2>/dev/null) | |
| COMMIT_MESSAGE=${SOURCE_COMMIT:-'deploy'} | |
| rm -rf "$OUT_DIR" | |
| mkdir -p "$OUT_DIR" | |
| if ! "${BUILD[@]}"; then | |
| exit 1 | |
| fi | |
| cd "$OUT_DIR" | |
| git init | |
| echo "$DOMAIN" >CNAME | |
| git add --all | |
| if ! git commit --message "$COMMIT_MESSAGE"; then | |
| exit 1 | |
| fi | |
| BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
| echo "Push $BRANCH to gh-pages on $REMOTE_ORIGIN? (y/N) " | |
| read ANSWER | |
| if [[ "$ANSWER" == "y" || "$ANSWER" == "Y" ]]; then | |
| git push -f "$HOST/$REPO_NAME.git" "${BRANCH}:gh-pages" | |
| fi | |
| cd - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment