adf0d17497
publish / version_or_publish (push) Waiting to run
storybook-build / changes (push) Waiting to run
storybook-build / :storybook-build (push) Blocked by required conditions
Sync Gradio Skills to Hugging Face / sync-skills (push) Waiting to run
functional / changes (push) Waiting to run
functional / build-frontend (push) Blocked by required conditions
functional / functional-test-SSR=false (push) Blocked by required conditions
functional / functional-reload (push) Blocked by required conditions
functional / functional-test-SSR=true (push) Blocked by required conditions
hygiene / hygiene-test (push) Waiting to run
python / changes (push) Waiting to run
python / build (push) Blocked by required conditions
python / test-ubuntu-latest-flaky (push) Blocked by required conditions
python / test-ubuntu-latest-not-flaky (push) Blocked by required conditions
python / test-windows-latest-flaky (push) Blocked by required conditions
python / test-windows-latest-not-flaky (push) Blocked by required conditions
js / changes (push) Waiting to run
js / js-test (push) Blocked by required conditions
docs-build / changes (push) Waiting to run
docs-build / docs-build (push) Blocked by required conditions
docs-build / website-build (push) Blocked by required conditions
77 lines
2.2 KiB
Python
77 lines
2.2 KiB
Python
import argparse
|
|
|
|
import requests
|
|
|
|
WORKFLOW_RUN_ENDPOINT = (
|
|
"https://api.github.com/repos/{owner}/{repo}/actions/runs/{run_id}/artifacts"
|
|
)
|
|
ARTIFACT_DOWNLOAD_ENDPOINT = (
|
|
"https://api.github.com/repos/{owner}/{repo}/actions/artifacts/{artifact_id}/zip"
|
|
)
|
|
|
|
|
|
def download_artifact(
|
|
owner: str, repo: str, run_id: str, artifact_name: str, gh_token: str
|
|
):
|
|
"""Download artifact by name from a run id
|
|
Args:
|
|
owner: Owner of the repo.
|
|
repo: The name of the repository.
|
|
run_id: The id of the action run that created the artifact.
|
|
artifact_name: The name of the artifact to download.
|
|
gh_token: The token used to download artifacts
|
|
"""
|
|
|
|
headers = {
|
|
"Accept": "application/vnd.github+json",
|
|
"Authorization": f"Bearer {gh_token}",
|
|
"X-GitHub-Api-Version": "2022-11-28",
|
|
}
|
|
|
|
artifacts = requests.get(
|
|
WORKFLOW_RUN_ENDPOINT.format(owner=owner, repo=repo, run_id=run_id),
|
|
headers=headers,
|
|
).json()
|
|
artifact_id = next(
|
|
(
|
|
artifact["id"]
|
|
for artifact in artifacts["artifacts"]
|
|
if artifact["name"] == artifact_name
|
|
),
|
|
None,
|
|
)
|
|
|
|
if not artifact_id:
|
|
raise ValueError(
|
|
f"Cannot find {artifact_name}! {artifacts} {owner} {repo} {run_id}"
|
|
)
|
|
|
|
download = requests.get(
|
|
ARTIFACT_DOWNLOAD_ENDPOINT.format(
|
|
artifact_id=artifact_id,
|
|
owner=owner,
|
|
repo=repo,
|
|
),
|
|
headers=headers,
|
|
)
|
|
with open(f"{artifact_name}.zip", "wb") as f:
|
|
f.write(download.content)
|
|
|
|
return f"{artifact_name}.zip"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description="Download an artifact")
|
|
parser.add_argument("run_id", type=str, help="Run id")
|
|
parser.add_argument("artifact_name", type=str)
|
|
parser.add_argument("gh_token", type=str)
|
|
parser.add_argument(
|
|
"--owner", type=str, help="Owner of repository", default="gradio-app"
|
|
)
|
|
parser.add_argument("--repo", type=str, help="Name of repository", default="gradio")
|
|
args = parser.parse_args()
|
|
new_space = download_artifact(
|
|
args.owner, args.repo, args.run_id, args.artifact_name, args.gh_token
|
|
)
|
|
print(new_space)
|