---
- name: Build TensorFlow IO
  hosts: localhost
  vars_files:
    ../vars/vars-tfio.yml

  tasks:
    - 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: 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"

    - name: Copy wheels for cache upload
      ansible.builtin.copy:
        src: "{{ wheels_dir }}"
        dest: "{{ build_dir }}/cache_upload"
        mode: 0644

    - name: Prepare wheels for cache
      ansible.builtin.include_role:
        name: linaro
        tasks_from: publish-wheels-cache.yml
      vars:
        wheels_dir: "{{ build_dir }}/cache_upload"
