Skip to content

Instantly share code, notes, and snippets.

@derhasi
Created April 23, 2015 09:32
Show Gist options
  • Save derhasi/57fbfc67fd2cd95f6b17 to your computer and use it in GitHub Desktop.
Save derhasi/57fbfc67fd2cd95f6b17 to your computer and use it in GitHub Desktop.
A build script for creating a build branch with all composer dependencies. Needs https://github.com/derhasi/staging
#!/usr/bin/env bash
########################################################################################################################
#
# BUILD SCRIPT
#
# Currently the build is triggered from the current branch!
#
# The build script builds a new branch from the current branch by installing all dependencies and allowing those
# dependencies to be checked in with using .build.gitignore.
#
########################################################################################################################
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
CURRENT_SHA=$(git rev-parse HEAD)
# Create a new branch
TEMP_BRANCH=BUILD_$(date +%s)
git checkout -b $TEMP_BRANCH
# First we build our artifacts
composer dependency-cleanup
# We need to touch that file, so the build does not wait for a prompt when running composer install.
touch docroot/sites/default/local.settings.php
composer install
# Remove all .git repos in subdirectories.
find * -name ".git" | xargs rm -r
# Then we change our gitignore, so files relevant for the build can be checked in.
mv ./.gitignore ./.orig.gitignore
mv ./.build.gitignore ./.gitignore
# Make sure all ignored files are not in the repo, even if they have been checked in before.
git rm -r --cached .
git add .
git commit -m "Build for $CURRENT_BRANCH (ref: $CURRENT_SHA)"
# After we created the temporary build branch, we update the general build branch.
./vendor/bin/staging -m "Updated build for $CURRENT_BRANCH (ref: $CURRENT_SHA)" origin build $TEMP_BRANCH
# Switch ignores back, after our build was built.
mv ./.gitignore ./.build.gitignore
mv ./.orig.gitignore ./.gitignore
# Move back to current branch
git checkout -f $CURRENT_BRANCH
# Remove temp branch again.
git branch -D $TEMP_BRANCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment