input-output-hk / actions

IOG GitHub Actions
2 stars 3 forks source link

The `devx` action should prevent users of using unsupported combinations of inputs #7

Open yvan-sraka opened 1 year ago

yvan-sraka commented 1 year ago

Currently, there is nothing that forbid devx GitHub Action users of using unsupported combinations of inputs, as defined in the exclude list of the job that populate ghcr.io with devx devshell closure.

I'm not sure what would be the best way to achieve that? I can suggest to just add this small python script that would fail if it encounters a conflict (I didn't test it yet):

import os

inputs = {
    "platform": os.environ.get('PLATFORM', '').strip(),
    "compiler-nix-name": os.environ.get('COMPILER_NIX_NAME', '').strip(),
    "target-platform": os.environ.get('TARGET_PLATFORM', '').strip(),
    "minimal": os.environ.get('MINIMAL', '').strip(),
    "iog": os.environ.get('IOG', '').strip()
}

exclusions = [
    # Just cross compiling javascript with ghc 9.6.2 for now
    {"compiler-nix-name": "ghc8107", "target-platform": "-js"},
    {"compiler-nix-name": "ghc928", "target-platform": "-js"},
    # Static builds not working for darwin yet
    {"platform": "x86_64-darwin", "target-platform": "-static"},
    # Static tools not working right now (so just building "-static-minimal" for now)
    {"target-platform": "-static", "minimal": "false"},
    # Windows cross compilation only works on x86_64-linux right now.
    {"platform": "aarch64-darwin", "target-platform": "-windows"},
    {"platform": "aarch64-linux", "target-platform": "-windows"},
    {"platform": "x86_64-darwin", "target-platform": "-windows"},
    # It does not makes sense to build minimal image that include IOG extra tooling
    # ... "-minimal" and "-iog" are mutually exclusive options!
    {"minimal": "true", "iog": "true"},
    # On darwin the `-js` target require `-minimal` to be set:
    {"target-platform": "-js", "platform": "aarch64-darwin", "minimal": "false"},
    {"target-platform": "-js", "platform": "x86_64-darwin", "minimal": "false"}
]

for exclusion in exclusions:
    if all(inputs[key] == value for key, value in exclusion.items()):
        exit(1)
angerman commented 1 year ago

we could use some bash snippet that uses case to match against unsupported combinations? Or use a regex?

yvan-sraka commented 10 months ago

GPT-4 seems to know better than me how to write bash script … this should do the job:

#!/bin/bash

platform="${PLATFORM:-}"
compiler_nix_name="${COMPILER_NIX_NAME:-}"
target_platform="${TARGET_PLATFORM:-}"
minimal="${MINIMAL:-}"
iog="${IOG:-}"

case "${compiler_nix_name}-${target_platform}" in
    "ghc8107"-*js*| "ghc928"-*js*) exit 1 ;;
esac

case "${platform}-${target_platform}" in
    *x86_64-darwin*-static*| *aarch64-darwin*-windows*| *x86_64-darwin*-windows*) exit 1 ;;
    *aarch64-linux*-windows*) exit 1 ;;
esac

if [[ "${target_platform}" == *-static* && "${minimal}" == "false" ]]; then
    exit 1
fi

if [[ "${minimal}" == "true" && "${iog}" == "true" ]]; then
    exit 1
fi

if [[ "${target_platform}" == *-js* && "${platform}" == *darwin* && "${minimal}" == "false" ]]; then
    exit 1
fi