Upload build-gate to use a "version" of jq that will exist

This commit is contained in:
Vincent Fiduccia 2021-04-02 12:38:38 -07:00
parent 7cb9153076
commit 486aa7fa4e
No known key found for this signature in database
GPG Key ID: 2B29AD6BB2BB2582
2 changed files with 29 additions and 2 deletions

View File

@ -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

25
scripts/jq-nano Executable file
View File

@ -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);