github.com/m3db/m3@v1.5.0/.buildkite/scripts/adhoc_build.sh (about) 1 #!/bin/bash 2 3 set -eo pipefail 4 5 # Script to run adhoc buildkite builds for the given branch. Useful for running 6 # CI tests against branches that may not yet be ready for a PR. See 7 # https://buildkite.com/docs/apis/rest-api#authentication for more info on 8 # buildkite tokens. To take full advantage of this script your token will need 9 # `read_builds` and `write_builds` scopes. The script expects a working 10 # installation of jq. 11 12 function usage() { 13 echo "build.sh <build|list>" 14 exit 1 15 } 16 17 function build() { 18 if [[ -z "$BUILDKITE_CLI_TOKEN" ]]; then 19 echo "BUILDKITE_CLI_TOKEN must be set" 20 exit 1 21 fi 22 23 local action=$1 24 local url="https://api.buildkite.com/v2/organizations/uberopensource/pipelines/m3-monorepo-ci" 25 local auth="Authorization: Bearer $BUILDKITE_CLI_TOKEN" 26 27 if [[ "$action" != "build" && "$action" != "list" ]]; then 28 usage 29 fi 30 31 if [[ "$action" == "list" ]]; then 32 curl -sSf -H "$auth" "${url}/builds" 33 return 34 fi 35 36 # action == build 37 local branch 38 branch=$(git rev-parse --abbrev-ref HEAD) 39 40 local data 41 data=$(cat <<EOF 42 { 43 "branch": "${branch}", 44 "message": "$(git show -s --format=%s HEAD) (adhoc)", 45 "commit": "HEAD", 46 "ignore_pipeline_branch_filters": true, 47 "clean_checkout": true 48 } 49 EOF 50 ) 51 52 curl -sSf -X POST -H "$auth" "${url}/builds" -d "$data" | jq -r .web_url 53 } 54 55 build "$*"