|
| 1 | +import functools |
| 2 | +import json |
| 3 | +import re |
| 4 | +import semver |
| 5 | +import subprocess as sp |
| 6 | + |
| 7 | +def exec(*argv): |
| 8 | + res = sp.run(argv, capture_output=True) |
| 9 | + if not res.returncode == 0: |
| 10 | + print('Error running', argv) |
| 11 | + print('StdOut:\n', res.stdout) |
| 12 | + print('StdErr:\n', res.stderr) |
| 13 | + raise Exception('Failed to exec ' + " ".join(argv)) |
| 14 | + return res |
| 15 | + |
| 16 | + |
| 17 | +def runHugo(outSuffix=""): |
| 18 | + return exec( |
| 19 | + "hugo", |
| 20 | + "--destination=public/" + outSuffix, |
| 21 | + "--baseURL", |
| 22 | + "https://tour.dgraph.io/" + outSuffix, |
| 23 | + "--config", |
| 24 | + "config.toml,releases.toml", |
| 25 | + ) |
| 26 | + |
| 27 | + |
| 28 | +def getReleases(): |
| 29 | + gitBranches = exec("git", "branch") |
| 30 | + branches = gitBranches.stdout.decode('utf8') |
| 31 | + branches = branches.split('\n') |
| 32 | + res = [] |
| 33 | + for b in branches: |
| 34 | + match = re.compile(r"[ *]+dgraph-([0-9.]+)").match(b) |
| 35 | + if match: |
| 36 | + res.append(match.group(1)) |
| 37 | + print('Found release versions', res) |
| 38 | + |
| 39 | + res.sort(key=functools.cmp_to_key(semver.compare), reverse=True) |
| 40 | + |
| 41 | + res = ["master"] + res |
| 42 | + print('Order on the webpage: ', res) |
| 43 | + return res |
| 44 | + |
| 45 | +def buildBranch(branch, dest, jsonData): |
| 46 | + print("Building", branch, "to public/" + dest) |
| 47 | + res = exec("git", "checkout", branch) |
| 48 | + |
| 49 | + with open('releases.json', 'w') as f: |
| 50 | + f.write(json.dumps(jsonData)) |
| 51 | + |
| 52 | + runHugo(dest) |
| 53 | + |
| 54 | +def buildAll(releases): |
| 55 | + latestRelease = releases[1] |
| 56 | + print('Latest Release (recommended to users): ', latestRelease) |
| 57 | + |
| 58 | + def jsonFor(version, latestRelease, releases): |
| 59 | + return { |
| 60 | + "latestRelease": latestRelease, |
| 61 | + "tourReleases": releases, |
| 62 | + "thisRelease": version, |
| 63 | + } |
| 64 | + |
| 65 | + buildBranch( |
| 66 | + "dgraph-" + latestRelease, |
| 67 | + "", |
| 68 | + jsonFor(latestRelease, latestRelease, releases)) |
| 69 | + |
| 70 | + for r in releases: |
| 71 | + path = r if r == "master" else "dgraph-" + r |
| 72 | + buildBranch(path, path, jsonFor(r, latestRelease, releases)) |
| 73 | + |
| 74 | + |
| 75 | +def main(): |
| 76 | + releases = getReleases() |
| 77 | + buildAll(releases) |
| 78 | + |
| 79 | + exec("git", "checkout", "master") |
| 80 | + |
| 81 | +main() |
0 commit comments