Skip to content

Instantly share code, notes, and snippets.

@mavcunha
Created June 14, 2015 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mavcunha/a997cb1f14c9a4836edb to your computer and use it in GitHub Desktop.
Save mavcunha/a997cb1f14c9a4836edb to your computer and use it in GitHub Desktop.
Script to trigger Snap when Dropbox folder is updated.
#!/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