-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: sa-github-api <138766536+sa-github-api@users.noreply.github.com> Co-authored-by: Luka Skugor <luka.skugor@chimeramail.com>
- Loading branch information
1 parent
5aaa420
commit a8b273e
Showing
3 changed files
with
101 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"https://github.com/dfinity/ic.git": { | ||
"commit": "7dee90107a88b836fc72e78993913988f4f73ca2", | ||
"ref": "refs/heads/master" | ||
}, | ||
"https://github.com/dfinity/cdk-rs.git": { | ||
"commit": "59795716487fbb8a9910ac503bcea1e0cb08c932", | ||
"ref": "refs/heads/main" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import json | ||
import re | ||
import subprocess | ||
from pathlib import Path | ||
|
||
SKIP = [ | ||
r"Cargo.lock", | ||
r"Cargo.Bazel.lock", | ||
r"target/.*", | ||
r".*\.png$", | ||
r".*\.jpeg$", | ||
r".*\.md$", | ||
r".*\.ico$", | ||
r"\.git/.*", | ||
"release-index.yaml", | ||
"__pycache__/.*", | ||
"release-controller/test_reconciler.py", | ||
] | ||
|
||
SKIP_REGEX = [re.compile(f".*/{pattern}") for pattern in SKIP] | ||
|
||
|
||
def get_toplevel() -> str: | ||
return subprocess.run( | ||
["git", "rev-parse", "--show-toplevel"], capture_output=True, text=True, check=True | ||
).stdout.strip() | ||
|
||
|
||
def get_latest_commit(repo_url: str, ref: str) -> str: | ||
return ( | ||
subprocess.run(["git", "ls-remote", repo_url, ref], capture_output=True, text=True, check=True) | ||
.stdout.strip() | ||
.split()[0] | ||
) | ||
|
||
|
||
def get_files(top_level: str): | ||
path = Path(top_level) | ||
for file_path in path.rglob("**/*"): | ||
if file_path.is_file() and not any([bool(regex.fullmatch(str(file_path))) for regex in SKIP_REGEX]): | ||
yield file_path | ||
|
||
|
||
def update_files(top_level: str, to_update: list[(str, str)]): | ||
for file_path in get_files(top_level): | ||
try: | ||
with open(file_path, "r") as file: | ||
content = file.read() | ||
|
||
for from_commit, to_commit in to_update: | ||
content = content.replace(from_commit, to_commit) | ||
|
||
with open(file_path, "w") as file: | ||
file.write(content) | ||
except Exception as e: | ||
print(f"Error on path '{file_path}': {e}") | ||
pass | ||
|
||
|
||
def main(): | ||
top_level = get_toplevel() | ||
deps = json.load(open(f"{top_level}/ic-revisions.json")) | ||
to_update = [] | ||
|
||
for key in deps: | ||
dep = deps[key] | ||
print(f"Updating {key} from {dep['commit']} and ref {dep['ref']}") | ||
new_commit = get_latest_commit(key, dep["ref"]) | ||
if dep["commit"] == new_commit: | ||
print("Nothing new... skipping") | ||
continue | ||
|
||
print(f"Will update {key}: {dep['commit']} > {new_commit}") | ||
to_update.append((dep["commit"], new_commit)) | ||
dep["commit"] = new_commit | ||
|
||
print("Updating files") | ||
update_files(top_level, to_update) | ||
|
||
print("Updating revisions file") | ||
json.dump(deps, open(f"{top_level}/ic-revisions.json", mode="w"), indent=4) | ||
print("Done") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |