Skip to content

Instantly share code, notes, and snippets.

@Seldaek
Created May 21, 2012 08:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Seldaek/2761118 to your computer and use it in GitHub Desktop.
Save Seldaek/2761118 to your computer and use it in GitHub Desktop.
PHAR build script

This creates a $buildphar as $root/$target/foo.phar + one phar per tag as $root/$target/download/$tag/foo.phar

It also dumps the latest git commit hash built in $root/$target/version

# config
root="/var/www/example.org"
build="project-src"
buildscript="bin/compile"
buildphar="example.phar"
target="web"
repo="https://github.com/example/example.git"
composer="/usr/bin/composer.phar"
# init
if [ ! -d "$root/$build" ]
then
cd $root
git clone $repo $build
fi
cd "$root/$build"
# update master
/usr/bin/git fetch -q origin && \
/usr/bin/git fetch --tags -q origin && \
/usr/bin/git checkout master -q && \
/usr/bin/git rebase origin/master -q && \
/usr/local/bin/php $composer install -q && \
/usr/local/bin/php -d phar.readonly=0 $buildscript && \
mv $buildphar "$root/$target/$buildphar" && \
/usr/bin/git log --pretty="%h" -n1 HEAD > "$root/$target/version"
# create tagged releases
for version in `git tag`; do
if [ ! -f "$root/$target/download/$version/$buildphar" ]
then
mkdir -p "$root/$target/download/$version/"
/usr/bin/git checkout $version -q && \
/usr/local/bin/php $composer install -q && \
/usr/local/bin/php -d phar.readonly=0 $buildscript && \
mv $buildphar "$root/$target/download/$version/$buildphar"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment