pipeline:
  build:
    image: docker.io/logicalhacking/isabelle2022
    commands:
      - ./.woodpecker/check_dangling_theories
      - ./.woodpecker/check_external_file_refs
      - ./.woodpecker/check_quick_and_dirty
      - export ARTIFACT_DIR=$CI_WORKSPACE/.artifacts/$CI_REPO/$CI_BRANCH/$CI_BUILD_NUMBER/$LATEX
      - mkdir -p $ARTIFACT_DIR
      - export `isabelle getenv ISABELLE_HOME_USER`
      - mkdir -p $ISABELLE_HOME_USER/etc
      - echo "ISABELLE_PDFLATEX=\"$LATEX --file-line-error\"" >> $ISABELLE_HOME_USER/etc/settings
      - isabelle build -x HOL-Proofs -x Isabelle_DOF-Proofs -D . -o browser_info
      - if [ "$LATEX" = "lualatex" ]; then isabelle build -o 'timeout_scale=2' -D . -o browser_info; else echo "Skipping Isabelle_DOF-Proofs for pdflatex build."; fi
      - find . -name 'root.tex' -prune -o -name 'output' -type f | xargs latexmk -$LATEX -cd  -quiet -Werror
      - isabelle components -u .
      - isabelle dof_mkroot -q DOF_test
      - isabelle build -D DOF_test
      - cp -r $ISABELLE_HOME_USER/browser_info $ARTIFACT_DIR
      - cd $ARTIFACT_DIR
      - cd ../..
      - ln -s * latest
  archive:
    image: docker.io/logicalhacking/isabelle2022
    commands:
      - export ARTIFACT_DIR=$CI_WORKSPACE/.artifacts/$CI_REPO/$CI_BRANCH/$CI_BUILD_NUMBER/$LATEX
      - mkdir -p $ARTIFACT_DIR
      - export ISABELLE_VERSION=`isabelle version`
      - ./.woodpecker/mk_release -d
      - cp Isabelle_DOF-Unreleased_$ISABELLE_VERSION.tar.xz $ARTIFACT_DIR/../
    when:
      matrix:
        LATEX: lualatex
  deploy:
    image: docker.io/drillster/drone-rsync
    settings:
      hosts: [ "ci.logicalhacking.com"]
      port: 22
      source: .artifacts/$CI_REPO_OWNER/*
      target: $CI_REPO_OWNER
      include: [ "**.*"]
      key:
        from_secret: artifacts_ssh
      user: artifacts
  notify:
    image: docker.io/drillster/drone-email
    settings:
      host: smtp.0x5f.org
      username: woodpecker
      password: 
        from_secret: email
      from: ci@logicalhacking.com
    when:
      status: [ failure ]    

matrix:
  LATEX:
  - lualatex      
  - pdflatex
