Files
shields/Makefile
Paul Melnikow 94611fb0e4 Rewrite server deploy script (#1793)
To run this requires renaming `private/secret.json` to `private/secret-production.json` in the working tree used for deployment.

Goals:

- Ensure production secrets are not used in development
- Avoid modifying the current working tree
- Avoid branch switching: make sure the current ref gets deployed
    - If something other than `master` is deployed, leave `HEAD` alone; don't reset to `master`
- Ensure the build runs before server deploy (#1941)

This makes use of Git working trees, which is a relatively new but stable feature in Git. I was initially reluctant to use git worktree, mostly because I don't like adding new tooling that isn't necessary. The other alternative I experimented with was copying or re-cloning to an entirely separate working copy. This was messier and more brittle than using `git worktree`.
2018-10-30 17:08:52 -04:00

90 lines
2.8 KiB
Makefile

SHELL:=/bin/bash
SERVER_TMP=${TMPDIR}shields-server-deploy
FRONTEND_TMP=${TMPDIR}shields-frontend-deploy
# This branch is reserved for the deploy process and should not be used for
# development. The deploy script will clobber it. To avoid accidentally
# pushing secrets to GitHub, this branch is configured to reject pushes.
WORKING_BRANCH=server-deploy-working-branch
all: website favicon test
favicon:
# This isn't working right now. See https://github.com/badges/shields/issues/1788
node lib/badge-cli.js '' '' '#bada55' .png > favicon.png
website:
LONG_CACHE=false npm run build
deploy: deploy-s0 deploy-s1 deploy-s2 clean-server-deploy deploy-gh-pages deploy-gh-pages-clean
deploy-s0: prepare-server-deploy push-s0
deploy-s1: prepare-server-deploy push-s1
deploy-s2: prepare-server-deploy push-s2
prepare-server-deploy: website
# Ship a copy of the front end to each server for debugging.
# https://github.com/badges/shields/issues/1220
rm -rf ${SERVER_TMP}
git worktree prune
git worktree add -B ${WORKING_BRANCH} ${SERVER_TMP}
cp -r build ${SERVER_TMP}
git -C ${SERVER_TMP} add -f build/
git -C ${SERVER_TMP} commit --no-verify -m '[DEPLOY] Add frontend for debugging'
mkdir -p ${SERVER_TMP}/private
cp private/secret-production.json ${SERVER_TMP}/private/secret.json
cp Verdana.ttf ${SERVER_TMP}
git -C ${SERVER_TMP} add -f private/secret.json Verdana.ttf
git -C ${SERVER_TMP} commit --no-verify -m '[DEPLOY] MUST NOT BE ON GITHUB'
clean-server-deploy:
rm -rf ${SERVER_TMP}
git worktree prune
push-s0:
git push -f s0 ${WORKING_BRANCH}:master
push-s1:
git push -f s1 ${WORKING_BRANCH}:master
push-s2:
git push -f s2 ${WORKING_BRANCH}:master
deploy-gh-pages:
rm -rf ${FRONTEND_TMP}
git worktree prune
LONG_CACHE=true \
BASE_URL=https://img.shields.io \
NEXT_ASSET_PREFIX=https://shields.io \
npm run build
git worktree add -B gh-pages ${FRONTEND_TMP}
git -C ${FRONTEND_TMP} ls-files | xargs git -C ${FRONTEND_TMP} rm
git -C ${FRONTEND_TMP} commit --no-verify -m '[DEPLOY] Completely clean the index'
cp -r build/* ${FRONTEND_TMP}
cp favicon.png ${FRONTEND_TMP}
echo shields.io > ${FRONTEND_TMP}/CNAME
touch ${FRONTEND_TMP}/.nojekyll
git -C ${FRONTEND_TMP} add .
git -C ${FRONTEND_TMP} commit --no-verify -m '[DEPLOY] Add built site'
git push -f origin gh-pages
deploy-gh-pages-clean:
rm -rf ${FRONTEND_TMP}
git worktree prune
deploy-heroku:
git add -f Verdana.ttf private/secret.json build/
git commit --no-verify -m'MUST NOT BE ON GITHUB'
git push -f heroku HEAD:master
git reset HEAD~1
(git checkout -B gh-pages && \
git merge master && \
git push -f origin gh-pages:gh-pages) || git checkout master
git checkout master
test:
npm test
.PHONY: all favicon website deploy prepare-server-deploy clean-server-deploy deploy-s0 deploy-s1 deploy-s2 push-s0 push-s1 push-s2 deploy-gh-pages deploy-gh-pages-clean deploy-heroku setup redis test