---
- name: Zip the repository
  ansible.builtin.command: ../files/export-repo.sh
  changed_when: false
  delegate_to: localhost
  run_once: true

- name: Ensure that the devops directory exists
  become: true
  ansible.builtin.file:
    path: "{{ devops_dir }}"
    mode: "0775"
    state: directory

- name: Remove directory if same version already exists
  become: true
  ansible.builtin.file:
    path: "{{ devops_dir }}/{{ feature_version }}"
    state: absent

- name: Create directory for current version
  become: true
  ansible.builtin.file:
    path: "{{ devops_dir }}/{{ feature_version }}"
    mode: "0755"
    state: directory

- name: Create app directory for current version
  become: true
  ansible.builtin.file:
    path: "{{ devops_dir }}/{{ feature_version }}/app"
    mode: "0755"
    state: directory

- name: Create scripts directory for current version
  become: true
  ansible.builtin.file:
    path: "{{ devops_dir }}/{{ feature_version }}/scripts"
    mode: "0755"
    state: directory

- name: Upload the zip file to the remote server
  become: true
  ansible.builtin.copy:
    src: "../../../dist/octopus.zip"
    dest: "/tmp/octopus.zip"
    mode: "0755"

- name: Unzip folder on the remote server
  become: true
  ansible.builtin.unarchive:
    src: "/tmp/octopus.zip"
    dest: "{{ devops_dir }}/{{ feature_version }}/app"
    remote_src: true

- name: Copy ecoffice.sh to scripts folder
  become: true
  ansible.builtin.copy:
    src: "{{ devops_dir }}/{{ feature_version }}/app/scripts/ecoffice.sh"
    dest: "{{ devops_dir }}/{{ feature_version }}/scripts/ecoffice.sh"
    mode: "0755"
    remote_src: true
