stages:
    - prep
    - build-assets
    - deploy-assets
    - build-website

default:
    image: ubuntu:22.04
    tags:
        - linux-x86_64
        - build
        - vtk-examples
    artifacts:
        expire_in: 1 day

build-vtk:
    image: $CI_REGISTRY/vtk/vtk-examples:20240604
    stage: prep
    cache:
        key: vtk-cache
        paths:
            - vtk_build
        policy: pull-push
    script:
        - bash .gitlab/ci/scripts/build_vtk.sh
    artifacts:
        paths: 
            - vtk_build/vtk
            - vtk_build/install

package-data:
    image: $CI_REGISTRY/vtk/vtk-examples:20240604
    stage: build-assets
    script:
        - bash .gitlab/ci/scripts/package_data.sh
    artifacts:
        paths:
            - packaged_data/

build-examples:
    image: $CI_REGISTRY/vtk/vtk-examples:20240604
    stage: build-assets
    dependencies:
        - build-vtk
    script:
        - bash .gitlab/ci/scripts/build_examples.sh
    artifacts:
        paths:
            - build_examples/

deploy-examples:
    rules:
        - if: '$CI_COMMIT_REF_NAME == "master"'
    needs:
        - build-examples
    stage: deploy-assets
    dependencies:
        - build-examples
    before_script:
        - bash .gitlab/ci/scripts/before_deploy_examples.sh
    script:
        - eval $(ssh-agent -s)
        - ssh-add $RSYNC_KEY
        - bash .gitlab/ci/scripts/deploy_examples.sh
    environment:
        name: deploy-examples
        url: https://web.kitware.com

deploy-data:
    rules:
        - if: '$CI_COMMIT_REF_NAME == "master"'
    needs:
        - package-data
    stage: deploy-assets
    dependencies:
        - package-data
    before_script:
        - bash .gitlab/ci/scripts/before_deploy_data.sh
    script:
        - eval $(ssh-agent -s)
        - ssh-add $RSYNC_KEY
        - bash .gitlab/ci/scripts/deploy_data.sh
    environment:
        name: deploy-examples
        url: https://web.kitware.com

build-gh-pages:
    rules:
        - if: '$CI_COMMIT_REF_NAME == "master"'
    stage: build-website
    needs:
        - deploy-examples
        - deploy-data
        - build-vtk
    dependencies:
        - build-vtk
    before_script:
        - bash .gitlab/ci/scripts/before_build_gh-pages.sh
    script:
        - eval $(ssh-agent -s)
        - ssh-add $GH_KEY
        - bash .gitlab/ci/scripts/build_gh-pages.sh
    environment:
        name: deploy-gh-pages
        url: https://github.com/Kitware/vtk-examples
