Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for github deploy #1774

Merged
merged 10 commits into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

@espadrine espadrine Jul 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulmelnikow The point of the CNAME file was to have GitHub redirect from badges.github.io/shields to shields.io.

I believe it no longer needs that, as it is now set up through the project settings: https://help.github.com/articles/adding-or-removing-a-custom-domain-for-your-github-pages-site/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something in my testing suggested the file still has an effect. When I ran this script on my fork without the CNAME file in gh-pages, it turned off the custom domain.

This link suggests changes made in the UI are stored in the repo: https://help.github.com/articles/troubleshooting-custom-domains/#github-repository-setup-errors

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;
}