stages:
  - test
  - publish

include:
  - template: Dependency-Scanning.gitlab-ci.yml
  - template: SAST.gitlab-ci.yml
  - template: Code-Quality.gitlab-ci.yml

sast:
  variables:
    SAST_EXCLUDED_PATHS: test/**

code_quality:
  rules:
    - if: '$CI_COMMIT_TAG'
      when: never

lint-node:
 image: node
 stage: test
 tags:
   - docker
 script:
   - npm install -g eslint
   - eslint --ignore-pattern "**/*.min.js" "$CI_PROJECT_DIR/lib"

test-node:
  coverage: '/Statements\s*:\s*(\d+(?:\.\d+)?\%)/'
  image: node:16-alpine
  stage: test
  artifacts:
    paths: [coverage]
  tags:
    - docker
  script:
    - npm i -g mocha nyc
    - npm ci .
    - npm run coverage

lint-deno:
 image: denoland/deno:alpine-1.22.2
 stage: test
 tags:
   - docker
 script:
   - cd deno
   - deno lint --unstable --ignore=test.js

# test-deno:
#   coverage: '/(\d+\.\d+\%)/'
#   image: denoland/deno:alpine-1.22.2
#   stage: test
#   tags:
#     - docker
#   script:
#     - cd deno
#     - deno test --allow-read --allow-write --coverage --unstable

# Publish package to NPM.
publish:
  stage: publish
  image: node
  tags:
    - docker
  only:
    - tags
    - triggers
  script:
    - npm set //registry.npmjs.org/:_authToken $NPM_TOKEN
    - npm publish
