-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathfind_artifact.py
More file actions
53 lines (39 loc) · 1.42 KB
/
Copy pathfind_artifact.py
File metadata and controls
53 lines (39 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
"""Find a build artifact by glob pattern in a directory.
Usage:
find_artifact.py --build-dir DIR --pattern PATTERN
Outputs (GITHUB_OUTPUT):
path - Full path to the artifact
found - 'true' or 'false'
"""
from __future__ import annotations
import argparse
import os
from pathlib import Path
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--build-dir", type=Path, required=True)
parser.add_argument("--pattern", required=True, help="Glob pattern (e.g. '*.apk')")
args = parser.parse_args()
github_output = os.environ.get("GITHUB_OUTPUT")
def set_output(key: str, value: str) -> None:
if github_output:
with open(github_output, "a", encoding="utf-8") as f:
f.write(f"{key}={value}\n")
if not args.build_dir.is_dir():
print(f"::warning::Build directory does not exist: {args.build_dir}")
set_output("found", "false")
return 0
matches = list(args.build_dir.rglob(args.pattern))
files = [m for m in matches if m.is_file()]
if not files:
print(f"::warning::No artifact matching {args.pattern} found")
set_output("found", "false")
return 0
artifact = files[0]
print(f"Found artifact: {artifact}")
set_output("path", str(artifact))
set_output("found", "true")
return 0
if __name__ == "__main__":
raise SystemExit(main())