From a84345ca85941b48b73022a45090b27040f321b2 Mon Sep 17 00:00:00 2001 From: Oliver Berger Date: Tue, 30 Mar 2021 09:18:33 +0200 Subject: [PATCH] with renaming --- .github/workflows/integration.yml | 2 ++ main.py | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index fc3a50b..6aca432 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -21,7 +21,9 @@ jobs: with: artifact_name: "${{ github.sha }}" token: "${{ secrets.GH_BOT_PAT }}" + name: foobar - name: Check outputs run: | test "${{ steps.selftest.outputs.success }}" == "Artifact downloaded: ${{ github.sha }}" + test -f foobar diff --git a/main.py b/main.py index c68f2f5..524d7f7 100644 --- a/main.py +++ b/main.py @@ -3,15 +3,16 @@ import os import urllib3 -token = os.environ["INPUT_TOKEN"] -artifact_name = os.environ["INPUT_ARTIFACT_NAME"] -repo = os.getenv("INPUT_REPO") or os.getenv("GITHUB_REPOSITORY") -wait_seconds = int(os.getenv("INPUT_WAIT_SECONDS") or "60") -wait_sleep = 0.5 - -artifacts_url = f"https://api.github.com/repos/{repo}/actions/artifacts" +TOKEN = os.environ["INPUT_TOKEN"] +ARTIFACT_NAME = os.environ["INPUT_ARTIFACT_NAME"] +NAME = os.environ["INPUT_NAME"] or ARTIFACT_NAME +REPO = os.getenv("INPUT_REPO") or os.getenv("GITHUB_REPOSITORY") +WAIT_SECONDS = int(os.getenv("INPUT_WAIT_SECONDS") or "60") +WAIT_SLEEP = 0.5 + +artifacts_url = f"https://api.github.com/repos/{REPO}/actions/artifacts" headers = { - "Authorization": f"token {token}", + "Authorization": f"token {TOKEN}", "User-Agent": "Python", } @@ -41,22 +42,22 @@ def get_artifact(name): if artifact["name"] == name: return artifact - waiting = time.time() - t_started < wait_seconds + waiting = time.time() - t_started < WAIT_SECONDS time.sleep(1) print("Waiting...", etag, resp.status) -def download_artifact(name): +def download_artifact(name, new_name): artifact = get_artifact(name) if artifact is None: print(f"::set-output name=error::Artifact not found: {name}") exit(1) r = http.request("GET", artifact["archive_download_url"], headers=headers) - with open(artifact["name"], "wb") as f: + with open(new_name, "wb") as f: f.write(r.data) print(f"::set-output name=success::Artifact downloaded: {artifact['name']}") if __name__ == "__main__": - download_artifact(artifact_name) + download_artifact(ARTIFACT_NAME, NAME)