Skip to content

Instantly share code, notes, and snippets.

@dylanPowers
Last active December 31, 2015 09:49
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 dylanPowers/7969683 to your computer and use it in GitHub Desktop.
Save dylanPowers/7969683 to your computer and use it in GitHub Desktop.
Dart deploy to github user page script. This uses pub build for the compilation to js. It also depends on pub being in your path. For a rough overview, it runs a pub build, then pushes the contents from the normally ignored build directory to the master branch on github.
#!/bin/sh
echo "\nBacking up the source with a git push"
git push
if [ $? -ne 0 ]; then
echo "\n\ngit push failed"
exit 1
fi
echo "\nRunning pub build..."
pub build
if [ $? -ne 0 ]; then
echo "\n\nPub build failed"
exit 1
fi
echo "\nAttempting to commit new build into master..."
build_rev_hash=`git rev-parse HEAD`
build_rev_branch=`git rev-parse --abbrev-ref HEAD`
git checkout master
if [ $? -ne 0 ]; then
echo "\n\nChecking out master failed"
exit 1
fi
cleanup() {
git checkout $build_rev_branch
pub get
}
# Clean the directory while ignoring build/ .git/ and any other hidden .* files/directories
# Note that this is a potentially dangerous operation!!!! If the .git directory gets
# clobbered, you're SOL
find . -maxdepth 1 -not -empty \( -name 'build' -o -name '.git' \
-o -wholename './.*' \) \
-o -wholename '.' -o -print0 | xargs -0 rm -r
# Put the deployable files into place
cp -R build/web/* .
git checkout $build_rev_hash -- CNAME
git add -A
git commit -m "Autobuild at revision $build_rev_hash"
echo "\nPublishing to origin master"
git push origin master
if [ $? -ne 0 ]; then
echo "\n\nPublishing failed"
cleanup
exit 1
fi
cleanup
echo "\nDeployment succeeded!"
# Master branch .gitignore
# Ignore the build stuff
/build/
/.buildlog
# Ignore pub
/.pub/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment