steps:
  render-site:
    image: ghcr.io/quarto-dev/quarto:1.7.22
    commands:
      - cd /woodpecker/src/git.polarolouis.fr/polarolouis/site-perso
      - quarto render
    when:
      event:
        - push
        - pull_request
      branch:
        - main
  # Push le contenu du dossier public sur le dépôt `pages` de git.polarolouis.fr
  # On utilise l'image alpine/git pour avoir git et ssh

  deploy-site:
    image: alpine/git
    commands:
      - git config --global --add safe.directory /woodpecker/src/git.polarolouis.fr/polarolouis/site-perso
      - git config --global --add safe.directory /woodpecker/src/git.polarolouis.fr/polarolouis/pages
      - git config --global user.name "Woodpecker CI"
      - git config --global user.email "git@polarolouis.fr"
      - cd /woodpecker/src/git.polarolouis.fr/polarolouis/
      - git clone "https://git.polarolouis.fr/polarolouis/pages.git"
      - rm -rf pages/*
      - cp -r site-perso/public/* pages/
      - cp site-perso/.domains pages/
      - cd pages
      - ls -la
      - git remote set-url origin "https://$${ACCESS_TOKEN}@git.polarolouis.fr/polarolouis/pages.git"
      - git add --all
      - git commit -m "Deploy site [CI SKIP]"
      - git push -f origin main
    environment:
      ACCESS_TOKEN:
        from_secret: access_token
    when:
      event:
        - push
        - pull_request
      branch:
        - main
    depends_on:
      - render-site
