- name: Create runner folder
  file:
    path: "{{ runner_folder }}"
    state: directory

- name: Download runner archive
  get_url:
    url: "{{ runner_archive.url }}"
    dest: "{{ runner_folder }}/{{ runner_archive.name }}"
    checksum: "sha256:{{ runner_archive.sha256sum }}"

- name: Uncompress runner archive
  command:
    chdir: "{{ runner_folder }}"
    cmd: tar xzf {{ runner_archive.name }}
    creates: "{{ runner_folder }}/config.sh"

- name: Unconfigure previous runner if exists
  command:
    chdir: "{{ runner_folder }}"
    cmd: ./config.sh remove --pat {{ config_token }}
    removes: "{{ runner_folder }}/.credentials"

- name: Configure runner
  command:
    chdir: "{{ runner_folder }}"
    cmd: ./config.sh --unattended --url {{ github_url }} --pat {{ config_token }} --labels {{ labels }} --name {{ inventory_hostname }}

- name: Install gh (GitHub cli)
  homebrew:
    name:
      - gh

- import_role:
    name: asdf_setup
