stages:
    - release
    - build

variables:
    VLC_VERSION: "3.0"
    VLC_DEBIAN_IMAGE: registry.videolan.org/vlc-debian-unstable:20200529132440
    VLC_PATH: /Users/videolanci/sandbox/bin

############
## Builds ##
############

.continous-job-base:
    stage: build
    only:
        - merge_requests
    interruptible: true

.continous-build-base:
    script:
        - ./buildMobileVLCKit.sh -${BUILD_PARAM}
    after_script:
        - rm -rf build/ || true
        - rm -rf libvlc/vlc || true
        - rm -rf *-binary || true

continous-MobileVLCKit:
    tags:
        - macos-m1
    extends:
        - .continous-job-base
        - .continous-build-base
    variables:
        BUILD_PARAM: "vf3"
        JOB_NAME: "MobileVLCKit"

continous-TVVLCKit:
    tags:
        - macos-xcode15
    extends:
        - .continous-job-base
        - .continous-build-base
    variables:
        BUILD_PARAM: "vft"
        JOB_NAME: "TVVLCKit"

continous-VLCKit:
    tags:
        - macos-xcode15
    extends:
        - .continous-job-base
        - .continous-build-base
    variables:
        BUILD_PARAM: "vx"
        JOB_NAME: "VLCKit"

############################################################
## Development artifacts builds                           ##
## These are running every time a merge request is merged ##
## or a commit gets pushed to the default branch          ##
############################################################

.dev-artifacts-job-base:
    stage: build
    rules:
        - if: '$CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_PATH == "videolan/VLCKit"'
        - if: '$CI_COMMIT_TAG'
          when: never

    artifacts:
        paths:
            - ./*.tar.xz

.dev-artifacts-build-base:
    script:
        - ./buildMobileVLCKit.sh -${BUILD_PARAM}
        - ./Packaging/create-distributable-package.sh -${PACKAGING_PARAM}
        - mv ${JOB_NAME}-*.tar.xz ${JOB_NAME}-${VLC_VERSION}-`date +%Y%m%d-%H%M`.tar.xz
    after_script:
        - rm -rf build/ || true
        - rm -rf libvlc/vlc || true
        - rm -rf *-binary || true

dev-artifacts-MobileVLCKit:
    tags:
        - macos-m1
    extends:
        - .dev-artifacts-job-base
        - .dev-artifacts-build-base
    variables:
        BUILD_PARAM: "vf3"
        PACKAGING_PARAM: "vm"
        JOB_NAME: "MobileVLCKit"

dev-artifacts-TVVLCKit:
    tags:
        - macos-xcode15
    extends:
        - .dev-artifacts-job-base
        - .dev-artifacts-build-base
    variables:
        BUILD_PARAM: "vft"
        PACKAGING_PARAM: "vt"
        JOB_NAME: "TVVLCKit"

dev-artifacts-VLCKit:
    tags:
        - macos-xcode15
    extends:
        - .dev-artifacts-job-base
        - .dev-artifacts-build-base
    variables:
        BUILD_PARAM: "vx"
        PACKAGING_PARAM: "v"
        JOB_NAME: "VLCKit"

#########
## doc ##
#########

pages:
    tags:
        - docker
        - amd64
    stage: build
    rules:
        - if: '$CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_PATH == "videolan/VLCKit"'
    image:
        name: $VLC_DEBIAN_IMAGE
    script:
        - doxygen doxygen.conf
        - mkdir public
        - cp -r doc/html/* public/
    artifacts:
        paths:
            - public

####################
## Release builds ##
####################

.release-job-base:
    stage: release
    only:
        - tags
    artifacts:
        paths:
            - ./*.tar.xz

.release-build-base:
    script:
        - cd Packaging
        - ./buildAndDeployFrameworks.sh -${BUILD_PARAM}
    after_script:
        - rm -rf build/ || true
        - rm -rf libvlc/vlc || true
        - rm -rf *-binary || true

MobileVLCKit:
    tags:
        - macos-m1
    extends:
        - .release-job-base
        - .release-build-base
    variables:
        BUILD_PARAM: "m"

TVVLCKit:
    tags:
        - macos-xcode15
    extends:
        - .release-job-base
        - .release-build-base
    variables:
        BUILD_PARAM: "t"

VLCKit:
    tags:
        - macos-xcode15
    extends:
        - .release-job-base
        - .release-build-base
    variables:
        BUILD_PARAM: "x"
