about summary refs log tree commit diff
diff options
context:
space:
mode:
authorflip1995 <hello@philkrones.com>2020-02-13 17:29:40 +0100
committerflip1995 <hello@philkrones.com>2020-02-13 17:59:37 +0100
commit5e03d5bb067db8ea03e0bb75471fe40daf64f55b (patch)
treec467db065e8ddffc5566b7eacf37fb61c45fd740
parent96c2e62d5700a811f479d984cf57ffc0675ab44a (diff)
downloadrust-5e03d5bb067db8ea03e0bb75471fe40daf64f55b.tar.gz
rust-5e03d5bb067db8ea03e0bb75471fe40daf64f55b.zip
Sort versions in json output
-rw-r--r--.github/deploy.sh10
-rwxr-xr-xutil/versions.py42
2 files changed, 45 insertions, 7 deletions
diff --git a/.github/deploy.sh b/.github/deploy.sh
index 4fcff830aa6..59a7cdae866 100644
--- a/.github/deploy.sh
+++ b/.github/deploy.sh
@@ -20,14 +20,10 @@ fi
 # Generate version index that is shown as root index page
 cp util/gh-pages/versions.html out/index.html
 
-cd out
-cat <<-EOF | python - > versions.json
-import os, json
-print json.dumps([
-    dir for dir in os.listdir(".") if not dir.startswith(".") and os.path.isdir(dir)
-])
-EOF
+echo "Making the versions.json file"
+python ./util/versions.py out
 
+cd out
 # Now let's go have some fun with the cloned repo
 git config user.name "GHA CI"
 git config user.email "gha@ci.invalid"
diff --git a/util/versions.py b/util/versions.py
new file mode 100755
index 00000000000..2c9bb5fe40a
--- /dev/null
+++ b/util/versions.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+
+import json
+import os
+import sys
+
+from lintlib import log
+
+
+def key(v):
+    if v == 'master':
+        return float('inf')
+    if v == 'current':
+        return sys.maxsize
+
+    v = v.replace('v', '').replace('rust-', '')
+
+    s = 0
+    for i, val in enumerate(v.split('.')[::-1]):
+        s += int(val) * 100**i
+
+    return s
+
+
+def main():
+    if len(sys.argv) < 2:
+        print("Error: specify output directory")
+        return
+
+    outdir = sys.argv[1]
+    versions = [
+        dir for dir in os.listdir(outdir) if not dir.startswith(".") and os.path.isdir(os.path.join(outdir, dir))
+    ]
+    versions.sort(key=key)
+
+    with open(os.path.join(outdir, "versions.json"), "w") as fp:
+        json.dump(versions, fp, indent=2)
+        log.info("wrote JSON for great justice")
+
+
+if __name__ == "__main__":
+    main()