default:
  image: swipl:latest
  # Gitlab-ci shared runner
  tags:
    - ci.inria.fr
    - small

stages:
  - test
  - release
  - deploy
  - publish

test:
  stage: test
  script:
  - swipl -g "global_test" -t halt test/doctest.plt

release_job:
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  rules:
    - if: $CI_COMMIT_TAG                 # Run this job when a tag is created
  script:
    - echo "running release job"
  release:                               # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties
    tag_name: '$CI_COMMIT_TAG'
    description: 'Release $CI_COMMIT_TAG'

pages:
  stage: deploy
  rules:
    - if: $CI_COMMIT_TAG                 # Run this job when a tag is created
  script:
    - mkdir /tmp/public
    - swipl -g "doc_save('.', [doc_root('/tmp/public'), recursive(true), if(true)])" -t halt
    - mv /tmp/public .
    # CI_PROJECT_ID 53810
    - swipl pack install -y gitlabci
    # for some reason the "app" is not found -> fixed in swipl 9.3.9
    - swipl gitlabci public/index.html
  artifacts:
    paths:
    - public/

publish:
  stage: publish
  rules:
    - if: $CI_COMMIT_TAG
  script:
    # pages are slow to update
    - sleep 120
    - swipl -g "pack_install('$CI_PAGES_URL/doctest-*.zip', [interactive(false)])." -t halt
