summaryrefslogtreecommitdiff
path: root/docs/support-matrix-generate
blob: 8a27849cf6a4289f7d53acf6db1a833b227b78ef (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
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
#!/bin/bash

# usage:
#   cd xen.git
#   docs/support-matrix-generate [-D]                               \
#       refs/remotes/origin/master                                  \
#           https://xenbits.xen.org/docs/unstable/SUPPORT.html      \
#       refs/remotes/origin/stable-NN                               \
#           https://xenbits.xen.org/docs/NN-testing/SUPPORT.html    \
#
# NN is a *literal* in the above rune!  It will be substituted with
# the appropriate version number.
#
# The idea is that we use staging's version of this script, and it
# looks into the git history and various git remote tracking refs to
# find the various versions of SUPPORT.md.
#
# The arguments specify the git refs to look in, and also the URLs for
# the SUPPORT.html (which are needed so that we can make
# cross-reference links).  We provide the ref and url (i) for unstable
# (ii) in template form for all previous versions.

# Algorithm:
#
# We start with `refs/remotes/origin/master' and process its
# SUPPORT.md into json.
#
# Then we try to find the next previous revision.  This is done by
# extracting the current version number from xen/Makefile.  (We make
# some slight assumption about how xen/Makefile's variables are
# written, because we want to be able to do this without checking out
# the whole tree for the version in question.)  Then we use git log on
# xen/Makefile to try to find a commit where the version changed.
# This gives us the previous version number, NN.
#
# That is substituted into the `refs/remotes/origin/stable-NN'
# argument to get the tip of the relevant branch.  That in turns
# contains another SUPPORT.md.  We keep going until either the ref
# itself is missing, or we get to a ref with no SUPPORT.md.

set -e
set -o posix
set -o pipefail

fail () { echo >&2 "$0: $1"; exit 12; }

args=()

case "$1" in
    -D) args+=("$1"); shift ;;
    -*) fail 'bad usage' ;;
    --) shift; break ;;
esac

case "$#" in
    4) ;;
    *) fail 'bad usage' ;;
esac

current_ref=$1
current_url=$2
pattern_ref=$3
pattern_url=$4

tmp_prefix="docs/tmp.support-matrix"
tmp_mdfile="$tmp_prefix.md"
tmp_revisions="$tmp_prefix.revisions.html"

versionfile=xen/Makefile
tmp_versionfile="$tmp_prefix.xen.make"

cat docs/misc/support-matrix-head.html

debug () {
    echo "<!-- $* -->"
}

select_commitish () {
    commitish=$1
    debug "select_commitish $commitish"
    obj="$(printf "%s:SUPPORT.md" "$commitish")"
    exists="$(printf "%s" "$obj" | git cat-file --batch-check)"
    >"$tmp_mdfile"
    case "$exists" in
        *' missing')
            rm "$tmp_mdfile"
            ;;
        *' blob '*)
            git cat-file blob "$obj" >"$tmp_mdfile"
            ;;
        *) fail "?? $current_url $exists ?";;
    esac
}

commitish_version () {
    case "$commitish" in
        refs/*)
            # this is how to find out if a ref exists
            local gfer=$(git for-each-ref "[r]${commitish#r}")
            if [ "x$gfer" = x ]; then return; fi
            ;;
    esac

    git cat-file blob "$commitish:$versionfile" >"$tmp_versionfile"

    local maj=$(sed -n 's/.*XEN_VERSION.*= \([0-9]\+\)/\1/p' < "$tmp_versionfile")
    local min=$(sed -n 's/.*XEN_SUBVERSION.*= \([0-9]\+\)/\1/p' < "$tmp_versionfile")

    if [ -z $maj ] || [ -z $min ];
    then
        fail "Unable to identify Xen version for $commitish";
    fi

    printf "%d.%d\n" "$maj" "$min"
}

exec 4>"$tmp_revisions"

while true; do
    select_commitish "$current_ref"
    current_version=$(commitish_version)
    debug "current_version=$current_version"

    if ! [ -e "$tmp_mdfile" ]; then break; fi

    cat >&4 <<END
<tr>
<td align="center">$current_version</td>
END
    git >&4 log -n1 --pretty=tformat:'
<td><code>%ci</code></td>
<td><code>%H</code></td>
' "$current_ref"
    cat >&4 <<END
</tr>
END

    current_jsonfile="$tmp_prefix.$current_version.json"
    pandoc -t json <"$tmp_mdfile" >"$current_jsonfile"

    args+=("$current_jsonfile" "$current_url")

    # find previous version
    search_commit="$current_ref"
    while true; do
        search_commit=$(git log --pretty=format:%H -n1 \
                        -G 'XEN.*VERSION' $search_commit -- $versionfile)
        if ! [ "$search_commit" ]; then search_version=''; break; fi

        search_commit="$search_commit~"
        select_commitish "$search_commit"
        search_version=$(commitish_version)
        debug "search_version=$search_version"
        if [ "x$search_version" != "x$current_version" ]; then break; fi
    done

    if [ "x$search_version" = x ]; then break; fi

    # have found the previous version
    current_ref=${pattern_ref/NN/$search_version}
    current_url=${pattern_url/NN/$search_version}
done

debug "${args[*]}"
docs/parse-support-md "${args[@]}"

cat <<END
    <h2>Source materials</h2>
      Generated from xen.git
      by docs/support-matrix-generate and docs/parse-support-md.
      <p>
      Input revisions of SUPPORT.md used:
    <table>
    <tr>
      <th>Version</th>
      <th align="left">Commit date</th>
      <th align="left">Git commit</th>
END

cat "$tmp_revisions"

generated=$(TZ=UTC date --iso-8601=minutes)

cat <<END
    </table>
    <p>
    Last checked/updated/regenerated: ${generated/T/ }
  </body>
</html>
END