---

image: registry.ubicast.net/mediaserver/envsetup

stages:
  - docker
  - lint
  - test

before_script:
  - make install-dev

docker:build:
  image: docker:stable
  stage: docker
  tags:
    - docker
  rules:
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME == "master"'
      changes:
        - .devcontainer/Dockerfile
        - requirements.dev.txt
  before_script:
    - apk add bash make
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.ubicast.net
  script:
    - make docker-build
    - make docker-push

docker:rebuild:
  image: docker:stable
  stage: docker
  tags:
    - docker
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
    - if: '$CI_PIPELINE_SOURCE == "web"'
  before_script:
    - apk add bash make
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.ubicast.net
  script:
    - make docker-build
    - make docker-push

lint:
  image: registry.ubicast.net/mediaserver/envsetup
  stage: lint
  tags:
    - docker
  rules:
    - if: '$CI_PIPELINE_SOURCE == "web"'
    - if: '$CI_PIPELINE_SOURCE == "merge_requests"'
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME == "master"'
      changes:
        - "*.yml"
        - "*.py"
  script:
    - make lint

test:
  image: registry.ubicast.net/mediaserver/envsetup:root
  stage: test
  tags:
    - docker
  rules:
    - if: '$CI_PIPELINE_SOURCE == "web"'
    - if: '$CI_PIPELINE_SOURCE == "merge_requests"'
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME == "master"'
      changes:
        - inventories/**/*
        - library/**/*
        - molecule/**/*
        - playbooks/**/*
        - plugins/**/*
        - roles/**/*
  script:
    - make test

...
