Skip to content

Commit 1ae340d

Browse files
committed
Improve snapshot deployment timestamp detection
This hopefully fixes an issue where the status table was erroneously categorizing many components as "Cut" even though nothing changed. Previously, we looked in G/A/maven-metadata.xml at the <versioning><lastUpdated> tag value. However, that tag value is sometimes updated even when no new snapshot has been deployed. I am not certain why -- perhaps certain Nexus scheduled tasks touch this value after refreshing indices, etc.? For example, as of this writing, net.imagej:ij1-patcher's newest snapshot (1.0.2-SNAPSHOT) was deployed at 20190930134831, but the lastUpdate tag of G/A/maven-metadata.xml is 20191006010052. The new detection strategy is a two-step process: 1. Extract the latest snapshot version from <versioning><latest> of G/A/maven-metadata.xml. 2. Extract its timestamp from <versioning><snapshot><timestamp> of G/A/V/maven-metadata.xml. Other strategies considered but discarded: - Use the Last-Updated value of G/A/maven-metadata.xml. When browsing the remote directory listing, the value appears correct. But `curl -I` on the file yields a too-recent value. - Use the Last-Updated value of G/A/V/maven-metadata.xml. This might work -- both the remote directory listing and `curl -I` request yields the correct value -- but it feels more ironclad to me to rely on file _contents_ here rather than file metadata.
1 parent 2106118 commit 1ae340d

File tree

1 file changed

+40
-26
lines changed

1 file changed

+40
-26
lines changed

version-timestamps.sh

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# For each G:A:V argument passed to the script,
1212
# there is one line of output, formatted as follows:
1313
#
14-
# G:A:V releaseTimestamp lastUpdated
14+
# G:A:V releaseTimestamp lastDeployed
1515

1616
# --------------------------------------------------------------
1717
# Set the M2_REPO_PATH variable to the desired Maven repository.
@@ -24,14 +24,15 @@ test "$M2_REPO_PATH" && repo=$M2_REPO_PATH ||
2424
processGAV() {
2525
debug processGAV $@
2626
g=$1; a=$2; v=$3
27-
versionTimestamp=$(versionTimestamp "$g" "$a" "$v")
28-
lastUpdated=$(lastUpdated "$g" "$a" "$v")
29-
echo "$g:$a:$v $versionTimestamp $lastUpdated"
27+
releaseTimestamp=$(releaseTimestamp "$g" "$a" "$v")
28+
newestSnapshot=$(newestSnapshot "$g" "$a")
29+
lastDeployed=$(snapshotTimestamp "$g" "$a" "$newestSnapshot")
30+
echo "$g:$a:$v $releaseTimestamp $lastDeployed"
3031
}
3132

32-
# Given a GAV, discerns when it was deployed.
33-
versionTimestamp() {
34-
debug versionTimestamp $@
33+
# Given a release GAV, discerns when it was deployed.
34+
releaseTimestamp() {
35+
debug releaseTimestamp $@
3536
g=$1; a=$2; v=$3
3637
case "$repo" in
3738
/*) # LOCAL
@@ -49,9 +50,9 @@ versionTimestamp() {
4950
*) # REMOTE
5051
# Query the POM's HTTP header for the last modified time.
5152
url="$repo/$(gpath "$g")/$a/$v/$a-$v.pom"
52-
debug "versionTimestamp: url -> $url"
53+
debug "releaseTimestamp: url -> $url"
5354
modified=$(curl -Ifs "$url" | grep '^Last-Modified' | sed 's/^[^ ]* //')
54-
debug "versionTimestamp: modified -> $modified"
55+
debug "releaseTimestamp: modified -> $modified"
5556
test "$modified" &&
5657
formatTimestamp "$modified" ||
5758
# Invalid URL; probably no such release.
@@ -60,37 +61,50 @@ versionTimestamp() {
6061
esac
6162
}
6263

63-
# Given a GA, discerns when the latest version was deployed.
64-
# This is probably, but not necessarily, the timestamp
65-
# corresponding to the most recently deployed SNAPSHOT.
66-
lastUpdated() {
67-
debug lastUpdated $@
68-
g=$1; a=$2
64+
# Given a GA, discerns the newest snapshot version.
65+
newestSnapshot() {
66+
debug newestSnapshot $@
67+
# Extract <versioning><latest> value.
68+
extractTag latest $@
69+
}
70+
71+
# Given a GAV, discerns when that snapshot was last deployed.
72+
snapshotTimestamp() {
73+
debug snapshotTimestamp $@
74+
g=$1; a=$2; v=$3
75+
# Extract <versioning><snapshot><timestamp> value.
76+
extractTag timestamp "$g" "$a/$v" | tr -d '.'
77+
}
78+
79+
# Given a GA(V), extracts an XML tag from local or remote maven-metadata.xml.
80+
extractTag() {
81+
debug extractTag $@
82+
tag=$1; g=$2; av=$3
6983
case "$repo" in
7084
/*) # LOCAL
71-
# Extract versioning/lastUpdated from each maven-metadata.xml.
85+
# Extract tag value from each maven-metadata.xml.
7286
# Then sort and take the last entry as newest.
73-
for f in "$repo"/*/"$(gpath "$g")/$a/maven-metadata.xml"
87+
for f in "$repo"/*/"$(gpath "$g")/$av/maven-metadata.xml"
7488
do
75-
cat "$f" | tagValue lastUpdated
89+
cat "$f" | tagValue "$tag"
7690
done | sort | tail -n1
7791
;;
7892
*) # REMOTE
79-
# Extract versioning/lastUpdated from the remote metadata.
80-
metadata=$(downloadMetadata "$g" "$a")
81-
lastUpdated=$(echo "$metadata" | tagValue lastUpdated)
82-
debug "lastUpdated: lastUpdated -> $lastUpdated"
83-
test "$lastUpdated" || die 1 "No lastUpdated tag in metadata:\n$metadata"
84-
echo "$lastUpdated"
93+
# Extract versioning/latest from the remote metadata.
94+
metadata=$(downloadMetadata "$g" "$av")
95+
tagValue=$(echo "$metadata" | tagValue "$tag")
96+
debug "newestSnapshot: $tag -> $tagValue"
97+
test "$tagValue" || die 1 "No $tag tag in metadata:\n$metadata"
98+
echo "$tagValue"
8599
;;
86100
esac
87101
}
88102

89103
# Downloads maven-metadata.xml from the remote repository as needed.
90104
downloadMetadata() {
91105
debug downloadMetadata $@
92-
g=$1; a=$2
93-
url="$repo/$(gpath "$g")/$a/maven-metadata.xml"
106+
g=$1; av=$2
107+
url="$repo/$(gpath "$g")/$av/maven-metadata.xml"
94108
test "$cachedMetadata" || cachedMetadata=$(curl -fs "$url")
95109
test "$cachedMetadata" || die 2 "Cannot access metadata remotely from: $url"
96110
debug "downloadMetadata: cachedMetadata ->\n$cachedMetadata"

0 commit comments

Comments
 (0)