Commit de465943 authored by Jan Kiene's avatar Jan Kiene
Browse files

add script for the pages job to avoid repetition

parent 63bf57e5
Loading
Loading
Loading
Loading
Loading

ci/setup_pages.py

0 → 100644
+66 −0
Original line number Diff line number Diff line
import os
import sys
import pathlib
import subprocess
from .get_id_of_last_job_occurence import get_job_id

JOBS = [
    "complexity-stereo-in-stereo-out", "complexity-ism-in-binaural-out", "complexity-sba-hoa3-in-hoa3-out", "complexity-mc-in-7_1_4-out", "complexity-masa-in-7_1_4-out", "complexity-StereoDmxEVS-stereo-in-mono-out", "coverage-test-on-main-scheduled"
]
ARTIFACTS = "artifacts.zip"
API_URL_BASE = "https://forge.3gpp.org/rep/api/v4/projects/$CI_PROJECT_ID/jobs"
PUBLIC = "./public"


def main():

    public_folder = pathlib.Path(PUBLIC)
    public_folder.mkdir()

    failed_count = 0
    for job in JOBS:
        job_id = get_job_id(os.environ["CI_COMMIT_REF_NAME"], job)
        try:
            curl_for_artifacts(job_id)

            job_public = job + "-public"
            if job == "coverage-test-on-main-scheduled":
                job_public = "coverage"

            pathlib.Path(job_public).rename(public_folder.joinpath(job_public))
            
        except subprocess.CalledProcessError:
            print(f"Could not get artifacts for {job}") 
            failed_count += 1

    if failed_count == len(JOBS):
        sys.exit(1)


def curl_for_artifacts(job_id):
    cmd = [
        "curl",
        "--request",
        "GET",
        API_URL_BASE + f"/{job_id}/artifacts",
        "--output",
        ARTIFACTS
    ]
    subprocess.run(cmd, check=True)

    # check for valid archive (if not, it is likely a 404 page, then display that)
    cmd = [
        "unzip",
        "-t",
        ARTIFACTS
    ]
    try:
        subprocess.run(cmd, check=True)
    except subprocess.CalledProcessError:
        with open(ARTIFACTS, "r") as f:
            print(f.read())
        raise subprocess.CalledProcessError("Unzip check failed")


if __name__ == "__main__":
    main()
 No newline at end of file