Skip to content

Instantly share code, notes, and snippets.

@lilinghai
Last active June 29, 2020 11:44
Show Gist options
  • Save lilinghai/5ffd4f76f5670627dffeee4181a0ba83 to your computer and use it in GitHub Desktop.
Save lilinghai/5ffd4f76f5670627dffeee4181a0ba83 to your computer and use it in GitHub Desktop.
com-check.py
# -*- coding:utf-8 -*-
# lib
# google.golang.org/grpc
# github.com/pingcap/kvproto
# github.com/pingcap/tipb
# github.com/pingcap/parser
# repo
# tidb pd tikv tidb-binlog tidb-lightning ticdc br dm
# dm 版本没有跟随 tidb 的版本变化
# tiflash 需要下载仓库的 .git 目录,解析出以来的 submodule
# file
# Cargo.lock go.sum last find parse
import urllib.request
import urllib.error
import ssl
import semver
import toml
import sys
import os
def prepare_tiflash(version):
os.popen("rm -rf .tics").read()
res = os.popen("git clone --no-checkout --branch {} git@github.com:pingcap/tics.git .tics".format(version)).read()
if res.find("not found") != -1:
return False
os.chdir('.tics')
return True
def done_tiflash():
os.popen("rm -rf ../.tics").read()
def parse_dep_version(repo, version, dep, has_tiflash):
if repo == "tiflash":
if not has_tiflash:
return "None"
commit = os.popen("git ls-tree {} contrib/{}".format(version, dep.split('/')[-1])).read()
if commit == "":
return "None"
else:
return commit.split(" ")[2][0:12]
lock_file = "go.sum"
mod_file = "go.mod"
if repo == "tikv":
lock_file = "Cargo.lock"
lock_endpoint = "https://raw.githubusercontent.com/pingcap/{}/{}/{}".format(repo, version, lock_file)
data = ""
mod_endpoint = "https://raw.githubusercontent.com/pingcap/{}/{}/{}".format(repo, version, mod_file)
try:
data = urllib.request.urlopen(lock_endpoint,
context=ssl.SSLContext()).read().decode('utf-8')
except urllib.error.HTTPError as e:
if e.code == 404:
return "None"
if repo == "tikv":
parsed = toml.loads(data)
for package in parsed["package"]:
if package["name"] == dep.split('/')[-1]:
return package["source"].split('#')[1][0:12]
return "None"
data2 = ""
try:
data2 = urllib.request.urlopen(mod_endpoint, context=ssl.SSLContext()).read().decode('utf-8')
except urllib.error.HTTPError as e:
if e.code == 404:
return "None"
lines2 = data2.split('\n')
flag = False
for line in lines2:
if line.find(dep) != -1:
flag = True
if not flag:
return "None"
lines = data.split('\n')
match = ""
for line in lines:
if line.find(dep) != -1:
match = line
if match == "":
return "None"
sv = match.split(' ')[1].split('/')[0]
ver = semver.VersionInfo.parse(sv[1:])
if ver.major == 0:
return sv.split('-')[2]
else:
return sv
# python com-check.py release-4.0
if __name__ == "__main__":
repos = ["tidb", "pd", "tikv", "br", "ticdc", "tidb-binlog", "tidb-lightning", "tiflash"]
deps = [
"google.golang.org/grpc",
"github.com/pingcap/kvproto",
"github.com/pingcap/tipb",
"github.com/pingcap/parser",
]
version = sys.argv[1]
has_tiflash = prepare_tiflash(version)
print(repos)
for dep in deps:
line = dep + '\t'
for repo in repos:
res = parse_dep_version(repo, version, dep, has_tiflash)
line += res + '\t'
print(line)
done_tiflash()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment