Skip to content

Instantly share code, notes, and snippets.

@mblarsen
Created April 17, 2019 06:16
Show Gist options
  • Save mblarsen/8923bffc6bb20682539afead249b8143 to your computer and use it in GitHub Desktop.
Save mblarsen/8923bffc6bb20682539afead249b8143 to your computer and use it in GitHub Desktop.
Query buildkit builds for changes since last
#!/usr/bin/env bash
set -euo pipefail
function builds() {
curl -s https://graphql.buildkite.com/v1 \
-H "Authorization: Bearer $GRAPHQL_KEY" \
-d '{
"query": "query SuccessfullBuilds { pipeline(slug: \"'"$BUILDKITE_ORGANIZATION_SLUG/$BUILDKITE_PIPELINE_SLUG"'\") { builds { edges { node { id commit message state } } } } }",
"variables": "{ }"
}'
}
function builds_with_state() {
jq -r '.data.pipeline.builds.edges[].node | select(.state == "'$1'") | .commit'
}
LAST_COMMIT=$(builds | builds_with_state "PASSED" | head -n 1)
FILES=$(git diff --name-only $LAST_COMMIT)
MATCH=functions*
for f in $FILES ; do
if [[ $f == $MATCH ]]; then
exit 0
fi
done
exit 1
@mblarsen
Copy link
Author

mblarsen commented Apr 17, 2019

LAST_COMMIT = commit of last passed bulid
MATCH = in my case I want to exit successfully if something matches "functions" otherwise fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment