image: $BUILD_IMAGE

stages:
    - check
    - build
    - deploy

release_check:
    stage: check
    script:
        - build-aux/release-check
    only:
        - tags

build:
    stage: build
    script:
        - git submodule update --init --recursive
        - git clone https://gitlab.com/mikegerwitz/hoxsl
        - export SAXON_CP=/usr/share/ant/lib/saxon9/saxon9he.jar
        - export HOXSL=hoxsl
        - ./bootstrap
        - make all check info pdf html
    artifacts:
        paths:
            - doc/
            - tamer/target/*/tamec
            - tamer/target/*/tameld
            - tamer/target/doc
        expire_in: 30 min

build:doc:tpl:
    image: $BUILD_IMAGE_TEXLIVE
    stage: build
    script:
        - cd design/tpl/
        - make
    artifacts:
        paths:
            - design/tpl/tpl.pdf
        expire_in: 30 min

pages:
    stage: deploy
    script:
        - mkdir -p public/doc
        - mv doc/tame.html/* doc/tame.pdf doc/tame.info public/
        - mv tamer/target/doc public/tamer/
        - mkdir -p public/design
        - mv design/tpl/tpl.pdf public/design/
    artifacts:
        paths:
            - public/
        expire_in: 30 min
    only:
        - main
        - stage

ci:merge:
    stage: deploy
    script:
        - git config user.email "gitlab-ci@localhost"
        - git config user.name "GitLab CI"
        - git checkout main
        - git reset --hard origin/main
        - git merge --ff origin/stage
        # Do not trigger the pipeline after pushing; there's no use in
        # re-doing the work we just did, since the merge is a fast-forward.
        - git push -o ci.skip http://ci:$STAGE_MERGE_ACCESS_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git HEAD:main
    only:
        - stage

