pytorch/.github/scripts/parse_ref.py
Nikita Shulga dbccccb7a2 [BE] Get rid of deprecation warnings in workflows (take 3) (#87152)
- Per [deprecation announcement](https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/) replace `echo "::set-output name="` with echo to `${GITHUB_OUTPUT}` as shown in following [example](https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs#example-defining-outputs-for-a-job)
- Update `actions/setup-python` from `v2` to `v4` to get rid of deprecated node version warning
- Update `actions/checkout-python` from `v2` to `v3` (and `silent-checkout` branch as well)
- Update `retry` action to 3e91a01664
Pull Request resolved: https://github.com/pytorch/pytorch/pull/87152
Approved by: https://github.com/kit1980, https://github.com/izaitsevfb
2022-10-18 13:53:30 +00:00

30 lines
734 B
Python
Executable File

#!/usr/bin/env python3
import os
import re
def set_output(name: str, val: str) -> None:
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()