~landscape/landscape-bundles/trunk

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash -e
#
# Mostly intended to be called with make targets
# Needs make clean, make render called first.
#

ACTION=$1
STORE_USER=${2:-landscape}
CHANNEL=${3}
INITIAL_CHANNEL="edge"
RELEASE_CHANNEL="stable"

if [ -z "$ACTION" ]; then
    cat <<EOF
Usage: $0 ACTION [user]
   actions:
        push - push to 'unpublished' channel
        publish-latest - publish the latest copy
        diff - diff your branch to the latest stable channel copy
   user:
        charm store user name
EOF
    exit 1
fi

if [ "$ACTION" == "push" ]; then
    echo "# Will be pushing new [unpublished] versions to the charm store"
    echo "#   as user: $STORE_USER"
fi

for target in landscape-dense-maas landscape-dense landscape-scalable; do

    if [ "$ACTION" == "diff" ]; then
        if [ -z $CHANNEL ]; then
            CHANNEL=$RELEASE_CHANNEL
        fi
        echo "# [$target] Pulling fresh copy from $CHANNEL channel"
        (set -x; charm pull --channel $CHANNEL "cs:~${STORE_USER}/bundle/${target}" build/${target}-${CHANNEL})

        echo "# [$target] Diff from latest $CHANNEL"
        (set +e; set -x; diff -Naur --exclude bundles.yaml build/${target}-${CHANNEL} build/${target}); RC=$?
        if [ $RC -eq 0 ]; then
            echo "<local bundle matches $CHANNEL channel>"
        fi
    fi

    if [ "$ACTION" == "push" ]; then
        echo "# [$target] Pushing to namespace ~${STORE_USER}, unpublished channel"
        url=$( (set -x; charm push build/${target} cs:~${STORE_USER}/bundle/${target}) | grep ^url | awk '{ print $2 }')

        if [ -n $CHANNEL ]; then
            echo "# [$target] Publishing to ${CHANNEL} channel"
            (set -x; charm release --channel ${CHANNEL} $url)
        fi
    fi

    if [ "$ACTION" == "publish-latest" ]; then
        latest=$(charm show --channel unpublished --format=json cs:~${STORE_USER}/bundle/${target} | jq -r '.["revision-info"].Revisions[0]')

        if [ -z $CHANNEL ]; then
            CHANNEL=$RELEASE_CHANNEL
        fi
        echo "# [$target] Publishing latest unpublished revision to ${CHANNEL} channel"
        (set -x; charm release --channel ${CHANNEL} $latest)
    fi

done

cat <<EOF
#
# You can manually examine things if you wish:"
#   ll build/*"
#   ll build/*-stable"
#
# Show details in the store:
#   charm show cs:~${STORE_USER}/bundle/landscape-dense-maas
#   charm show --channel unpublished cs:~${STORE_USER}/bundle/landscape-dense-maas
#
# Make sure everyone can use your charm if you want:
#   charm grant cs:~${STORE_USER}/bundle/BUNDLE_NAME-VERSION everyone
#
# Publish like this (controls what clients see by default, you can
# even set it to a previous known good version): 
#   charm publish cs:~${STORE_USER}/bundle/BUNDLE_NAME-VERSION
#
EOF