From 5e03d5bb067db8ea03e0bb75471fe40daf64f55b Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 13 Feb 2020 17:29:40 +0100 Subject: [PATCH 1/4] Sort versions in json output --- .github/deploy.sh | 10 +++------- util/versions.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) create mode 100755 util/versions.py diff --git a/.github/deploy.sh b/.github/deploy.sh index 4fcff830a..59a7cdae8 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 000000000..2c9bb5fe4 --- /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() From 2044931cbe2ad7229eebd6cc044a73ad3dd244af Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 13 Feb 2020 17:32:29 +0100 Subject: [PATCH 2/4] Better version ordering of documentation --- util/gh-pages/versions.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/util/gh-pages/versions.html b/util/gh-pages/versions.html index 391e22a47..a1d385c96 100644 --- a/util/gh-pages/versions.html +++ b/util/gh-pages/versions.html @@ -36,7 +36,7 @@ @@ -54,10 +54,14 @@ .controller('docVersions', function ($scope, $http) { $scope.loading = true; - $scope.normalizeVersion = function(v) { + $scope.normalizeVersionDisplay = function(v) { return v.replace(/^v/, ''); }; + $scope.normalizeVersion = function(v) { + return v.replace(/^v/, '').replace(/^rust-/, ''); + }; + $scope.versionOrder = function(v) { if (v === 'master') { return Infinity; } if (v === 'current') { return Number.MAX_VALUE; } From 0533cff125d89e15bfda0a265ef01b1b33d8cd95 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 13 Feb 2020 18:07:56 +0100 Subject: [PATCH 3/4] Use python3 instead of python This changes the formatting a bit of json.dump(..) --- .github/deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/deploy.sh b/.github/deploy.sh index 59a7cdae8..8007bc75c 100644 --- a/.github/deploy.sh +++ b/.github/deploy.sh @@ -8,7 +8,7 @@ rm -rf out/master/ || exit 0 echo "Making the docs for master" mkdir out/master/ cp util/gh-pages/index.html out/master -python ./util/export.py out/master/lints.json +python3 ./util/export.py out/master/lints.json if [[ -n $TAG_NAME ]]; then echo "Save the doc for the current tag ($TAG_NAME) and point current/ to it" @@ -21,7 +21,7 @@ fi cp util/gh-pages/versions.html out/index.html echo "Making the versions.json file" -python ./util/versions.py out +python3 ./util/versions.py out cd out # Now let's go have some fun with the cloned repo From 0f7918266fa4f4a50237c8bdac79cb1e3001d86c Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 14 Feb 2020 12:03:48 +0100 Subject: [PATCH 4/4] Rename current -> stable --- .github/deploy.sh | 6 +++--- util/gh-pages/versions.html | 2 +- util/versions.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/deploy.sh b/.github/deploy.sh index 8007bc75c..b1f572d2b 100644 --- a/.github/deploy.sh +++ b/.github/deploy.sh @@ -11,10 +11,10 @@ cp util/gh-pages/index.html out/master python3 ./util/export.py out/master/lints.json if [[ -n $TAG_NAME ]]; then - echo "Save the doc for the current tag ($TAG_NAME) and point current/ to it" + echo "Save the doc for the current tag ($TAG_NAME) and point stable/ to it" cp -r out/master "out/$TAG_NAME" - rm -f out/current - ln -s "$TAG_NAME" out/current + rm -f out/stable + ln -s "$TAG_NAME" out/stable fi # Generate version index that is shown as root index page diff --git a/util/gh-pages/versions.html b/util/gh-pages/versions.html index a1d385c96..cd3611db3 100644 --- a/util/gh-pages/versions.html +++ b/util/gh-pages/versions.html @@ -64,7 +64,7 @@ $scope.versionOrder = function(v) { if (v === 'master') { return Infinity; } - if (v === 'current') { return Number.MAX_VALUE; } + if (v === 'stable') { return Number.MAX_VALUE; } return $scope.normalizeVersion(v) .split('.') diff --git a/util/versions.py b/util/versions.py index 2c9bb5fe4..5798761ad 100755 --- a/util/versions.py +++ b/util/versions.py @@ -10,7 +10,7 @@ from lintlib import log def key(v): if v == 'master': return float('inf') - if v == 'current': + if v == 'stable': return sys.maxsize v = v.replace('v', '').replace('rust-', '')