File: release-guide

package info (click to toggle)
cockpit 239-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 67,268 kB
  • sloc: javascript: 245,474; ansic: 72,273; python: 23,634; xml: 6,155; sh: 2,919; makefile: 923; sed: 5
file content (197 lines) | stat: -rwxr-xr-x 3,702 bytes parent folder | download
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/sh -euf
#
# release-guide
#
# A release that commits the HTML guide to another git repository
#
# We update the version number in a Dockerfile, and tests that
# the resulting URLs can be fetched. Commits the changes and pushes
# the result.
#
# We expect an 'html' subdirectory and likely an 'index.html' file there.
#
# Arguments are described here. Most arguments have an equivalent envvar.
#
# -f tgz     RELEASE_SOURCE=tbz     The tarball to extract documentation from
# -q         RELEASE_QUIET=1        Make output more quiet
# -v         RELEASE_VERBOSE=1      Make output more verbose
#

set -euf

# Various arguments
TRANSACTION=${RELEASE_TRANSACTION:-0}
QUIET=${RELEASE_QUIET:-0}
VERBOSE=${RELEASE_VERBOSE:-0}
SRPM=${RELEASE_SRPM:-$PWD/srpm}
SOURCE=${RELEASE_SOURCE:-}
CHECK=${RELEASE_CHECK:-0}

REPO=""
WORKDIR=""
DIRECTORY=""
TARBALL=""

usage()
{
    echo "usage: release-guide [-qvxz] [-f TARBALL] DIRECTORY REPO" >&2
    exit ${1-2}
}

trace()
{
    if [ $QUIET -eq 0 ]; then
        echo "> $@" >&2
    fi
}

message()
{
    echo "release-guide: $@" >&2
}

parse_version()
{
    echo "$@" | sed -n 's/.\+-\([0-9].*\)/\1/p'
}

check()
{
    check-git-rw git@github.com "$REPO"
}

prepare()
{
    local version subdir

    trace "Extracting the tarball $TARBALL"

    WORKDIR=$(mktemp --directory source.XXXXXX)
    mkdir -p $WORKDIR/extract
    tar -f $TARBALL -C $WORKDIR/extract -x

    trace "Checking out Github repo $REPO"

    cd $WORKDIR

    git clone git@github.com:$REPO repo
    cd extract

    set +f
    subdir=$(echo *)
    set -f

    version="$(parse_version $subdir)"
    if [ -z "$version" ]; then
        message "couldn't determine version from $subdir"
        exit 1
    fi

    cd ..

    trace "Committing documentation for version $version"
    mkdir -p repo/guide/
    rm -rf repo/guide/$version
    if [ ! -f extract/$subdir/$DIRECTORY/html/index.html ]; then
        message "no html/index.html documentation in $DIRECTORY"
        exit 1
    fi

    mv -n extract/$subdir/$DIRECTORY/html/ repo/guide/$version
    if [ -f extract/$subdir/$DIRECTORY/index.html ]; then
        mv extract/$subdir/$DIRECTORY/index.html repo/guide/index.html
    fi
    rm -rf repo/guide/latest
    cp -rp repo/guide/$version repo/guide/latest

    # Add frontmatter for Jekyll
    find repo/guide/latest -name '*.html' | xargs sed -i '
1i\
---\
layout: guide\
---'

    git -C repo add guide/

    if git -C repo diff --staged --exit-code > /dev/null; then
        trace "Already uploaded documentation for $version"
        exit 0
    fi

    trace "Committing changes"
    git -C repo commit --message="Update guide to version $version"
    cd ..
}

commit()
(
    trace "Pushing changes to guide"
    git -C $WORKDIR/repo push origin master
    rm -rf $WORKDIR
)

while getopts "f:qvxz" opt; do
    case "$opt" in
    f)
        SOURCE="$OPTARG"
        ;;
    q)
        QUIET=1
        VERBOSE=0
        ;;
    v)
        QUIET=0
        VERBOSE=1
        ;;
    x)
        TRANSACTION=1
        ;;
    z)
        CHECK=1
        ;;
    -)
        break
        ;;
    *)
        usage
        ;;
    esac
done

shift $(expr $OPTIND - 1)

if [ $# -ne 2 ]; then
    usage
fi

if [ $VERBOSE -eq 1 ]; then
    set -x
fi

DIRECTORY="$1"
REPO="$2"

if [ -z "$SOURCE" ]; then
    message "no tarball source specified"
    exit 2
elif [ -d "$SOURCE" ]; then
    TARBALL="$(find $SOURCE -maxdepth 1 -name '*.tar.*' | sort | head -n1)"
elif [ -f "$SOURCE" ]; then
    TARBALL="$SOURCE"
else
    message "tarball source not found: $SOURCE"
    exit 1
fi

if [ $CHECK -eq 1 ]; then
    check
    exit 0
fi

prepare

if [ $TRANSACTION -eq 1 ]; then
    kill -STOP $$
fi

commit