apkbuilds @ 01ad5973c88c01ced5551758645f3c8da6026078

 1#!/bin/sh
 2upstream=https://builds.sr.ht
 3manifest=build.yml
 4
 5if [ -e ~/.config/sr.ht ]
 6then
 7	. ~/.config/sr.ht
 8fi
 9
10while getopts m:u:t:h flag
11do
12	case $flag in
13		u)
14			upstream="$OPTARG"
15			;;
16		t)
17			bearer_token="$OPTARG"
18			;;
19		m)
20			manifest="$OPTARG"
21			;;
22		h)
23			echo "Usage: $0 [-u https://upstream...] [-t oauth token] <packages...>"
24			exit 0
25			;;
26	esac
27done
28shift $((OPTIND-1))
29
30builds=""
31note=""
32for target in $*
33do
34	if [ "$builds" = "" ]
35	then
36		builds="'${target#sr.ht/}'"
37		note="${target#sr.ht/}"
38	else
39		builds="$builds, '${target#sr.ht/}'"
40		if [ "${#note}" -lt 128 ]
41		then
42			note="$note, ${target#sr.ht/}"
43		fi
44	fi
45done
46
47vars="$(sed "s/packages: \\[\\]/packages: [$builds]/g" < $manifest | jq -sR '{
48	"manifest": .,
49	"tags": ["apkbuilds"],
50	"note": "'"$note"'"
51}')"
52query="$(jq -sR '.' <<"EOF"
53mutation SubmitJob($manifest: String!, $tags: [String!]!, $note: String!) {
54	submit(manifest: $manifest, tags: $tags, note: $note) {
55		id, tags
56	}
57}
58EOF
59)"
60
61curl --oauth2-bearer "$bearer_token" \
62	-H Content-Type:application/json \
63	-d '{
64		"query": '"$query"',
65		"variables": '"$vars"'
66	}' "$upstream/query" | jq .