-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_tracks.sh
executable file
·65 lines (52 loc) · 1.84 KB
/
create_tracks.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
62
63
64
65
#!/bin/bash
# This script look inside publish_channels for all tracks that should exits.
# If the track does not exist, it creates it.
if ! command -v charmcraft &> /dev/null
then
echo "charmcraft could not be found"
echo "Install it with: snap install charmcraft --classic"
exit 1
fi
if ! command -v yq &> /dev/null
then
echo "yq could not be found"
echo "Install it with: snap install yq"
exit 1
fi
if ! command -v jq &> /dev/null
then
echo "jq could not be found"
echo "Install it with: snap install jq"
exit 1
fi
if ! command -v curl &> /dev/null
then
echo "curl could not be found"
echo "Install it with: apt install curl"
exit 1
fi
opt_charm=""
publish_channel=$(yq -r '.[0].project.vars.publish_channels | to_entries | .[] | (.key + " " + .value)' zuul.d/zuul.yaml)
while IFS=' ' read -r charm _; do
opt_charm="$opt_charm --charm=$charm"
done < <(echo "$publish_channel")
charmcraft login --export=sunbeam-charms.auth \
$opt_charm \
--permission=package-view-metadata \
--permission=package-manage-metadata \
--ttl=3600
CHARMHUB_MACAROON_HEADER="Authorization: Macaroon $(cat sunbeam-charms.auth | base64 -d | jq -r .v)"
while IFS=' ' read -r charm channel; do
track=$(echo "$channel" | cut -d'/' -f1)
url=https://api.charmhub.io/v1/charm/$charm
metadata=$(curl -s "$url" -H'Content-type: application/json' -H "$CHARMHUB_MACAROON_HEADER")
tracks=$(echo "$metadata" | jq -r '.metadata.tracks[].name')
if [[ $tracks =~ $track ]]; then
echo "Track $track already exists for charm $charm"
else
echo "Creating track $track for charm $charm"
curl -s "$url/tracks" -X POST -H'Content-type: application/json' -H "$CHARMHUB_MACAROON_HEADER" -d '[{"name": "'"$track"'"}]'
fi
done < <(echo "$publish_channel")
# Clean the created files
rm sunbeam-charms.*