Skip to content

Commit

Permalink
Fixes for github deploy (#1774)
Browse files Browse the repository at this point in the history
This addresses some long-standing comments in #1458 (comment)

We should also adopt Gatsby, create-react-app, or something similar designed for static sites, to eliminate the unnecessary runtime dependency on Next.js while also letting someone else maintain our front-end tooling. :-D These alternative tools might work just fine in subdirectories without config, and we might be able to leave Jekyll turned on (though we don’t need it). However these git-related changes are orthogonal.

- Don’t check out master, making it possible to deploy the currently checked-out commit
- Disable Jekyll which we don’t need. This allows _next folders to be deployed, and the related URL rewriting to be removed.
- Completely empty the deploy branch’s index before deployment. This prevents errors from broken symlinks, while preserving the commit history in the deploy branch.
- Do the deployment work in a git working tree. This requires Git 2.18 but makes it possible to do the above very safely.
  • Loading branch information
paulmelnikow authored Jul 19, 2018
1 parent 6462cc4 commit e39b280
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
1 change: 0 additions & 1 deletion CNAME

This file was deleted.

37 changes: 25 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
SHELL:=/bin/bash

DEPLOY_TEMP=${TMPDIR}shields-deploy

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: website deploy-s0 deploy-s1 deploy-s2 deploy-gh-pages
# `website` is needed for the server deploys.
deploy: website deploy-s0 deploy-s1 deploy-s2 deploy-gh-pages deploy-gh-pages-clean

deploy-s0:
# Ship a copy of the front end to each server for debugging.
Expand All @@ -34,17 +38,26 @@ deploy-s2:
git checkout master

deploy-gh-pages:
(LONG_CACHE=true BASE_URL=https://img.shields.io npm run build && \
git checkout -B gh-pages master && \
cp build/index.html index.html && \
cp -r build/_next next && \
pushd next/*/page && mv {_,}error && popd && \
sed -i 's,/_next/,./next/,g' index.html $$(find next -type f) && \
sed -i 's,_error,error,g' index.html $$(find next -type f) && \
git add -f build index.html next && \
git commit -m '[DEPLOY] Build index.html' && \
git push -f origin gh-pages:gh-pages) || git checkout master
git checkout master
rm -rf ${DEPLOY_TEMP}
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 ${DEPLOY_TEMP}
git -C ${DEPLOY_TEMP} ls-files | xargs git -C ${DEPLOY_TEMP} rm
git -C ${DEPLOY_TEMP} commit -m '[DEPLOY] Completely clean the index'
cp -r build/* ${DEPLOY_TEMP}
cp favicon.png ${DEPLOY_TEMP}
echo shields.io > ${DEPLOY_TEMP}/CNAME
touch ${DEPLOY_TEMP}/.nojekyll
git -C ${DEPLOY_TEMP} add .
git -C ${DEPLOY_TEMP} commit -m '[DEPLOY] Add built site'
git push -f origin gh-pages

deploy-gh-pages-clean:
rm -rf $DEPLOY_TEMP
git worktree prune

deploy-heroku:
git add -f Verdana.ttf private/secret.json build/
Expand Down
11 changes: 11 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const envFlag = require('node-env-flag');
const webpack = require('webpack');
const shouldAnalyze = envFlag(process.env.ANALYZE);
const assetPrefix = process.env.NEXT_ASSET_PREFIX;

module.exports = {
webpack: config => {
Expand All @@ -22,9 +23,19 @@ module.exports = {
loader: 'json-loader',
});

if (assetPrefix) {
config.output.publicPath = `${assetPrefix}/${config.output.publicPath}`;
}

return config;
},
exportPathMap: () => ({
'/': { page: '/' },
}),
};

// Avoid setting an `undefined` value. This causes
// `TypeError: Cannot read property 'replace' of undefined` at build time.
if (assetPrefix) {
module.exports.assetPrefix = assetPrefix;
}

0 comments on commit e39b280

Please sign in to comment.