include: "utils.smk" import datetime DATE = datetime.datetime.now().strftime("%Y%m%d") ARTIFACTS_FOLDER_NICKEL = "artifacts_nickel" ARTIFACTS_FOLDER_JSON = "artifacts_json" BLACKLIST_FOLDER = "blacklists" BLACKLIST = "blacklist.csv" EXTENSION = "json" ARTIFACTS = get_artifacts_to_build(ARTIFACTS_FOLDER_NICKEL, BLACKLIST) rule all: input: expand("{folder}/{artifact}/{date}.csv",\ folder=["pkgs", "build_status", "artifact_hash"],\ artifact=ARTIFACTS,\ date=DATE ), expand("{folder}/{artifact}/{date}.txt",\ folder=["logs"],\ artifact=ARTIFACTS,\ date=DATE ), f"{BLACKLIST_FOLDER}/{DATE}.csv" rule check_artifact: input: "flake.nix", "flake.lock", contract="workflow/nickel/artifact_contract.ncl", artifact=f"{ARTIFACTS_FOLDER_NICKEL}/{{artifact}}.ncl" output: f"{ARTIFACTS_FOLDER_JSON}/{{artifact}}.json" shell: """ nickel export --format json --output {output} <<< 'let {{Artifact, ..}} = import "{input.contract}" in ((import "{input.artifact}") | Artifact)' """ rule run_ecg: input: "flake.nix", "flake.lock", ecg="ecg.py", artifact=f"{ARTIFACTS_FOLDER_JSON}/{{artifact}}.{EXTENSION}" output: log = "logs/{artifact}/{date}.txt", pkg = "pkgs/{artifact}/{date}.csv", build_status = "build_status/{artifact}/{date}.csv", artifact_hash = "artifact_hash/{artifact}/{date}.csv" shell: f"python3 {{input.ecg}} -l {{output.log}} -p {{output.pkg}} -b {{output.build_status}} -a {{output.artifact_hash}} {ARTIFACTS_FOLDER_JSON}/{{wildcards.artifact}}.{EXTENSION}" rule update_blacklist: input: BLACKLIST, build_status=expand("build_status/{artifact}/{{date}}.csv",\ artifact=ARTIFACTS) output: f"{BLACKLIST_FOLDER}/{{date}}.csv" shell: f"cat {{input}} > {{output}} && ln -s {{output}} {BLACKLIST}"