-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update translations; use http_archive
- Loading branch information
Showing
2 changed files
with
47 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
import os | ||
import sys | ||
from typing import Optional, Tuple | ||
import requests | ||
from hashlib import sha256 | ||
|
||
root = os.environ["BUILD_WORKSPACE_DIRECTORY"] | ||
repos_bzl = os.path.join(root, "repos.bzl") | ||
|
@@ -64,18 +66,32 @@ def update_git_repos(): | |
@dataclass | ||
class GitInfo: | ||
sha1: str | ||
shallow_since: str | ||
zip_sha256: str | ||
|
||
|
||
def git_url_to_zip_url(repo: str, commit: str) -> str: | ||
repo = repo.replace("[email protected]:", "https://github.com/") | ||
return f"{repo}/archive/{commit}.zip" | ||
|
||
|
||
def get_zip_sha(zip_url: str) -> str: | ||
resp = requests.get(zip_url) | ||
resp.raise_for_status() | ||
return sha256(resp.content).hexdigest() | ||
|
||
|
||
def module_git_info(module: Module) -> GitInfo: | ||
folder = module.folder() | ||
sha = subprocess.check_output( | ||
sha1 = subprocess.check_output( | ||
["git", "log", "-n", "1", "--pretty=format:%H"], cwd=folder | ||
).decode("utf8") | ||
zip_url = git_url_to_zip_url(module.repo, sha1) | ||
zip_sha = get_zip_sha(zip_url) | ||
|
||
return GitInfo( | ||
sha1=sha1, | ||
zip_sha256=zip_sha, | ||
) | ||
shallow = subprocess.check_output( | ||
["git", "log", "-n", "1", "--pretty=format:%cd", "--date=raw"], cwd=folder | ||
) | ||
return GitInfo(sha1=sha.decode("utf8"), shallow_since=shallow.decode("utf8")) | ||
|
||
|
||
def update_repos_bzl(): | ||
|
@@ -85,12 +101,12 @@ def update_repos_bzl(): | |
git = module_git_info(module) | ||
prefix = f"{module.name}_i18n_" | ||
entries[prefix + "commit"] = git.sha1 | ||
entries[prefix + "shallow_since"] = git.shallow_since | ||
entries[prefix + "zip_csum"] = git.zip_sha256 | ||
|
||
# apply | ||
out = [] | ||
path = repos_bzl | ||
reg = re.compile(r'(\s+)(\S+_(?:commit|shallow_since)) = "(.*)"') | ||
reg = re.compile(r'(\s+)(\S+_(?:commit|zip_csum)) = "(.*)"') | ||
for line in open(path).readlines(): | ||
if m := reg.match(line): | ||
(indent, key, _oldvalue) = m.groups() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters