From bc54882209392de60dd7a57c7d508dd86de12fbd Mon Sep 17 00:00:00 2001 From: hawkeye116477 Date: Sat, 16 Sep 2023 15:12:21 +0200 Subject: [PATCH] Test --- .github/workflows/test.yml | 13 ++----- Dockerfile_ED | 2 +- scripts/CI/downloadArtifacts.py | 61 +++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 11 deletions(-) create mode 100755 scripts/CI/downloadArtifacts.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5d5eba9..e422749 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,20 +33,13 @@ jobs: needs: generate-artifacts runs-on: ubuntu-latest container: ghcr.io/filtersheroes/expired_domains_image:latest + env: + GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v4 - run: | git config --global --add safe.directory "$GITHUB_WORKSPACE" ./scripts/CI/getArtifactNamesForED.py KAD - npm install @actions/artifact - - uses: actions/github-script@v6 - with: - script: | - const artifact = require("@actions/artifact") - const artifactClient = artifact.create() - const artifactFiles = process.env.E_KAD_NAMES.split(" ") - for (artifactFile of artifactFiles) { - await artifactClient.downloadArtifact(artifactFile, "./expired-d", { createArtifactFolder: false }) - } + ./scripts/CI/downloadArtifacts.py "E_KAD_NAMES" - run: | ls -l ./expired-d diff --git a/Dockerfile_ED b/Dockerfile_ED index 2acd4c5..23913a7 100644 --- a/Dockerfile_ED +++ b/Dockerfile_ED @@ -3,7 +3,7 @@ FROM python:3-slim # make Apt non-interactive ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get update && apt-get install -y locales git openssh-client ca-certificates wget tzdata whois curl nodejs npm --no-install-recommends && pip install GitPython dnspython aiohttp tldextract --no-cache-dir +RUN apt-get update && apt-get install -y locales git openssh-client ca-certificates wget tzdata whois curl --no-install-recommends && pip install GitPython dnspython aiohttp tldextract aiodns --no-cache-dir # uncomment chosen locale to enable it's generation RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && sed -i -e 's/# pl_PL.UTF-8 UTF-8/pl_PL.UTF-8 UTF-8/' /etc/locale.gen diff --git a/scripts/CI/downloadArtifacts.py b/scripts/CI/downloadArtifacts.py new file mode 100755 index 0000000..1b774a2 --- /dev/null +++ b/scripts/CI/downloadArtifacts.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +# coding=utf-8 +# pylint: disable=C0103 +# pylint: disable=missing-module-docstring +# pylint: disable=missing-class-docstring +# pylint: disable=missing-function-docstring +import os +import sys +import shutil +import asyncio +import aiohttp + + +pj = os.path.join +pn = os.path.normpath + +script_path = os.path.dirname(os.path.realpath(__file__)) +main_path = os.getenv("GITHUB_WORKSPACE") + +expired_dir = pj(main_path, "expired-d") +if not os.path.isdir(expired_dir): + os.mkdir(expired_dir) + +async def download_artifact(session, limit, name): + async with limit: + try: + repo = os.getenv("GITHUB_REPOSITORY") + artifacts_url = f"https://api.github.com/repos/{repo}/actions/artifacts" + token = os.getenv("GIT_TOKEN") + headers = { "Authorization": f"Bearer {token}", "User-Agent": "Python"} + params = {'name': name} + resp = await session.get(artifacts_url, headers=headers, params=params) + if resp.status == 200: + data = await resp.json() + if data["artifacts"]: + artifact = data["artifacts"][0] + try: + print(f"Downloading artifact {name} ...") + resp_adl = await session.get(artifact["archive_download_url"], headers=headers) + if resp_adl.status == 200: + file_path = pj(expired_dir, name + ".zip") + with open(file_path, "wb") as f: + f.write(resp_adl.read()) + if os.path.isfile(file_path): + shutil.unpack_archive(file_path, expired_dir) + os.remove(file_path) + except Exception as e_adl: + print(e_adl) + except Exception as e: + print(e) + +async def download_artifacts(limit_value, names): + limit = asyncio.Semaphore(limit_value) + async with aiohttp.ClientSession() as session: + await asyncio.gather(*[download_artifact(session, limit, name) for name in names]) + +artifact_names = [] +if sys.argv[1]: + print(sys.argv[1]) + artifact_names = os.getenv(str(sys.argv[1])).split(" ") +asyncio.run(download_artifacts(5, artifact_names))