---
- name: Build TensorFlow Text in Dual ABI container
  hosts: localhost
  vars_files:
    ../vars/vars-tf-text.yml

  tasks:
    - 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 Text version
      ansible.builtin.include_role:
        name: tensorflow_text
        tasks_from: manylinux-build.yml
      loop: "{{ tf_text_versions | dict2items }}"
      loop_control:
        loop_var: tf_text_ver
      when: tf_text_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"
