#!/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",
}
PLATFORMS = {
    "nova": "linux/amd64,linux/arm64",
    "neutron": "linux/amd64,linux/arm64",
}


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_image_build_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": f"type=gha,scope={project}-{release}",
            "cache-to": "type=gha,mode=max,scope={project}-{release}",
            "push": True,
            "platforms": PLATFORMS.get(project, "linux/amd64"),
            "build-args": "\n".join([f"{k}={v}" for k, v in build_args.items()]),
            "tags": f"quay.io/vexxhost/{project}:{ref}",
        },
    }


def get_image_promote_job_for_project(project, release):
    ref = get_ref_for_project(project, release)

    return {
        "name": "Promote openstack/{}".format(project),
        "uses": "akhilerm/tag-push-action@v2.0.0",
        "with": {
            "src": f"quay.io/vexxhost/{project}:{ref}",
            "dst": f"quay.io/vexxhost/{project}:{release}",
        },
    }


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_image_build_job_for_project(project, release)
                    for project in PROJECTS
                ]
                + [
                    # molecule
                ]
                + [
                    get_image_promote_job_for_project(project, release)
                    for project in PROJECTS
                ],
            }
        },
    }

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