Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Travis CI to update websites via FTP by thinking it's a Node.js app
language: node_js
node_js:
- "0.11"
# whitelist
branches:
only:
- master
env:
global:
- secure: h6i/QFDLprVJe7u/ZT...
- secure: CeolZiNWmqNp03j2bF...
after_success:
- ./deploy.sh
#!/bin/bash
gitLastCommit=$(git show --summary --grep="Merge pull request")
if [[ -z "$gitLastCommit" ]]
then
lastCommit=$(git log --format="%H" -n 1)
else
echo "We got a Merge Request!"
#take the last commit and take break every word into an array
arr=($gitLastCommit)
#the 5th element in the array is the commit ID we need. If git log changes, this breaks. :(
lastCommit=${arr[4]}
fi
echo $lastCommit
filesChanged=$(git diff-tree --no-commit-id --name-only -r $lastCommit)
if [ ${#filesChanged[@]} -eq 0 ]; then
echo "No files to update"
else
for f in $filesChanged
do
#do not upload these files that aren't necessary to the site
if [ "$f" != ".travis.yml" ] && [ "$f" != "deploy.sh" ] && [ "$f" != "test.js" ] && [ "$f" != "package.json" ]
then
echo "Uploading $f"
curl --ftp-create-dirs -T $f -u $FTP_USER:$FTP_PASS ftp://bourbonpursuit.com/$f
fi
done
fi
{
"name": "mywebsite.com",
"description": "my website",
"version": "0.0.1",
"scripts": {
"test": "node test.js"
}
}
console.log('Nothing to see here...');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment