image: python:latest

stages:
  - test
  - build
  - release

test:
  image: python:2.7-alpine
  stage: test
  before_script:
    - pip install -r requirements.txt
  script:
    - flake8
    - ./scripts/xgettext.sh

build:
  stage: build
  before_script:
    - apk update
    - apk add git make zip
    - git submodule update --init --depth=22
  script:
    - make
  only:
    - master

release:
  stage: release
  before_script:
    - apk update
    - apk add git make lftp zip
    - git submodule update --init --depth=22
  script:
    - make
    - make zipfiles
  after_script:
    - |
        lftp -c "open 'ftp://$FTP_USER:$FTP_PASS@$FTP_HOST'; \
        cd plugin.video.elementum; \
        mirror --reverse --verbose --exclude '.*' --exclude '.*/' --include-glob addon.xml; \
        mkdir -p -f $CI_BUILD_TAG; \
        cd $CI_BUILD_TAG; \
        mirror --reverse --verbose --exclude '.*' --exclude '.*/' --include-glob *.zip; \
        exit;"
  artifacts:
    paths:
    - plugin.video.elementum-${CI_BUILD_TAG:1}.zip
    - plugin.video.elementum-${CI_BUILD_TAG:1}.android_arm.zip
    - plugin.video.elementum-${CI_BUILD_TAG:1}.android_x64.zip
    - plugin.video.elementum-${CI_BUILD_TAG:1}.android_x86.zip
    - plugin.video.elementum-${CI_BUILD_TAG:1}.darwin_x64.zip
    - plugin.video.elementum-${CI_BUILD_TAG:1}.linux_arm.zip
    - plugin.video.elementum-${CI_BUILD_TAG:1}.linux_armv7.zip
    - plugin.video.elementum-${CI_BUILD_TAG:1}.linux_arm64.zip
    - plugin.video.elementum-${CI_BUILD_TAG:1}.linux_x64.zip
    - plugin.video.elementum-${CI_BUILD_TAG:1}.linux_x86.zip
    - plugin.video.elementum-${CI_BUILD_TAG:1}.windows_x64.zip
    - plugin.video.elementum-${CI_BUILD_TAG:1}.windows_x86.zip
  only:
    - tags
