---
- name: Create build scripts directory
  ansible.builtin.file:
    path: "{{ build_dir }}/scripts"
    state: directory
    mode: "755"

- name: Create build scripts from templates
  ansible.builtin.template:
    src: "audit_tf_text_wheels.sh.j2"
    dest: "{{ build_dir }}/scripts/audit_tf_text_wheels.sh"
    mode: "755"
    force: true

- name: Start TensorFlow Text build container
  community.docker.docker_container:
    name: "tf-text-multipython"
    image: "gcr.io/tensorflow-sigs/build-arm64:tf-{{ image_prefix }}-multi-python"
    pull: true
    state: started
    restart: true
    volumes:
      - "{{ build_dir }}:/tmp/workspace"
    detach: true
    user: buildslave
    working_dir: "/tmp/workspace"
    network_mode: host
    command: "sleep infinity"
    timeout: 600

- name: Go through each Python version
  ansible.builtin.include_tasks:
    file: build_wheel.yml
  loop: "{{ tf_text_ver.value.python_versions }}"
  loop_control:
    loop_var: python_version

- name: Stop build container
  community.docker.docker_container:
    name: "tf-text-multipython"
    image: "gcr.io/tensorflow-sigs/build-arm64:tf-{{ image_prefix }}-multi-python"
    state: absent
    timeout: 600

- name: Audit TensorFlow Text wheels in manylinux2014_aarch64 container
  when: run_audit
  block:
    - name: Start TensorFlow IO manylinux2014 audit container
      community.docker.docker_container:
        name: "tf-text-audit"
        image: "quay.io/pypa/manylinux2014_aarch64"
        pull: true
        state: started
        restart: true
        volumes:
          - "{{ build_dir }}:/tmp/workspace"
        detach: true
        working_dir: "/tmp/workspace"
        network_mode: host
        command: "sleep infinity"
        timeout: 600

    - name: Audit TensorFlow Text wheels
      community.docker.docker_container_exec:
        container: "tf-text-audit"
        command: /bin/bash -c /tmp/workspace/scripts/audit_tf_text_wheels.sh
        chdir: "/tmp/workspace/text-{{ tensorflow_text_version }}"

    - name: Stop audit container
      community.docker.docker_container:
        name: "tf-text-audit"
        image: "quay.io/pypa/manylinux2014_aarch64"
        state: absent
        timeout: 600
