forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_ref.py
More file actions
executable file
·30 lines (23 loc) · 776 Bytes
/
Copy pathparse_ref.py
File metadata and controls
executable file
·30 lines (23 loc) · 776 Bytes
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
#!/usr/bin/env python3
import os
import re
def set_output(name: str, val: str) -> None:
print(f"Setting output {name}={val}")
if os.getenv("GITHUB_OUTPUT"):
with open(str(os.getenv("GITHUB_OUTPUT")), "a") as env:
print(f"{name}={val}", file=env)
else:
print(f"::set-output name={name}::{val}")
def main() -> None:
ref = os.environ["GITHUB_REF"]
m = re.match(r"^refs/(\w+)/(.*)$", ref)
if m:
category, stripped = m.groups()
if category == "heads":
set_output("branch", stripped)
elif category == "pull":
set_output("branch", "pull/" + stripped.split("/")[0])
elif category == "tags":
set_output("tag", stripped)
if __name__ == "__main__":
main()