Created
June 14, 2015 02:32
-
-
Save mavcunha/a997cb1f14c9a4836edb to your computer and use it in GitHub Desktop.
Script to trigger Snap when Dropbox folder is updated.
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
#!/usr/bin/env bash | |
set -e | |
SNAP_KEY=$(keychain snap-api-key) | |
SNAP_API_ROOT_URL="https://api.snap-ci.com/project/mavcunha/blog/branch/master" | |
SNAP_LATEST="/pipelines/latest" | |
HTTP_OPTS="-u mavcunha:${SNAP_KEY} --silent -X" | |
function _latest_pipeline() { | |
local snap_result="" | |
snap_result=$(curl ${HTTP_OPTS} GET ${SNAP_API_ROOT_URL}${SNAP_LATEST} | jq ._links.redirect.href | tr -d '"' ) | |
echo ${snap_result##*/} | |
} | |
function _publish() { | |
local pipeline=${1} | |
[[ -z ${pipeline} ]] && exit 1 | |
curl ${HTTP_OPTS} POST ${SNAP_API_ROOT_URL}/trigger/${pipeline}/publish | jq .message | |
} | |
echo "Start listening for triggers" | |
while read -d "" event; do | |
echo "Publishing!" | |
_publish $(_latest_pipeline) | |
done < <(fswatch -0 ~/Dropbox/PublishBlog) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment