---
- name: Build TensorFlow IO in Dual ABI container
  hosts: localhost
  vars_files:
    ../vars/vars-tfio.yml

  tasks:
    - name: Set dual abi variable
      ansible.builtin.set_fact:
        dual_abi: true

    - name: Remove previous build wheels
      ansible.builtin.file:
        path: "{{ wheels_dir }}"
        force: true
        state: absent

    - name: Create output wheels directory
      ansible.builtin.file:
        path: "{{ wheels_dir }}"
        state: directory
        mode: 0755

    - name: Go through each TensorFlow IO version
      ansible.builtin.include_role:
        name: tensorflow_io
        tasks_from: manylinux-build.yml
      loop: "{{ tfio_versions | dict2items }}"
      loop_control:
        loop_var: tfio_ver
      when: tfio_ver.key in to_be_built

    - name: Remove file not needed to be published
      ansible.builtin.file:
        path: "{{ wheels_dir }}/upper-constraints.txt"
        state: absent

    - name: Prepare wheels for publishing  # noqa no-changed-when
      ansible.builtin.shell:
        cmd: |
          set -xe
          for pkg in *.whl
          do
            pkgdir=$(echo `basename $pkg`|cut -d'-' -f1 | tr '[:upper:]_' '[:lower:]-')
            mkdir -p "{{ wheels_dir }}/$pkgdir"
            mv $pkg  "{{ wheels_dir }}/$pkgdir"
          done
        chdir: "{{ wheels_dir }}"
        executable: "/bin/bash"
