Sort versions in json output

This commit is contained in:
flip1995 2020-02-13 17:29:40 +01:00
parent 96c2e62d57
commit 5e03d5bb06
No known key found for this signature in database
GPG key ID: 693086869D506637
2 changed files with 45 additions and 7 deletions

10
.github/deploy.sh vendored
View file

@ -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"

42
util/versions.py Executable file
View file

@ -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()