Skip to content

Instantly share code, notes, and snippets.

@msaladna
Created September 11, 2019 20:48
Show Gist options
  • Save msaladna/1d2bc92107e4bcc6faecc9a761166e86 to your computer and use it in GitHub Desktop.
Save msaladna/1d2bc92107e4bcc6faecc9a761166e86 to your computer and use it in GitHub Desktop.
#!/bin/sh -x
set -euo pipefail
BRANCH="${BRANCH:-master}"
APNSCP_HOME="/usr/local/apnscp"
LN="/usr/local/apnscp-${BRANCH}"
function mount_layer() {
mount -t overlay -o lowerdir=/usr/local/apnscp-layers/official:/usr/local/apnscp-layers/blank,upperdir=/usr/local/apnscp-layers/production-${BRANCH}/,workdir=/tmp $APNSCP_HOME $APNSCP_HOME
}
function reload_layer() {
umount $APNSCP_HOME || true
mount_layer
}
#[[ -d $APNSCP_HOME/lib ]] || mount_layer
reload_layer
pushd $APNSCP_HOME
git fetch
# New branch?
REVBRANCH=master
set +e
git rev-parse --verify gitlab/"$BRANCH" 2> /dev/null
RET=$?
set -e
# > /dev/null 2>&1
if test $RET -eq 0 ; then
REVBRANCH=$BRANCH
fi
#git checkout "$BRANCH"
LASTRUN=$(git log -n 1 gitlab/"$REVBRANCH" | grep '^Date:' | cut -d' ' -f1 --complement)
popd
reload_layer
pushd /usr/local/apnscp-layers
pushd history-tracker
git checkout "$BRANCH"
git reset --hard origin/"$BRANCH"
git pull --commit --no-edit origin "$BRANCH"
git submodule update --recursive --remote
popd
rm -rf official
git clone --depth 1 --branch "$BRANCH" --recurse file:///usr/local/apnscp-layers/history-tracker official
pushd official
git reset --hard "$BRANCH"
rm -rf .git lib/modules/.git
popd
TEMPFILE=`mktemp`
trap (){ rm -f $TEMPFILE; }
pushd history-tracker
# Update composite after mucking around lower layers
reload_layer
( git log --after="$LASTRUN" . ; git submodule foreach git log --after="$LASTRUN" ) | apnscp_php $APNSCP_HOME/bin/scripts/changelogparser.php | php -R '$line = strip_tags($argn); $line && print($line . "\n");' > $TEMPFILE
if [[ ! -s $TEMPFILE ]] ; then
echo "empty commit"
exit 255
fi
popd
pushd $APNSCP_HOME
$APNSCP_HOME/build/ioncube/compileBackend.sh
git add -A
git commit -S -a -F $TEMPFILE
git push bitbucket master:$BRANCH
git push gitlab master:$BRANCH
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment