clone:
  git:
    image: plugins/git
    recursive: false

pipeline:

  pull_build:
    image: sots:latest
    secrets: [ssh_private_key, ssh_known_hosts, ssh_host]
    commands:
      - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
      - eval $(ssh-agent -s)
      - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
      - mkdir -p ~/.ssh
      - chmod 700 ~/.ssh
      - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
      - chmod 644 ~/.ssh/known_hosts
      - echo "$SSH_HOST" > ~/.ssh/config
      - git submodule sync --recursive
      - git submodule update --init

      - mkdir -p ../tools
      - rm -rf ../tools/v_tools
      - cp -r /sots-tools/v_tools ../tools
      - rm -f /base/bpre0.gba
      - cp /bpre0.gba ./base/bpre0.gba
      - chmod 644 ./base/bpre0.gba
      
      - make -j4 all

  build_story:
    image: xelatex:latest
    commands:
      - cd sots-private/story && make
      - mv build/story.pdf build/master.pdf

  deploy_story:
    image: appleboy/drone-scp
    host: gitlab.karathan.at
    port: 22
    strip_components: 3
    target: /var/www/sots/story/
    source: sots-private/story/build/master.pdf
    secrets: [ ssh_password, ssh_username ]
