---
- hosts: all
  tasks:
    - name: Read project docs configuration
      ansible.builtin.include_vars: "{{ docs_update_data_file }}"

    - name: Detect list of changes
      ansible.builtin.command: "git log -1 --name-only --pretty="
      args:
        chdir: "{{ zuul.project.src_dir }}"
      register: git_log
      ignore_errors: true
      changed_when: false

    - name: Verify document matches the one in the current HC
      ansible.builtin.include_role:
        name: "compare"
      vars:
        compare_html_location: "{{ doc.1.html_location }}"
        compare_hc_location: "{{ doc.1.hc_location }}"
        doc_label: "{{ doc.0.service_type }}_{{ doc.1.type }}"
      loop: "{{ categories | json_query('*') | flatten | subelements('docs') }}"
      loop_control:
        loop_var: "doc"
        label: "{{ doc.0.service_type }}_{{ doc.1.type }}"
      when:
        - "doc.1.html_location is defined"
        - "doc.1.hc_location is defined"
        - |
          git_log.stdout is search(doc.1.html_location)
