Skip to content

Commit

Permalink
Update Travis deploy script to delete gh-pages/local-pages history (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
akshatnitd authored and fragm3 committed Aug 17, 2019
1 parent f3bccac commit 2fbfce6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 58 deletions.
82 changes: 24 additions & 58 deletions deploy.sh
Expand Up @@ -25,95 +25,61 @@ chmod 600 ../deploy_key
eval `ssh-agent -s`
ssh-add ../deploy_key

# Cloning the repository to repo/ directory,
# Cloning the source branch only of repository to repo/ directory,
# Creating gh-pages branch if it doesn't exists else moving to that branch
git clone $REPO repo
cd repo
git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH
cd ..
git clone --single-branch --branch $SOURCE_BRANCH $REPO repo

# Setting up the username and email.
git config user.name "Travis CI"
git config user.email "$COMMIT_AUTHOR_EMAIL"

# Cleaning up the old repo's gh-pages branch except CNAME file and 404.html
find repo/* ! -name "CNAME" ! -name "404.html" -maxdepth 1 -exec rm -rf {} \; 2> /dev/null
cd repo

git add --all
git commit -m "Travis CI Clean Deploy : ${SHA}"

git checkout $SOURCE_BRANCH

# Actual building and setup of current push or PR.
npm install
npm run build
mv build ../build/

git checkout $TARGET_BRANCH
rm -rf node_modules/
# Create an orphan target branch
git checkout --orphan $TARGET_BRANCH
# Remove all the files that were checked out from source branch
git rm -rf .
mv ../build/* .
cp index.html 404.html
rm -Rf node_modules/ package-lock.json

# Staging the new build for commit; and then committing the latest build
git add -A
git commit --amend --no-edit --allow-empty
# Create a commit on target branch
git add --all
git commit -m "Travis CI Clean Deploy : ${SHA}"

# Deploying only if the build has changed
if [ -z `git diff --name-only HEAD HEAD~1` ]; then
# There are changes in the Build; push the changes to gh-pages
echo "There are changes in the Build; pushing the changes to gh-pages"

echo "No Changes in the Build; exiting"
exit 0
# Actual push to gh-pages branch via Travis
git push --force $SSH_REPO $TARGET_BRANCH

else
# There are changes in the Build; push the changes to gh-pages
echo "There are changes in the Build; pushing the changes to gh-pages"

# Actual push to gh-pages branch via Travis
git push --force $SSH_REPO $TARGET_BRANCH
fi

# Deploying to local-pages
git checkout $LOCAL_TARGET_BRANCH || git checkout --orphan $LOCAL_TARGET_BRANCH
cd ..

# Cleaning up the old repo's gh-pages branch except CNAME file and 404.html
find repo/* ! -name "CNAME" ! -name "404.html" -maxdepth 1 -exec rm -rf {} \; 2> /dev/null
cd repo

git add --all
git commit -m "Travis CI Clean Deploy : ${SHA}"

git checkout $SOURCE_BRANCH

# Actual building and setup of current push or PR.
npm install
export REACT_APP_API_URL=http://localhost:4000
export REACT_APP_LOCAL_ENV=true
npm run build
mv build ../build/

git checkout $LOCAL_TARGET_BRANCH
rm -rf node_modules/
# Create an orphan local target branch
git checkout --orphan $LOCAL_TARGET_BRANCH
# Remove all the files that were checked out from source branch
git rm -rf .
mv ../build/* .
mv build/* .
rm -Rf build
cp index.html 404.html
rm -Rf node_modules/ package-lock.json

# Staging the new build for commit; and then committing the latest build
git add -A
git commit --amend --no-edit --allow-empty

# Deploying only if the build has changed
if [ -z `git diff --name-only HEAD HEAD~1` ]; then

echo "No Changes in the Build; exiting"
exit 0

else
# There are changes in the Build; push the changes to gh-pages
echo "There are changes in the Build; pushing the changes to local-pages"
# Create a commit on target branch
git add --all
git commit -m "Travis CI Clean Deploy : ${SHA}"

# Actual push to gh-pages branch via Travis
git push --force $SSH_REPO $LOCAL_TARGET_BRANCH
fi
# There are changes in the Build; push the changes to local-pages
echo "There are changes in the Build; pushing the changes to local-pages"
1 change: 1 addition & 0 deletions public/CNAME
@@ -0,0 +1 @@
susi.ai

0 comments on commit 2fbfce6

Please sign in to comment.