<commit_before>include:
- template: Security/Dependency-Scanning.gitlab-ci.yml
- template: Security/License-Scanning.gitlab-ci.yml
- template: Security/SAST.gitlab-ci.yml
- template: Security/Secret-Detection.gitlab-ci.yml
- template: Container-Scanning.gitlab-ci.yml

image: node:12

stages:
- setup
- test
- docker
- deploy
- release

variables:
  CI_APPLICATION_REPOSITORY: $CI_REGISTRY_IMAGE

workflow:
  rules:
  - if: $CI_MERGE_REQUEST_ID
  - if: $CI_COMMIT_BRANCH == "master"
  - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/

cache:
  key: "$CI_COMMIT_REF_SLUG"
  paths:
  - node_modules/

setup-js:
  stage: setup
  script:
  - npm install

test-js:
  stage: test
  script:
  - npm run test

lint-js:
  stage: test
  script:
  - npm run lint

audit-js:
  stage: test
  script:
  - npm audit

site-generation:
  stage: test
  script:
  - ./bin/kuvia.js -o kuvia.html -r -d example

.docker-job:
  image: docker:latest
  services:
  - docker:dind
  before_script:
  - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY

build-docker:
  stage: docker
  extends: .docker-job
  variables:
    CONTAINER_IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA"
  script:
  - docker build -t $CONTAINER_IMAGE .
  - docker run --rm $CONTAINER_IMAGE
  - docker push $CONTAINER_IMAGE

pages:
  stage: deploy
  before_script:
  - mkdir -p public
  script:
  - cp -r example public/
  - cd public/example/
  - ../../bin/kuvia.js -o index.html -r -d . --no-min
  artifacts:
    paths:
    - public
  rules:
  - if: $CI_COMMIT_BRANCH == "master"

release-npm:
  stage: release
  before_script:
  - npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
  script:
  - npm publish
  rules:
  - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/

release-gitlab:
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  script:
  - release-cli create --name "Release ${CI_COMMIT_TAG}" --tag-name ${CI_COMMIT_TAG}
  rules:
  - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/<commit_msg>Limit node cache to node jobs<commit_after>include:
- template: Security/Dependency-Scanning.gitlab-ci.yml
- template: Security/License-Scanning.gitlab-ci.yml
- template: Security/SAST.gitlab-ci.yml
- template: Security/Secret-Detection.gitlab-ci.yml
- template: Container-Scanning.gitlab-ci.yml

image: node:12

stages:
- setup
- test
- docker
- deploy
- release

variables:
  CI_APPLICATION_REPOSITORY: $CI_REGISTRY_IMAGE

workflow:
  rules:
  - if: $CI_MERGE_REQUEST_ID
  - if: $CI_COMMIT_BRANCH == "master"
  - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/

.node-cache:
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
    - node_modules/

setup-js:
  stage: setup
  extends: .node-cache
  script:
  - npm install

test-js:
  stage: test
  extends: .node-cache
  script:
  - npm run test

lint-js:
  stage: test
  extends: .node-cache
  script:
  - npm run lint

audit-js:
  stage: test
  extends: .node-cache
  script:
  - npm audit

site-generation:
  stage: test
  extends: .node-cache
  script:
  - ./bin/kuvia.js -o kuvia.html -r -d example

.docker-job:
  image: docker:latest
  services:
  - docker:dind
  before_script:
  - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY

build-docker:
  stage: docker
  extends: .docker-job
  variables:
    CONTAINER_IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA"
  script:
  - docker build -t $CONTAINER_IMAGE .
  - docker run --rm $CONTAINER_IMAGE
  - docker push $CONTAINER_IMAGE

pages:
  stage: deploy
  extends: .node-cache
  before_script:
  - mkdir -p public
  script:
  - cp -r example public/
  - cd public/example/
  - ../../bin/kuvia.js -o index.html -r -d . --no-min
  artifacts:
    paths:
    - public
  rules:
  - if: $CI_COMMIT_BRANCH == "master"

release-npm:
  stage: release
  before_script:
  - npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
  script:
  - npm publish
  rules:
  - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/

release-gitlab:
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  script:
  - release-cli create --name "Release ${CI_COMMIT_TAG}" --tag-name ${CI_COMMIT_TAG}
  rules:
  - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/
{'fraction_non_alphanumeric': 0.14922894424673785, 'fraction_numerical': 0.009489916963226572, 'mean_word_length': 3.003798670465337, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4113191', 'n_tokens_mistral': 1789, 'n_tokens_neox': 1714, 'n_words': 349}