---
include:
  # Using the local file option parameter is probably better, but it breaks the
  # pre-commit hook. This can also be better if you're working on different
  # branches but want to use the hooks from the master branch.
  # yamllint disable-line rule:line-length
  - remote: |-
      https://git.shore.co.il/shore/ci-templates/-/raw/master/templates/pre-commit.yml
  - remote: |-
      https://git.shore.co.il/shore/ci-templates/-/raw/master/templates/containerfiles.yml
  - remote: |-
      https://git.shore.co.il/shore/ci-templates/-/raw/master/templates/notify.yml

lint templates:
  image: registry.shore.co.il/ci-images:pre-commit
  stage: test
  before_script:
    # yamllint disable-line rule:line-length
    - python3 -m pip install --break-system-packages git+https://gitlab.com/devopshq/gitlab-ci-linter#v1.0.6
    - gitlab-ci-linter --help
  script:
    # yamllint disable rule:line-length
    - |
      for template in templates/*.yml
      do
        echo "Checking $template" >&2
        gitlab-ci-linter --server "$CI_SERVER_URL" --filename "$template" || EXITCODE=1
        echo
      done
      [ -z "${EXITCODE:-}" ]
    # yamllint enable rule:line-length
  variables:
    XDG_CACHE_HOME: "$CI_PROJECT_DIR/.cache"
  rules:
    - if: $CI_PIPELINE_SOURCE == "push"
      changes:
        - templates/*
  cache:
    paths:
      - .cache/

# bats image:

build-bats:
  extends: .container-build
  variables:
    CONTEXT: images/bats

push-bats:
  extends: .container-push
  variables:
    CONTEXT: images/bats
    IMAGE: ci-images
    TAG: bats
  needs:
    - job: build-bats
      artifacts: true

# docker image:

build-docker:
  extends: .container-build
  variables:
    CONTEXT: images/docker

push-docker:
  extends: .container-push
  variables:
    CONTEXT: images/docker
    IMAGE: ci-images
    TAG: docker
  needs:
    - job: build-docker
      artifacts: true

# hugo image:

build-hugo:
  extends: .container-build
  variables:
    CONTEXT: images/hugo

push-hugo:
  extends: .container-push
  variables:
    CONTEXT: images/hugo
    IMAGE: ci-images
    TAG: hugo
  needs:
    - job: build-hugo
      artifacts: true

# k8s image:

build-k8s:
  extends: .container-build
  variables:
    CONTEXT: images/k8s

push-k8s:
  extends: .container-push
  variables:
    CONTEXT: images/k8s
    IMAGE: ci-images
    TAG: k8s
  needs:
    - job: build-k8s
      artifacts: true

# pre-commit image:

build-pre-commit:
  extends: .container-build
  variables:
    CONTEXT: images/pre-commit

push-pre-commit:
  extends: .container-push
  variables:
    CONTEXT: images/pre-commit
    IMAGE: ci-images
    TAG: pre-commit
  needs:
    - job: build-pre-commit
      artifacts: true

# python3 image:

build-python3:
  extends: .container-build
  variables:
    CONTEXT: images/python3

push-python3:
  extends: .container-push
  variables:
    CONTEXT: images/python3
    IMAGE: ci-images
    TAG: python3
  needs:
    - job: build-python3
      artifacts: true

# python3-build image:

build-python3-build:
  extends: .container-build
  variables:
    CONTEXT: images/python3-build

push-python3-build:
  extends: .container-push
  variables:
    CONTEXT: images/python3-build
    IMAGE: ci-images
    TAG: python3-build
  needs:
    - job: build-python3-build
      artifacts: true
