#!/usr/bin/env python3

import yaml

PROJECTS = [
    "cinder",
    "heat",
    "senlin",
    "octavia",
    "barbican",
    "designate",
    "nova",
    "neutron",
    "monasca-notification",
    "monasca-agent",
    "keystone",
    "horizon",
    "monasca-api",
    "ironic",
    "glance",
    "magnum",
    "monasca-persister",
    "placement",
]
RELEASES = ["xena", "wallaby", "yoga", "master"]

PROFILES = {
    "cinder": "ceph qemu",
    "nova": "ceph openvswitch configdrive qemu migration",
    "neutron": "openvswitch vpn",
    "keystone": "apache ldap openidc",
    "horizon": "apache",
    "monasca-api": "apache influxdb",
    "ironic": "ipxe ipmi qemu tftp",
    "glance": "ceph",
    "monasca-persister": "influxdb",
    "placement": "apache",
}
DIST_PACKAGES = {
    "heat": "curl",
    "designate": "bind9utils",
    "nova": "ovmf qemu-efi-aarch64",
    "neutron": "jq ethtool lshw",
    "monasca-agent": "iproute2 libvirt-clients lshw",
    "ironic": "ethtool lshw iproute2",
}
PIP_PACKAGES = {
    "neutron": "neutron-vpnaas",
    "monasca-agent": "libvirt-python python-glanceclient python-neutronclient python-novaclient py3nvml",
    "horizon": "designate-dashboard heat-dashboard ironic-ui magnum-ui neutron-vpnaas-dashboard octavia-dashboard senlin-dashboard monasca-ui",
    "ironic": "python-dracclient sushy",
    "placement": "httplib2",
}


def get_ref_for_project(project, release):
    return (
        open(f"images/openstack/projects/{project}/{release}/ref", "r").read().strip()
    )


def get_build_args_for_project(project, release):
    return {
        "RELEASE": release,
        "PROJECT": project,
        "PROJECT_REF": get_ref_for_project(project, release),
        "PROFILES": PROFILES.get(project, ""),
        "DIST_PACKAGES": DIST_PACKAGES.get(project, ""),
        "PIP_PACKAGES": PIP_PACKAGES.get(project, ""),
    }


def get_platforms_for_project(project):
    try:
        return (
            open(f"images/openstack/projects/{project}/platforms", "r").read().strip()
        )
    except FileNotFoundError:
        return "linux/amd64"


def get_job_for_project(project, release):
    build_args = get_build_args_for_project(project, release)
    ref = get_ref_for_project(project, release)

    return {
        "name": "Build openstack/{}".format(project),
        "uses": "docker/build-push-action@v3.1.1",
        "with": {
            "context": "images/openstack",
            "cache-from": "type=gha",
            "cache-to": "type=gha,mode=max",
            "push": True,
            "platforms": get_platforms_for_project(project),
            "build-args": "\n".join([f"{k}={v}" for k, v in build_args.items()]),
            "tags": f"quay.io/vexxhost/{project}:{ref}",
        },
    }


for release in RELEASES:
    workflow_name = f"test-{release}"

    workflow = {
        "name": f"test-{release}",
        "on": {
            "pull_request": {},
            "push": {"branches": ["main"]},
        },
        "jobs": {
            "build-images": {
                "runs-on": "ubuntu-latest",
                "steps": [
                    {"uses": "actions/checkout@v3.0.2"},
                    {"uses": "docker/setup-qemu-action@v2.0.0"},
                    {"uses": "docker/setup-buildx-action@v2.0.0"},
                    {
                        "uses": "docker/login-action@v2.0.0",
                        "with": {
                            "registry": "quay.io",
                            "username": "${{ secrets.QUAY_USERNAME }}",
                            "password": "${{ secrets.QUAY_ROBOT_TOKEN }}",
                        },
                    },
                ]
                + [get_job_for_project(project, release) for project in PROJECTS]
                + [
                    # molecule
                    # promote image if it is the default branch
                ],
            }
        },
    }

    with open(f".github/workflows/{workflow_name}.yml", "w") as fd:
        yaml.dump(workflow, fd, sort_keys=False)
