default:
  image: cosmomyzrailgorynych/docker-nw-builder:node-20
  # Caching settigns for NPM, according to https://docs.gitlab.com/ee/ci/caching/index.html#cache-nodejs-dependencies
  before_script:
    - npm ci --cache .npm --prefer-offline
  cache:
    key: $CI_COMMIT_REF_SLUG
    paths:
      - node_modules
      - app/node_modules
      - .npm/
stages:
  - test
  - pack

workflow:
  rules:
    # Skip WIPs
    - if: $CI_COMMIT_MESSAGE =~ /WIP/
      when: never
    # Include PRs
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    # Skip duplication for merge requests to develop, master, v1.x
    - if: '$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS'
      when: never
    # Include develop, master, v1.x direct pushes
    - if: $CI_COMMIT_BRANCH == "develop"
    - if: $CI_COMMIT_BRANCH == "master"
    - if: $CI_COMMIT_BRANCH == "v1.x"
    # For testing
    - if: $CI_COMMIT_BRANCH == "gitlab-ci"

preinstall:
  stage: .pre
  script:
    - "npm install"
    - "gulp -f devSetup.gulpfile.js"

lint:
  needs: ["preinstall"]
  stage: test
  script:
    - gulp lint

build:
  needs: ["preinstall"]
  stage: test
  script:
    - gulp build

pack-deploy-release:
  tags: [ "saas-linux-medium-amd64" ]
  stage: pack
  needs: ["lint", "build"]
  script:
    - gulp -f devSetup.gulpfile.js
    - gulp deploy --buildNum=$CI_COMMIT_TAG
  only:
    - tags
    - master

pack-deploy-nightly:
  stage: pack
  needs: ["lint", "build"]
  rules:
    - if: $CI_COMMIT_BRANCH == "develop"
  script:
    - npm i -g gulp-cli
    - gulp -f devSetup.gulpfile.js
    - gulp packages --nightly --buildNum=$CI_COMMIT_SHORT_SHA
    - gulp deployItchOnly --nightly --buildNum=$CI_COMMIT_SHORT_SHA

