#!/usr/bin/env python3

import yaml

PROJECTS = [
    "barbican",
    "cinder",
    "designate",
    "glance",
    "heat",
    "horizon",
    "ironic",
    "keystone",
    "magnum",
    "monasca-agent",
    "monasca-api",
    "monasca-notification",
    "monasca-persister",
    "neutron",
    "nova",
    "octavia",
    "placement",
    "senlin",
]
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": f"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)
