stages:
  - build
  - publish

build_guide:
  stage: build
  image: ubuntu:latest
  script:
    - apt update
    - apt install -y --no-install-recommends asciidoctor
    - gem install asciidoctor-pdf --pre
    - asciidoctor-pdf -o angelguide_en.pdf guide.adoc
    - asciidoctor-pdf -a lang=de -o angelguide_de.pdf guide.adoc
  artifacts:
    paths:
      - "angelguide_en.pdf"
      - "angelguide_de.pdf"
    expire_in: 12 months

publish_artifacts:
  stage: publish
  image: ubuntu:latest
  before_script:
    - '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 -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
  script:
    - 'rsync -v angelguide_??.pdf $PUBLISHING_HOST:'
  rules:
    - if: '$CI_COMMIT_REF_NAME == "master"'
      when: always
    - when: never
