---
kind: pipeline
name: Opytex 2022-2023
type: docker

clone:
  skip_verify: true

workspace:
    path: /drone/content/

steps:
- name: Push Raw
  image: alpine
  commands:
  - apk add --no-cache openssh-client ca-certificates bash
  - apk add rsync
  - echo Début du Push
  - eval `ssh-agent -s`
  - echo "$SSH_KEY" | ssh-add -
  - mkdir -p ~/.ssh
  - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
  - rsync -rv --delete -e "ssh -p 22" --exclude ".git" --exclude "config*" --exclude "*/Evaluations/DS*" --exclude "tools/" --exclude "*.rst" --exclude "*.tex" ./ sshcontent@91.121.90.228:~/raw.opytex.org/www/ --checksum
  environment:
    SSH_KEY:
      from_secret: sshcontent-key

- name: Build Opytex 2022-2023
  image: python:3.8-alpine
  commands:
  - apk add --no-cache git imagemagick-dev imagemagick
  - cd ..
  - git init .
  - git remote add origin https://git.opytex.org/lafrite/site_opytex.git
  - git pull origin 2022-2023
  - git checkout 2022-2023
  - git submodule init
  - git submodule update
  - pip install --no-cache-dir -r requirements.txt
  - export MAGICK_HOME=/usr
  - pelican content/ -o output -s publishconf.py --relative-urls

  - apk add --no-cache openssh-client ca-certificates bash rsync
  - eval `ssh-agent -s`
  - echo "$SSH_KEY" | ssh-add -
  - mkdir -p ~/.ssh
  - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
  - ssh sshcontent@91.121.90.228 'mkdir -p ~/raw.opytex.org/www/enseignements/2022-2023/'
  - rsync -rv --delete -e "ssh -p 22" ./output/ sshcontent@91.121.90.228:~/opytex.org/www/enseignements/2022-2023/ --checksum
  environment:
    SSH_KEY:
      from_secret: sshcontent-key
