diff --git a/ftl/sync.py b/ftl/sync.py index f929ce9354e..0696d99f636 100644 --- a/ftl/sync.py +++ b/ftl/sync.py @@ -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("git@github.com:", "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() diff --git a/repos.bzl b/repos.bzl index b10f34a1ac7..a4ebd492da7 100644 --- a/repos.bzl +++ b/repos.bzl @@ -131,11 +131,13 @@ def register_repos(): # translations ################ + core_i18n_repo = "anki-core-i18n" core_i18n_commit = "b1c03cebb554e8568529e293756ac36cdf62341a" - core_i18n_shallow_since = "1608607833 +1000" + core_i18n_zip_csum = "ce9c846e6985af9bda2d51390df4dd8a65e91ce9f8f217a0ef46565271303e43" - qtftl_i18n_commit = "e7dda1058c0510665f2ea8d8ffd74e506e578f7a" - qtftl_i18n_shallow_since = "1608607833 +1000" + qtftl_i18n_repo = "anki-desktop-ftl" + qtftl_i18n_commit = "e8fa8cb9a9a5eb4d6f9b4c14111aa2c48ac62cc9" + qtftl_i18n_zip_csum = "557b7ae01324e38d23009805c7bef87d32413682a8bb68726df8724fbb9424c7" i18n_build_content = """ filegroup( @@ -147,19 +149,29 @@ exports_files(["l10n.toml"]) """ maybe( - new_git_repository, + http_archive, name = "rslib_ftl", build_file_content = i18n_build_content, - commit = core_i18n_commit, - shallow_since = core_i18n_shallow_since, - remote = "https://github.com/ankitects/anki-core-i18n", + strip_prefix = core_i18n_repo + "-" + core_i18n_commit, + urls = [ + "https://github.com/ankitects/{}/archive/{}.zip".format( + core_i18n_repo, + core_i18n_commit, + ), + ], + sha256 = core_i18n_zip_csum, ) maybe( - new_git_repository, + http_archive, name = "extra_ftl", build_file_content = i18n_build_content, - commit = qtftl_i18n_commit, - shallow_since = qtftl_i18n_shallow_since, - remote = "https://github.com/ankitects/anki-desktop-ftl", + strip_prefix = qtftl_i18n_repo + "-" + qtftl_i18n_commit, + urls = [ + "https://github.com/ankitects/{}/archive/{}.zip".format( + qtftl_i18n_repo, + qtftl_i18n_commit, + ), + ], + sha256 = qtftl_i18n_zip_csum, )