2023-08-17 07:07:39 +01:00
|
|
|
"""
|
|
|
|
These commands are related to downloading test suite CI artifacts.
|
|
|
|
"""
|
2024-02-27 10:24:22 +00:00
|
|
|
|
2023-08-17 07:07:39 +01:00
|
|
|
# pylint: disable=resource-leakage,broad-except,3rd-party-module-not-gated
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import logging
|
2023-10-03 12:51:03 -04:00
|
|
|
import pathlib
|
2023-08-17 07:07:39 +01:00
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
from ptscripts import Context, command_group
|
|
|
|
|
|
|
|
import tools.utils
|
|
|
|
import tools.utils.gh
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
# Define the command group
|
|
|
|
download = command_group(
|
|
|
|
name="download",
|
|
|
|
help="Test Suite CI Artifacts Related Commands",
|
|
|
|
description=__doc__,
|
|
|
|
parent="ts",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@download.command(
|
|
|
|
name="onedir-artifact",
|
|
|
|
arguments={
|
|
|
|
"run_id": {
|
|
|
|
"help": "The workflow run ID from where to download artifacts from",
|
|
|
|
"required": True,
|
|
|
|
},
|
|
|
|
"platform": {
|
|
|
|
"help": "The onedir platform artifact to download",
|
2024-01-16 17:41:00 +00:00
|
|
|
"choices": ("linux", "macos", "windows"),
|
2023-08-17 07:07:39 +01:00
|
|
|
"required": True,
|
|
|
|
},
|
|
|
|
"arch": {
|
|
|
|
"help": "The onedir artifact architecture",
|
|
|
|
"choices": ("x86_64", "aarch64", "amd64", "x86"),
|
|
|
|
},
|
|
|
|
"repository": {
|
|
|
|
"help": "The repository to query, e.g. saltstack/salt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
def download_onedir_artifact(
|
|
|
|
ctx: Context,
|
|
|
|
run_id: int = None,
|
|
|
|
platform: str = None,
|
|
|
|
arch: str = "x86_64",
|
|
|
|
repository: str = "saltstack/salt",
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
Download CI onedir artifacts.
|
|
|
|
"""
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
assert run_id is not None
|
|
|
|
assert platform is not None
|
|
|
|
|
|
|
|
exitcode = tools.utils.gh.download_onedir_artifact(
|
|
|
|
ctx=ctx, run_id=run_id, platform=platform, arch=arch, repository=repository
|
|
|
|
)
|
|
|
|
ctx.exit(exitcode)
|
|
|
|
|
|
|
|
|
|
|
|
@download.command(
|
|
|
|
name="nox-artifact",
|
|
|
|
arguments={
|
|
|
|
"run_id": {
|
|
|
|
"help": "The workflow run ID from where to download artifacts from",
|
|
|
|
"required": True,
|
|
|
|
},
|
2024-01-12 18:34:54 +00:00
|
|
|
"platform": {
|
|
|
|
"help": "The onedir platform artifact to download",
|
|
|
|
"choices": ("linux", "macos", "windows"),
|
|
|
|
"required": True,
|
|
|
|
},
|
|
|
|
"arch": {
|
|
|
|
"help": "The onedir artifact architecture",
|
|
|
|
"choices": ("x86_64", "aarch64", "amd64", "x86"),
|
2023-08-17 07:07:39 +01:00
|
|
|
"required": True,
|
|
|
|
},
|
|
|
|
"nox_env": {
|
|
|
|
"help": "The nox environment name.",
|
|
|
|
},
|
|
|
|
"repository": {
|
|
|
|
"help": "The repository to query, e.g. saltstack/salt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
def download_nox_artifact(
|
|
|
|
ctx: Context,
|
|
|
|
run_id: int = None,
|
2024-01-12 18:34:54 +00:00
|
|
|
platform: str = None,
|
|
|
|
arch: str = None,
|
2023-08-17 07:07:39 +01:00
|
|
|
nox_env: str = "ci-test-onedir",
|
|
|
|
repository: str = "saltstack/salt",
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
Download CI nox artifacts.
|
|
|
|
"""
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
assert run_id is not None
|
2024-01-12 18:34:54 +00:00
|
|
|
assert arch is not None
|
|
|
|
assert platform is not None
|
2023-08-17 07:07:39 +01:00
|
|
|
|
|
|
|
exitcode = tools.utils.gh.download_nox_artifact(
|
2024-01-12 18:34:54 +00:00
|
|
|
ctx=ctx,
|
|
|
|
run_id=run_id,
|
|
|
|
platform=platform,
|
|
|
|
arch=arch,
|
|
|
|
nox_env=nox_env,
|
|
|
|
repository=repository,
|
2023-08-17 07:07:39 +01:00
|
|
|
)
|
|
|
|
ctx.exit(exitcode)
|
|
|
|
|
|
|
|
|
|
|
|
@download.command(
|
|
|
|
name="pkgs-artifact",
|
|
|
|
arguments={
|
|
|
|
"run_id": {
|
|
|
|
"help": "The workflow run ID from where to download artifacts from",
|
|
|
|
"required": True,
|
|
|
|
},
|
|
|
|
"slug": {
|
|
|
|
"help": "The OS slug",
|
|
|
|
"required": True,
|
2024-03-27 14:21:56 +00:00
|
|
|
"choices": sorted(tools.utils.get_golden_images()),
|
2023-08-17 07:07:39 +01:00
|
|
|
},
|
|
|
|
"repository": {
|
|
|
|
"help": "The repository to query, e.g. saltstack/salt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
def download_pkgs_artifact(
|
|
|
|
ctx: Context,
|
|
|
|
run_id: int = None,
|
|
|
|
slug: str = None,
|
|
|
|
repository: str = "saltstack/salt",
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
Download CI built packages artifacts.
|
|
|
|
"""
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
assert run_id is not None
|
|
|
|
assert slug is not None
|
|
|
|
|
|
|
|
exitcode = tools.utils.gh.download_pkgs_artifact(
|
|
|
|
ctx=ctx, run_id=run_id, slug=slug, repository=repository
|
|
|
|
)
|
|
|
|
ctx.exit(exitcode)
|
2023-10-03 12:51:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
@download.command(
|
|
|
|
name="artifact",
|
|
|
|
arguments={
|
|
|
|
"artifact_name": {
|
|
|
|
"help": "The name of the artifact to download",
|
|
|
|
},
|
|
|
|
"dest": {
|
|
|
|
"help": "The path to the file downloaded",
|
|
|
|
},
|
|
|
|
"run_id": {
|
|
|
|
"help": "The workflow run ID from where to download artifacts from",
|
|
|
|
},
|
|
|
|
"branch": {
|
|
|
|
"help": "The branch from where to look for artifacts.",
|
|
|
|
"metavar": "BRANCH_NAME",
|
|
|
|
},
|
|
|
|
"pr": {
|
|
|
|
"help": "The pull-request from where to look for artifacts.",
|
|
|
|
"metavar": "PR_NUMBER",
|
|
|
|
},
|
|
|
|
"nightly": {
|
|
|
|
"help": "The nightly build branch from where to look for artifacts.",
|
|
|
|
"metavar": "BRANCH_NAME",
|
|
|
|
},
|
|
|
|
"repository": {
|
|
|
|
"help": "The repository to query, e.g. saltstack/salt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
def download_artifact(
|
|
|
|
ctx: Context,
|
|
|
|
artifact_name: pathlib.Path,
|
|
|
|
dest: pathlib.Path,
|
|
|
|
run_id: int = None,
|
|
|
|
branch: str = None,
|
|
|
|
nightly: str = None,
|
|
|
|
pr: int = None,
|
|
|
|
repository: str = "saltstack/salt",
|
|
|
|
):
|
|
|
|
"""
|
2023-10-16 13:34:41 -04:00
|
|
|
Download CI artifacts.
|
2023-10-03 12:51:03 -04:00
|
|
|
"""
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
assert artifact_name is not None
|
|
|
|
assert dest is not None
|
|
|
|
|
|
|
|
if run_id is not None:
|
|
|
|
actual_run_id = run_id
|
|
|
|
else:
|
|
|
|
potential_run_id = tools.utils.gh.discover_run_id(
|
|
|
|
ctx, branch=branch, nightly=nightly, pr=pr, repository=repository
|
|
|
|
)
|
|
|
|
if potential_run_id is not None:
|
|
|
|
actual_run_id = potential_run_id
|
|
|
|
else:
|
|
|
|
ctx.exit(1, "Could not discover run ID")
|
|
|
|
|
|
|
|
succeeded = tools.utils.gh.download_artifact(
|
|
|
|
ctx,
|
|
|
|
dest,
|
|
|
|
actual_run_id,
|
|
|
|
repository=repository,
|
|
|
|
artifact_name=str(artifact_name),
|
|
|
|
)
|
2023-11-26 16:10:40 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
assert succeeded is not None
|
2023-10-03 12:51:03 -04:00
|
|
|
ctx.info(succeeded)
|
|
|
|
if succeeded:
|
|
|
|
ctx.info(f"Downloaded {artifact_name} to {dest}")
|
|
|
|
ctx.exit(0)
|
|
|
|
else:
|
|
|
|
ctx.exit(1)
|