Created
December 10, 2015 00:39
-
-
Save kacole2/7f31a4ad4b8837035193 to your computer and use it in GitHub Desktop.
Travis CI to update websites via FTP by thinking it's a Node.js app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
language: node_js | |
node_js: | |
- "0.11" | |
# whitelist | |
branches: | |
only: | |
- master | |
env: | |
global: | |
- secure: h6i/QFDLprVJe7u/ZT... | |
- secure: CeolZiNWmqNp03j2bF... | |
after_success: | |
- ./deploy.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "mywebsite.com", | |
"description": "my website", | |
"version": "0.0.1", | |
"scripts": { | |
"test": "node test.js" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('Nothing to see here...'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment