2019-05-11 16:48:31 +03:00
|
|
|
.PHONY: all gh-pages
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
# Build KaTeX.
|
2019-05-11 16:18:07 +03:00
|
|
|
all:
|
2021-01-01 21:15:12 +03:00
|
|
|
set -e
|
2019-05-11 16:18:07 +03:00
|
|
|
git submodule update --init --recursive
|
|
|
|
cd src/KaTeX
|
|
|
|
yarn
|
|
|
|
yarn build
|
2019-05-11 16:48:31 +03:00
|
|
|
|
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
|
|
|
|
exit "KATEX must be set to a directory."
|
|
|
|
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
|
|
|
|
git rm -r --cached src/KaTeX
|
|
|
|
git commit -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
|
|
|
|
git rm -r --cached src/KaTeX
|
|
|
|
git commit -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-01 21:15:12 +03:00
|
|
|
# Clone the existing version of KaTeX into the worktree.
|
|
|
|
git clone $$KATEX KaTeX
|
|
|
|
# We are assuming KaTeX has already been built.
|
|
|
|
# Remove `.git` and associated files, so KaTeX is no longer recognised as a git repository.
|
2020-03-04 21:03:29 +03:00
|
|
|
cd KaTeX
|
2021-01-01 21:15:12 +03:00
|
|
|
rm -rf .git
|
|
|
|
rm .gitignore
|
|
|
|
rm .gitmodules
|
|
|
|
# We need to be able to commit KaTeX as a plain directory, so we have to unregister it as a
|
|
|
|
# submodule. The cloned repository by default won't contain any `.gitignore`d files, but we
|
|
|
|
# actually want the `dist/`, directory, which contains various resources, e.g. fonts, so we copy
|
|
|
|
# it across ourselves.
|
|
|
|
cp -r $$KATEX/dist .
|
2020-03-04 21:03:29 +03:00
|
|
|
cd ../
|
2021-01-01 21:15:12 +03:00
|
|
|
git add -A
|
|
|
|
git commit -m "Add 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
|
|
|
|
2021-01-01 21:15:12 +03:00
|
|
|
# Push to the remote `gh-pages` branch. We do need to force push at some point, to overwrite the
|
|
|
|
# existing branch content. However, this will not suffice to rebuild on GitHub Pages, so we then
|
|
|
|
# perform another (non-`--force`) push immediately afterwards.
|
2019-05-11 16:48:31 +03:00
|
|
|
git push --force
|
2021-01-01 21:15:12 +03:00
|
|
|
# Set the `CNAME`. It is convenient to do so now, because we have to push a commit anyway to
|
|
|
|
# force a rebuild, and we need to set the `CNAME` eventually.
|
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"
|
2020-03-04 21:03:29 +03:00
|
|
|
git push
|
|
|
|
|
|
|
|
# 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
|