---

- name: Update pacman website
  hosts: localhost
  vars:
    pacman_version: '6.0.1'
    pacman_dir: '/srv/http/archweb/archlinux.org/pacman'
  tasks:
    - name: Create temp dir
      tempfile: state=directory suffix=pacman
      register: tempdir

    - name: fetch pacman tarball
      get_url: url=https://sources.archlinux.org/other/pacman/pacman-{{ pacman_version }}.tar.xz dest={{ tempdir.path }}/pacman.tar.xz

    - name: unpack tarball
      unarchive: src={{ tempdir.path }}/pacman.tar.xz dest={{ tempdir.path }}

    - name: build website
      command: "{{ item }}"
      args:
        chdir: "{{ tempdir.path }}/pacman-{{ pacman_version }}"
      loop:
        - meson -Ddoc=enabled build
        - ninja -C build doc/website.tar.gz

    - block:
      - name: create website directory
        file: state=directory owner=root group=root mode=0755 path={{ pacman_dir }}

      - name: upload website
        unarchive:
          src: "{{ tempdir.path }}/pacman-{{ pacman_version }}/build/doc/website.tar.gz"
          dest: "{{ pacman_dir }}"
          owner: nobody
          group: nobody
      delegate_to: archlinux.org
