]> git.wincent.com - hextrapolate.git/blob - publish.sh
chore: add target browser configuration
[hextrapolate.git] / publish.sh
1 #!/bin/sh
2
3 # Get a temporary index file to work with.
4 INDEX="$(mktemp -d)/index"
5
6 for FILE in $(find build -type f -and -not -name '.*'); do
7   # Add file contents to object database.
8   BLOB_ID=$(git hash-object -w -- "$FILE")
9
10   # Add file to index.
11   MODE=100644
12   NAME=${FILE#build/}
13   env GIT_INDEX_FILE="$INDEX" git update-index \
14     --add \
15     --cacheinfo "${MODE},${BLOB_ID},${NAME}"
16 done
17
18 # Special file: "CNAME" for GitHub pages custom domain.
19 # See: https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site#configuring-a-subdomain
20 BLOB_ID=$(/bin/echo -n hex.wincent.com | git hash-object -w --stdin)
21 MODE=100644
22 NAME=CNAME
23 env GIT_INDEX_FILE="$INDEX" git update-index \
24   --add \
25   --cacheinfo "${MODE},${BLOB_ID},${NAME}"
26
27 # Create tree object from index.
28 TREE_ID=$(env GIT_INDEX_FILE="$INDEX" git write-tree)
29
30 # Make the commit.
31 DATE=$(date)
32 PARENT=$(git rev-parse refs/heads/gh-pages)
33 SOURCE=$(git describe --always --dirty)
34 COMMIT=$(builtin echo "Build $DATE\n\nFrom $SOURCE." | git commit-tree "$TREE_ID" -p "$PARENT" -F -)
35
36 git update-ref refs/heads/gh-pages "$COMMIT"
37
38 echo "Created commit: $(git rev-parse --short "$COMMIT")\n"
39
40 git log --raw -1 refs/heads/gh-pages
41
42 if $(git diff --quiet "$COMMIT" "$PARENT"); then
43   BOLD=$(tput bold)
44   RED=$(tput setaf 1)
45   RESET=$(tput sgr0)
46   echo "\n${BOLD}${RED}WARNING: CREATED EMPTY COMMIT${RESET}\n"
47   echo "If this was in error, reset using:"
48   echo "  git update-ref refs/heads/gh-pages $(git rev-parse --short "$PARENT")"
49 fi