Created
April 17, 2019 06:16
-
-
Save mblarsen/8923bffc6bb20682539afead249b8143 to your computer and use it in GitHub Desktop.
Query buildkit builds for changes since last
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 -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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LAST_COMMIT = commit of last passed bulid
MATCH = in my case I want to exit successfully if something matches "functions" otherwise fail