aboutsummaryrefslogtreecommitdiff
path: root/submit-builds
blob: eada36932b784ee1af013c64ca5dc911c872152b (plain)
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
62
63
64
65
66
#!/bin/sh
upstream=https://builds.sr.ht
manifest=build.yml

if [ -e ~/.config/sr.ht ]
then
	. ~/.config/sr.ht
fi

while getopts m:u:t:h flag
do
	case $flag in
		u)
			upstream="$OPTARG"
			;;
		t)
			bearer_token="$OPTARG"
			;;
		m)
			manifest="$OPTARG"
			;;
		h)
			echo "Usage: $0 [-u https://upstream...] [-t oauth token] <packages...>"
			exit 0
			;;
	esac
done
shift $((OPTIND-1))

builds=""
note=""
for target in $*
do
	if [ "$builds" = "" ]
	then
		builds="'${target#sr.ht/}'"
		note="${target#sr.ht/}"
	else
		builds="$builds, '${target#sr.ht/}'"
		if [ "${#note}" -lt 128 ]
		then
			note="$note, ${target#sr.ht/}"
		fi
	fi
done

vars="$(sed "s/packages: \\[\\]/packages: [$builds]/g" < $manifest | jq -sR '{
	"manifest": .,
	"tags": ["apkbuilds"],
	"note": "'"$note"'"
}')"
query="$(jq -sR '.' <<"EOF"
mutation SubmitJob($manifest: String!, $tags: [String!]!, $note: String!) {
	submit(manifest: $manifest, tags: $tags, note: $note) {
		id, tags
	}
}
EOF
)"

curl --oauth2-bearer "$bearer_token" \
	-H Content-Type:application/json \
	-d '{
		"query": '"$query"',
		"variables": '"$vars"'
	}' "$upstream/query" | jq .