Skip to content

Instantly share code, notes, and snippets.

@kaushalmodi
Last active September 27, 2017 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaushalmodi/456b5ea26b3e869e5d63d4a67b85f676 to your computer and use it in GitHub Desktop.
Save kaushalmodi/456b5ea26b3e869e5d63d4a67b85f676 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# /home/kmodi/go.apps/src/github.com/gohugoio/hugo/README.md
# http://matthewkwilliams.com/index.php/2014/09/28/go-executables-are-statically-linked-except-when-they-are-not/
here=$(pwd)
hugo_src="github.com/gohugoio/hugo"
chroma_src="github.com/alecthomas/chroma"
export CGO_ENABLED=0
export GO_EXTLINK_ENABLED=0
# https://discuss.gohugo.io/t/started-getting-failed-to-normalize-url-string-returning-in/5034/7?u=kaushalmodi
# Do govendor sync to prevent issues like this: https://github.com/gohugoio/hugo/issues/2919
if ! hash govendor 2>/dev/null
then
go get -u -v github.com/kardianos/govendor
fi
# Install hugo for the first time so that the ${GOPATH}/src/${hugo_src}
# directory gets populated.
if [[ ! -d "${GOPATH}/src/${hugo_src}" ]] || ( ! hash hugo 2>/dev/null )
then
go get -u -v ${hugo_src}
fi
# Update to hugo master branch
cd "${GOPATH}/src/${hugo_src}" || exit
git fetch --all # fetch new branch names if any
git checkout master
# git fetch --all
# Force update the vendor file in case it got changed
git reset --hard origin/master
# Synchronize all the dependent packages as per the just updated vendor file
govendor sync
# Update dependent packages from their master branches
# govendor fetch github.com/chaseadamsio/goorgeous
# govendor fetch github.com/chaseadamsio/goorgeous@=fixNewlineParagraphs
# Tue Sep 26 11:28:47 EDT 2017 - kmodi
# Turns out that the chroma package contains sub-packages too.. so have to
# include all separately.
# govendor fetch ${chroma_src}
# govendor fetch ${chroma_src}/formatters
# govendor fetch ${chroma_src}/formatters/html
# govendor fetch ${chroma_src}/lexers
# govendor fetch ${chroma_src}/styles
# https://discourse.gohugo.io/t/building-hugo-with-the-latest-version-of-chroma/8543/2?u=kaushalmodi
go get -u -v ${chroma_src}/...
# make vendor
rm -rf "${GOPATH}/src/${hugo_src}/vendor/${chroma_src}"
hugo_commithash=$(git rev-parse --short HEAD 2>/dev/null)
chroma_commithash=$(cd "${GOPATH}/src/${chroma_src}" && git rev-parse --short HEAD 2>/dev/null)
builddate=$(date +%FT%T%z)
go install -v \
-ldflags "-X ${hugo_src}/hugolib.CommitHash=${hugo_commithash}:chroma-${chroma_commithash} \
-X ${hugo_src}/hugolib.BuildDate=${builddate}" \
${hugo_src}
cd "${here}" || exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment