-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-with-curl-json.sh
executable file
·61 lines (52 loc) · 1.64 KB
/
build-with-curl-json.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
##
# Script to send the BASIC file to the service using the curl to send the binary
# to the service, and retrieve a build result as structured data.
#
# This example code requires:
#
# curl
# jq
# sed
# base64
#
# The submission code examples come from here:
#
# https://build.riscos.online/ci-build.html#curl
#
# The result comes out as JSON, which is described under the JSON API, here:
#
# https://build.riscos.online/api.html
#
# Syntax: build-with-curl-json.sh [<input-file> [<output-prefix>]]
#
set -eo pipefail
input_file="${1:-myprogram,fd1}"
output_prefix="${2:-data}"
# Remove the result data if any
rm -f result.json
echo Run on the build service
# Note: The curl -F option treats a `,` as a separator, so RISC OS
# filenames can't just be given directly - instead we have
# curl read the file from stdin.
curl --silent -F source=@- -o result.json http://json.build.riscos.online/build/json < "$input_file"
if [[ ! -f result.json ]] ; then
echo "CURL request failed (no JSON output generated)" >&2
exit 1
fi
# Write out the messages and output, indented.
echo "Build completed:"
jq -r '.messages[]' result.json | sed 's/^/ /'
echo "Output:"
jq -r 'reduce .output[] as $i ("";. + $i)' result.json | sed 's/^/ /'
# Check that we were successful
RC=$(jq -r .rc result.json)
echo "Exit code: $RC"
FILETYPE=$(jq -r .filetype result.json)
FILETYPE_HEX=$(printf '%03x' "$FILETYPE")
if [ "$RC" = 0 ] ; then
echo "Output type: &$FILETYPE_HEX"
jq -r .data result.json | base64 --decode - > "${output_prefix},$FILETYPE_HEX"
fi
# Return the RC to the user, so that we can use this in scripts if we want
exit "$RC"