forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into mvafin/pt_fe/perf_refactor
- Loading branch information
Showing
837 changed files
with
34,744 additions
and
9,944 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import logging | ||
import os | ||
|
||
|
||
def init_logger(): | ||
logging.basicConfig(level=logging.DEBUG, | ||
format='%(asctime)s %(name)-15s %(levelname)-8s %(message)s', | ||
datefmt='%m-%d-%Y %H:%M:%S') | ||
|
||
|
||
def set_github_output(name: str, value: str, github_output_var_name: str = 'GITHUB_OUTPUT'): | ||
"""Sets output variable for a GitHub Action""" | ||
logger = logging.getLogger(__name__) | ||
# In an environment variable "GITHUB_OUTPUT" GHA stores path to a file to write outputs to | ||
with open(os.environ.get(github_output_var_name), 'a+') as file: | ||
logger.info(f"Add {name}={value} to {github_output_var_name}") | ||
print(f'{name}={value}', file=file) |
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,51 @@ | ||
from __future__ import annotations | ||
|
||
import argparse | ||
import os | ||
from pathlib import Path | ||
from .constants import EventType | ||
|
||
|
||
def add_common_args(parser: argparse.ArgumentParser): | ||
parser.add_argument('-s', '--commit_sha', help='Commit hash for which artifacts were generated', required=True) | ||
parser.add_argument('-b', '--branch_name', help='Name of GitHub branch', required=False, | ||
default=os.getenv('GITHUB_BASE_REF') or os.getenv('GITHUB_REF_NAME')) | ||
parser.add_argument('-e', '--event_name', help='Name of GitHub event', required=False, | ||
default=os.getenv('GITHUB_EVENT_NAME')) | ||
parser.add_argument('--storage_dir', help='Subdirectory name for artifacts, same as product type', required=True) | ||
parser.add_argument('--storage_root', help='Root path of the artifacts storage', required=False, | ||
default=os.getenv('ARTIFACTS_SHARE')) | ||
|
||
|
||
def get_event_type(event_name: str = os.getenv('GITHUB_EVENT_NAME')) -> str: | ||
return EventType.pre_commit.value if event_name == 'pull_request' else EventType.commit.value | ||
|
||
|
||
def get_storage_event_dir(storage_root: str | Path, branch_name: str, event_name: str, | ||
product_name: str = 'dldt') -> Path: | ||
""" Returns path to stored artifacts for a given branch and event """ | ||
event_type = get_event_type(event_name) | ||
storage_branch_dir = Path(storage_root) / product_name / branch_name / event_type | ||
return storage_branch_dir | ||
|
||
|
||
def get_storage_dir(product_type: str, commit_hash: str, storage_root: str | Path, branch_name: str, event_name: str, | ||
product_name: str = 'dldt') -> Path: | ||
""" Returns full path to stored artifacts for a given product type """ | ||
|
||
# TODO: return, once we decide to get rid of post-commit and choose artifacts generated for a merged PR in queue? | ||
# merge_queue_matcher = re.search(r'gh-readonly-queue/(.*?)/pr-', branch_name) | ||
# if merge_queue_matcher: | ||
# branch_name = merge_queue_matcher.group(1) | ||
|
||
storage_event_dir = get_storage_event_dir(storage_root, branch_name, event_name, product_name) | ||
storage = storage_event_dir / commit_hash / product_type | ||
return storage | ||
|
||
|
||
def get_latest_artifacts_link(product_type: str, storage_root: str | Path, branch_name: str, event_name: str, | ||
product_name: str = 'dldt') -> Path: | ||
""" Returns path to latest available artifacts for a given branch, event and product type """ | ||
storage_branch_dir = get_storage_event_dir(storage_root, branch_name, event_name, product_name) | ||
latest_artifacts_for_branch = storage_branch_dir / f"latest_{product_type}.txt" | ||
return Path(latest_artifacts_for_branch) |
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,8 @@ | ||
from enum import Enum | ||
|
||
|
||
class EventType(Enum): | ||
pre_commit = 'pre_commit' | ||
commit = 'commit' | ||
|
||
# TODO: add enum for product type to validate it |
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
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,58 @@ | ||
name: 'Restore artifacts' | ||
description: 'Take artifacts from a shared drive and load them back to GitHub' | ||
inputs: | ||
storage_dir: | ||
description: "Subdirectory name for artifacts, same as product type" | ||
required: true | ||
storage_root: | ||
description: "Root path of the artifacts storage" | ||
required: true | ||
event_name: | ||
description: "GitHub event name. If not set - taken from github context" | ||
required: false | ||
branch_name: | ||
description: "Target branch name. If not set - taken from github context" | ||
required: false | ||
trigger_repo_sha: | ||
description: "Commit hash of a trigger repo. If not set - taken from github context" | ||
required: false | ||
artifacts_key: | ||
description: "A key under which to upload the artifacts to storage, product type by default" | ||
required: false | ||
|
||
|
||
outputs: | ||
artifacts_storage_path: | ||
description: "Path on a shared drive where the artifacts are stored" | ||
value: ${{ steps.restore.outputs.artifacts_storage_path }} | ||
restored_artifacts_key: | ||
description: "Key under which the restored artifacts, if any, were uploaded to GitHub" | ||
value: ${{ steps.restore.outputs.restored_artifacts_key }} | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Restore artifacts | ||
id: restore | ||
if: "!inputs.artifacts" | ||
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} | ||
run: >- | ||
python3 ${{ env.ACTION_PATH }}/restore_artifacts.py | ||
-t "${{ env.GITHUB_WORKSPACE }}/${{ inputs.storage_dir }}" | ||
--storage_dir "${{ inputs.storage_dir }}" --storage_root "${{ inputs.storage_root }}" | ||
-s "${{ inputs.trigger_repo_sha || github.event.pull_request.head.sha || github.sha }}" | ||
${{ inputs.branch_name && env.BRANCH_PARAM || '' }} | ||
${{ inputs.event_name && env.EVENT_PARAM || '' }} | ||
env: | ||
ACTION_PATH: ${{ runner.os == 'Windows' && '$env:GITHUB_ACTION_PATH' || '$GITHUB_ACTION_PATH' }} | ||
GITHUB_WORKSPACE: ${{ runner.os == 'Windows' && '$env:GITHUB_WORKSPACE' || '$GITHUB_WORKSPACE' }} | ||
BRANCH_PARAM: "-b ${{ inputs.branch_name }}" | ||
EVENT_PARAM: "-e ${{ inputs.event_name }}" | ||
|
||
- name: Upload artifacts | ||
if: "!inputs.artifacts" | ||
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 | ||
with: | ||
name: ${{ inputs.artifacts_key || steps.restore.outputs.restored_artifacts_key }} | ||
path: ${{ steps.restore.outputs.artifacts_workspace_path }} | ||
if-no-files-found: 'error' |
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,52 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
|
||
import argparse | ||
import logging | ||
import shutil | ||
import sys | ||
from pathlib import Path | ||
|
||
sys.path.append(str(Path(__file__).parents[1])) | ||
from common import artifact_utils, action_utils | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser(description='Returns a path to artifacts for a given revision on a shared drive') | ||
artifact_utils.add_common_args(parser) | ||
parser.add_argument('-t', '--target_dir', type=str, help='Path to a dir in a workspace to download artifacts into', | ||
required=True) | ||
parser.add_argument('-k', '--artifact_key', type=str, | ||
help='A key under which to upload the artifacts to storage, product type by default', | ||
required=False) | ||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
def main(): | ||
action_utils.init_logger() | ||
logger = logging.getLogger(__name__) | ||
args = parse_args() | ||
|
||
if args.commit_sha == 'latest': | ||
latest_artifacts_link = artifact_utils.get_latest_artifacts_link(args.storage_dir, args.storage_root, | ||
args.branch_name, args.event_name) | ||
storage = Path(args.storage_root) / latest_artifacts_link.read_text() | ||
else: | ||
storage = artifact_utils.get_storage_dir(args.storage_dir, args.commit_sha, args.storage_root, args.branch_name, | ||
args.event_name) | ||
|
||
action_utils.set_github_output("artifacts_storage_path", str(storage)) | ||
logger.info(f"Artifacts are taken from here: {storage}") | ||
|
||
shutil.copytree(storage, args.target_dir, dirs_exist_ok=True) | ||
logger.info(f"Artifacts are copied here: {args.target_dir}") | ||
|
||
action_utils.set_github_output("artifacts_workspace_path", args.target_dir) | ||
action_utils.set_github_output("restored_artifacts_key", args.artifact_key or args.storage_dir) | ||
|
||
|
||
if __name__ == '__main__': | ||
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
pr-25234 | ||
pr-25992 |
Oops, something went wrong.