diff --git a/scripts/build-upload-gate b/scripts/build-upload-gate index 737617ac57..4317abda40 100755 --- a/scripts/build-upload-gate +++ b/scripts/build-upload-gate @@ -1,6 +1,8 @@ #!/bin/bash set -e +cd $(dirname $0)/.. + BUILD_DEBUG="${BUILD_DEBUG:-}" if [[ -n "${BUILD_DEBUG}" ]]; then set -x @@ -35,7 +37,7 @@ tmp=$(mktemp -u) STATUS_CODE=$(curl -w "%{http_code}" -s -o $tmp https://api.github.com/repos/$DRONE_REPO/branches/$DRONE_BRANCH) if [ "$STATUS_CODE" == "403" ]; then - RATE_LIMIT_REMAINING=$(curl -s https://api.github.com/rate_limit | jq -r .rate.remaining) + RATE_LIMIT_REMAINING=$(curl -s https://api.github.com/rate_limit | ./scripts/jq-nano - rate remaining) echo "Remaining GITHUB requests available: $RATE_LIMIT_REMAINING" RATE_LIMIT_REMAINING=${RATE_LIMIT_REMAINING:-0} if ((RATE_LIMIT_REMAINING < 1)); then @@ -45,7 +47,7 @@ if [ "$STATUS_CODE" == "403" ]; then # Fall through to the normal path like any other failed status code fi -LATEST_BRANCH_COMMIT=$(cat $tmp | jq -r .commit.sha) +LATEST_BRANCH_COMMIT=$(cat $tmp | ./scripts/jq-nano - commit sha) rm $tmp echo "Latest Branch Commit: $LATEST_BRANCH_COMMIT" if [ -z "$LATEST_BRANCH_COMMIT" ]; then diff --git a/scripts/jq-nano b/scripts/jq-nano new file mode 100755 index 0000000000..da3e761f21 --- /dev/null +++ b/scripts/jq-nano @@ -0,0 +1,25 @@ +#!/usr/bin/env node + +const fs = require('fs'); +const readline = require('readline'); + +const args = process.argv.slice(2); +const file = args.shift(); + +let text; + +if ( file === '-' ) { + process.stdin.resume(); + text = fs.readFileSync(0, "utf8"); +} else { + text = fs.readFileSync(file, "utf8"); +} + +const data = JSON.parse(text); + +let out = data; +while ( args.length ) { + out = out[args.shift()]; +} + +console.log(out);