image: node:current-alpine

stages:
  - test
  - publish

code quality:
  stage: test
  script:
    - npm ci
    - npm run lint

npm outdated:
  stage: test
  script:
    - npm ci
    - npm outdated
  allow_failure: true

security scan:
  stage: test
  script:
    - npm audit --production
  allow_failure: false

test on nodejs lts:
  stage: test
  image: node:lts-alpine
  script:
    - npm it
  coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'

test & coverage:
  stage: test
  script:
    - npm it
  coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'
  artifacts:
    paths:
      - coverage/

coverage report:
  stage: publish
  dependencies:
    - test & coverage
  script:
    - mv coverage/lcov-report/ public/
  artifacts:
    paths:
      - public
  only:
    - master
  environment:
    name: coverage report
    url: https://demsking.gitlab.io/image-downloader

package:
  stage: publish
  script:
    - npm pack
  artifacts:
    paths:
      - ./*.tgz

publish:
  stage: publish
  only:
    - tags
    - triggers
  script:
    - echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc
    - npm publish
  environment:
    name: npm
    url: https://www.npmjs.com/package/image-downloader
