Skip to content

Commit c29c640

Browse files
committed
Use cgit atom feed to find devel commit
This avoids doing an expensive temporary checkout and lets us get to the answer much faster.
1 parent 7025dbf commit c29c640

File tree

2 files changed

+68
-10
lines changed

2 files changed

+68
-10
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.jq-template.awk
2+
.yq

Diff for: versions.sh

+67-10
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,78 @@ for version in "${versions[@]}"; do
4040
fi
4141

4242
if [ "$version" = 'devel' ]; then
43-
git clone --quiet --branch devel --depth 10 https://git.savannah.gnu.org/git/bash.git "$tmp/devel"
44-
snapshotDate="$(TZ=UTC date --date 'last monday 23:59:59' '+%Y-%m-%d %H:%M:%S %Z')" # https://github.com/docker-library/faq#can-i-use-a-bot-to-make-my-image-update-prs
45-
commit="$(git -C "$tmp/devel" log --before="$snapshotDate" --format='format:%H' --max-count=1)"
46-
if [ -z "$commit" ]; then
47-
echo >&2 "error: cannot determine commit for $version (from https://git.savannah.gnu.org/cgit/bash.git)"
43+
yq='./.yq'
44+
# https://github.com/mikefarah/yq/releases
45+
# TODO detect host architecture
46+
yqUrl='https://github.com/mikefarah/yq/releases/download/v4.44.5/yq_linux_amd64'
47+
yqSha256='638c4b251c49201fc94b598834b715f8f1c6e9b1854d2820772d2c79f0289002'
48+
if command -v yq &> /dev/null; then
49+
# TODO verify that the "yq" in PATH is https://github.com/mikefarah/yq, not the python-based version you'd get from "apt-get install yq" somehow? maybe they're compatible enough for our needs that it doesn't matter?
50+
yq='yq'
51+
elif [ ! -x "$yq" ] || ! sha256sum <<<"$yqSha256 *$yq" --quiet --strict --check; then
52+
wget -qO "$yq.new" "$yqUrl"
53+
sha256sum <<<"$yqSha256 *$yq.new" --quiet --strict --check
54+
chmod +x "$yq.new"
55+
"$yq.new" --version
56+
mv "$yq.new" "$yq"
57+
fi
58+
59+
# https://github.com/docker-library/faq#can-i-use-a-bot-to-make-my-image-update-prs
60+
snapshotDate="$(date --utc --date 'last monday 23:59:59' '+%s')"
61+
commit='devel' # this is also our iteration variable, so if we don't find a suitable commit each time through this loop, we'll use the last commit of the previous list to get a list of new (older) commits until we find one suitably old enough
62+
fullVersion=
63+
while [ -z "$fullVersion" ]; do
64+
commits="$(
65+
wget -qO- "https://git.savannah.gnu.org/cgit/bash.git/atom/?h=$commit" \
66+
| "$yq" --input-format xml --output-format json \
67+
| jq -r '
68+
.feed.entry[]
69+
| select(
70+
(.id | startswith("urn:sha1:"))
71+
and .updated // .published
72+
and .title
73+
)
74+
| [
75+
@sh "commit=\(.id | ltrimstr("urn:sha1:"))",
76+
@sh "date=\([ .updated, .published ] | sort | reverse[0])",
77+
@sh "desc=\(.title)",
78+
empty
79+
]
80+
| join("\n")
81+
| @sh
82+
'
83+
)"
84+
eval "commits=( $commits )"
85+
if [ "${#commits[@]}" -eq 0 ]; then
86+
echo >&2 "error: got no commits when listing history from $commit"
87+
exit 1
88+
fi
89+
for commitShell in "${commits[@]}"; do
90+
unset commit date desc
91+
eval "$commitShell"
92+
[ -n "$commit" ]
93+
[ -n "$date" ]
94+
[ -n "$desc" ]
95+
date="$(date --utc --date "$date" '+%s')"
96+
if [ "$date" -le "$snapshotDate" ]; then
97+
fullVersion="$commit"
98+
break 2
99+
fi
100+
done
101+
done
102+
if [ -z "$fullVersion" ]; then
103+
snapshotDateStr="$(date --utc --date "@$snapshotDate" '+%Y-%m-%d %H:%M:%S %Z')"
104+
echo >&2 "error: cannot find full version for $version (maybe too many commits since $snapshotDateStr? cgit changed the atom feed format? yq changed how it parses XML?)"
48105
exit 1
49106
fi
50-
desc="$(git -C "$tmp/devel" log --max-count=1 --format='format:%s' "$commit")"
107+
[ "$commit" = "$fullVersion" ]
108+
[ -n "$date" ]
51109
[ -n "$desc" ]
110+
52111
if timestamp="$(sed -rne '/.*[[:space:]]+bash-([0-9]+)[[:space:]]+.*/s//\1/p' <<<"$desc")" && [ -n "$timestamp" ]; then
53-
: # "commit bash-20210305 snapshot"
112+
: # "commit bash-20210305 snapshot" (https://git.savannah.gnu.org/cgit/bash.git/commit/?h=devel&id=11bf534f3628cc0a592866ee4f689beca473f548)
54113
else
55-
timestamp="$(git -C "$tmp/devel" log --max-count=1 --format='format:%aI' "$commit")" # ideally we'd use "%as" and just axe "-" but that requires newer Git than Debian 10 has /o\
56-
timestamp="${timestamp%%T*}"
57-
timestamp="${timestamp//-/}"
114+
timestamp="$(date --utc --date "@$date" '+%Y%m%d')"
58115
fi
59116

60117
echo "$version: $commit ($timestamp -- $desc)"

0 commit comments

Comments
 (0)