2023-08-17 13:55:59 +03:00
|
|
|
.PHONY: all gh-pages cleanup
|
2019-05-11 16:48:31 +03:00
|
|
|
|
|
|
|
# Ensure `cd` works properly by forcing everything to be executed in a single shell.
|
2019-05-11 16:18:07 +03:00
|
|
|
.ONESHELL:
|
2019-05-11 16:48:31 +03:00
|
|
|
|
2023-12-15 18:09:18 +03:00
|
|
|
# Note: the order matters; the service worker must be built last to have a complete assets
|
|
|
|
# precaching manifest.
|
2023-12-20 00:07:36 +03:00
|
|
|
all: src/KaTeX src/icon-192.png src/icon-512.png src/Workbox/workbox-window.prod.mjs src/service-worker.js
|
2023-12-15 18:09:18 +03:00
|
|
|
|
|
|
|
# Vendor KaTeX dependencies.
|
|
|
|
src/KaTeX:
|
2021-01-01 21:15:12 +03:00
|
|
|
set -e
|
2023-12-15 18:18:43 +03:00
|
|
|
curl -L -O "https://github.com/KaTeX/KaTeX/releases/download/v0.16.9/katex.zip"
|
2021-01-02 16:32:58 +03:00
|
|
|
unzip katex.zip
|
|
|
|
rm katex.zip
|
|
|
|
mv katex src/KaTeX
|
2019-05-11 16:48:31 +03:00
|
|
|
|
2023-12-15 18:09:18 +03:00
|
|
|
# Vendor any workbox dependency.
|
2023-12-20 00:07:36 +03:00
|
|
|
src/Workbox/workbox-%:
|
2023-12-15 18:09:18 +03:00
|
|
|
mkdir -p $(@D)
|
|
|
|
curl -L -o $@ https://storage.googleapis.com/workbox-cdn/releases/7.0.0/workbox-$*
|
|
|
|
curl -L -o $@.map https://storage.googleapis.com/workbox-cdn/releases/7.0.0/workbox-$*.map
|
|
|
|
|
|
|
|
# Build service worker.
|
|
|
|
src/service-worker.js: service-worker/build.js
|
|
|
|
cd $(dir $<)
|
|
|
|
. $$NVM_DIR/nvm.sh
|
|
|
|
nvm use 20 && npm install && node build.js
|
|
|
|
|
|
|
|
# Generate icons required by the webapp manifest. Requires ImageMagick.
|
|
|
|
src/icon-512.png: src/icon.png
|
|
|
|
convert $< -background none -resize 512x512 $@
|
|
|
|
src/icon-192.png: src/icon.png
|
|
|
|
convert $< -background none -resize 192x192 $@
|
|
|
|
|
2020-03-04 21:03:29 +03:00
|
|
|
# Update the `dev` branch from `master`.
|
|
|
|
dev:
|
2021-01-01 21:15:12 +03:00
|
|
|
set -e
|
2020-03-04 21:03:29 +03:00
|
|
|
git checkout dev
|
|
|
|
git rebase master
|
|
|
|
git checkout @{-1}
|
|
|
|
|
|
|
|
# Update the `release` branch from `dev`.
|
|
|
|
release:
|
2021-01-01 21:15:12 +03:00
|
|
|
set -e
|
2020-03-04 21:03:29 +03:00
|
|
|
git checkout release
|
|
|
|
git rebase dev
|
|
|
|
git checkout @{-1}
|
|
|
|
|
2019-05-11 16:48:31 +03:00
|
|
|
# Update the quiver GitHub Pages application.
|
|
|
|
gh-pages:
|
2020-03-04 21:03:29 +03:00
|
|
|
# We use several branches for the deployment workflow.
|
|
|
|
# - `master`: Main development branch.
|
|
|
|
# - `release`: The branch that is used for hosting on GitHub Pages.
|
|
|
|
# - `dev`: The branch that is hosted under /dev on GitHub Pages.
|
2021-01-01 21:15:12 +03:00
|
|
|
# - `squash`: A temporary branch containing squashed versions of `release` and `dev`.
|
2020-03-04 21:03:29 +03:00
|
|
|
# - `gh-pages`: The branch that is actually hosted directly. This includes `release` and `dev`.
|
|
|
|
|
2021-01-01 21:15:12 +03:00
|
|
|
# Terminate if there are any errors. We may have to do some manual cleanup in this case, but
|
|
|
|
# it's better than trying to push a broken version of quiver.
|
|
|
|
set -e
|
|
|
|
# It's too error-prone to clone KaTeX from the origin each time we want to push quiver, so we
|
|
|
|
# instead copy it from an existing directory, typically the one in `src/KaTeX`, which must be
|
|
|
|
# stored in the `$KATEX` environment variable.
|
|
|
|
if [ ! -d "$$KATEX" ]; then
|
2021-11-21 00:26:13 +03:00
|
|
|
echo "KATEX must be set to a directory."
|
|
|
|
exit 1
|
2021-01-01 21:15:12 +03:00
|
|
|
fi
|
|
|
|
# Store the name of the current branch, to return to it after completing this process.
|
|
|
|
CURRENT=$$(git rev-parse --abbrev-ref HEAD)
|
2020-03-04 21:03:29 +03:00
|
|
|
# Checkout the release branch.
|
|
|
|
git checkout release
|
2021-01-01 21:15:12 +03:00
|
|
|
# Get the initial commit ID, which will be used for squashing history.
|
|
|
|
TAIL=$$(git rev-list --max-parents=0 HEAD)
|
|
|
|
# Copy the release branch on to a new branch, for squashing purposes.
|
|
|
|
git checkout -b squashed
|
|
|
|
# Squash all the history (excluding the fixed, initial commit). This will improve performance
|
|
|
|
# for `subtree split` later, which has to iterate through the entire history of the branch.
|
|
|
|
git reset $$TAIL
|
|
|
|
git add -A
|
2023-01-10 17:46:48 +03:00
|
|
|
git commit --allow-empty -m "Add release branch"
|
2020-03-04 21:03:29 +03:00
|
|
|
# Split off the `src/` directory into its own branch.
|
|
|
|
RELEASE=$$(git subtree split --prefix=src)
|
2021-01-01 21:15:12 +03:00
|
|
|
# Checkout the development branch, squash it, and split it off, just like `release`.
|
2020-03-04 21:03:29 +03:00
|
|
|
git checkout dev
|
2021-01-01 21:15:12 +03:00
|
|
|
git branch -D squashed
|
|
|
|
git checkout -b squashed
|
|
|
|
git reset $$TAIL
|
|
|
|
git add -A
|
2023-01-10 17:46:48 +03:00
|
|
|
git commit --allow-empty -m "Add dev branch"
|
2020-03-04 21:03:29 +03:00
|
|
|
DEV=$$(git subtree split --prefix=src)
|
|
|
|
|
2021-01-01 21:15:12 +03:00
|
|
|
# Checkout the GitHub Pages branch in a new worktree. We use a new worktree because the branch
|
2020-03-04 21:03:29 +03:00
|
|
|
# is essentially incomparable with the other branches and we don't want to get any git conflicts
|
|
|
|
# from switching incompatible branches.
|
|
|
|
git worktree add ../quiver-worktree gh-pages
|
2019-05-11 16:48:31 +03:00
|
|
|
cd ../quiver-worktree
|
2021-01-01 21:15:12 +03:00
|
|
|
# Reset the GitHub Pages branch so that it contains the release source code.
|
2020-03-04 21:03:29 +03:00
|
|
|
git reset --hard $$RELEASE
|
2021-01-14 20:13:19 +03:00
|
|
|
# Copy KaTeX into the main release directory.
|
|
|
|
cp -r $$KATEX .
|
2020-03-04 21:03:29 +03:00
|
|
|
|
2021-01-01 21:15:12 +03:00
|
|
|
# Merge the development branch into the `dev/` directory.
|
2020-03-04 21:03:29 +03:00
|
|
|
git merge -s ours --no-commit $$DEV
|
|
|
|
git read-tree --prefix=dev -u $$DEV
|
2021-01-01 21:15:12 +03:00
|
|
|
# We have already cloned KaTeX and stripped it of git repository information, so don't need to
|
|
|
|
# do so again: we can just copy it across.
|
2020-03-04 21:03:29 +03:00
|
|
|
cp -r KaTeX dev
|
2021-01-01 21:15:12 +03:00
|
|
|
git add -A
|
|
|
|
git commit -m "Merge dev as subdirectory of release"
|
2020-03-04 21:03:29 +03:00
|
|
|
|
2023-01-10 17:46:48 +03:00
|
|
|
# Set the `CNAME`.
|
2020-11-13 04:55:49 +03:00
|
|
|
printf "q.uiver.app" > CNAME
|
|
|
|
git add CNAME
|
2021-01-01 21:15:12 +03:00
|
|
|
git commit -m "Create CNAME"
|
2023-01-10 17:46:48 +03:00
|
|
|
# Push to the remote `gh-pages` branch, which will trigger a rebuild on GitHub Pages.
|
|
|
|
git push --force
|
2020-03-04 21:03:29 +03:00
|
|
|
|
|
|
|
# Navigate back to the main working tree.
|
2019-05-11 16:48:31 +03:00
|
|
|
cd ../quiver
|
2020-03-04 21:03:29 +03:00
|
|
|
# Remove the temporary worktree.
|
|
|
|
git worktree remove ../quiver-worktree -f
|
|
|
|
# Checkout the original branch.
|
2021-01-01 21:15:12 +03:00
|
|
|
git checkout $$CURRENT
|
|
|
|
# Delete the temporary `squashed` branch.
|
|
|
|
git branch -D squashed
|
2023-08-17 13:55:59 +03:00
|
|
|
|
|
|
|
# Clean up the effects of the gh-pages upload, if it did not successfully terminate.
|
|
|
|
cleanup:
|
|
|
|
git checkout master
|
|
|
|
git worktree remove ../quiver-worktree -f
|
|
|
|
git branch -D squashed
|