3
from pathlib import Path
5
from pytest_caching_utils import (
15
def parse_args() -> argparse.Namespace:
16
parser = argparse.ArgumentParser(
17
description="Upload this job's the pytest cache to S3"
20
mode = parser.add_mutually_exclusive_group(required=True)
22
"--upload", action="store_true", help="Upload the pytest cache to S3"
27
help="Download the pytest cache from S3, merging it with any local cache",
33
help="Path to the folder pytest uses for its cache",
35
parser.add_argument("--pr_identifier", required=True, help="A unique PR identifier")
39
help="A unique job identifier that should be the same for all runs of job",
42
"--sha", required="--upload" in sys.argv, help="SHA of the commit"
45
"--test_config", required="--upload" in sys.argv, help="The test config"
48
"--shard", required="--upload" in sys.argv, help="The shard id"
54
help="The github repository we're running in, in the format 'owner/repo-name'",
57
"--temp_dir", required=False, help="Directory to store temp files"
60
"--bucket", required=False, help="The S3 bucket to upload the cache to"
63
args = parser.parse_args()
71
pr_identifier = PRIdentifier(args.pr_identifier)
72
print(f"PR identifier for `{args.pr_identifier}` is `{pr_identifier}`")
74
repo = GithubRepo.from_string(args.repo)
75
cache_dir = Path(args.cache_dir)
77
temp_dir = Path(args.temp_dir)
79
temp_dir = Path(TEMP_DIR)
82
print(f"Uploading cache with args {args}")
85
if not cache_dir.exists():
86
print(f"The pytest cache dir `{cache_dir}` does not exist. Skipping upload")
90
pr_identifier=pr_identifier,
92
job_identifier=args.job_identifier,
94
test_config=args.test_config,
102
print(f"Downloading cache with args {args}")
103
download_pytest_cache(
104
pr_identifier=pr_identifier,
106
job_identifier=args.job_identifier,
107
dest_cache_dir=cache_dir,
113
if __name__ == "__main__":