mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 07:04:18 +00:00
Sort versions in json output
This commit is contained in:
parent
96c2e62d57
commit
5e03d5bb06
2 changed files with 45 additions and 7 deletions
10
.github/deploy.sh
vendored
10
.github/deploy.sh
vendored
|
@ -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
42
util/versions.py
Executable 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()
|
Loading…
Reference in a new issue