stages:
  - build
  - publish

build_guide:
  stage: build
  image: alpine
  script:
    - apk update
    - apk add ruby 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_guide:
  stage: publish
  image: kroniak/ssh-client
  before_script:
    - apk add rsync
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - eval $(ssh-agent -s)
    - echo -n "$SSH_PRIVATE_KEY" | ssh-add -
    - ssh-keyscan -H "$PUBLISH_HOST" >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
  script:
    - 'rsync -av angelguide_*.pdf $PUBLISH_USER@$PUBLISH_HOST:$PUBLISH_PATH'
#  rules:
#    - if: '$CI_COMMIT_REF_NAME == "master"'
#      when: on_success
#    - when: never
