Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
.gitlab-ci.yml 2.67 KiB
---
default:
  image: node:20.10.0
  tags:
    - docker

stages:
  - setup
  - check
  - build
  - test
  - deploy

include:
  - project: "ics-infrastructure/gitlab-ci-yml"
    file: "PreCommit.gitlab-ci.yml"
  - project: "ics-infrastructure/gitlab-ci-yml"
    file: "SonarScanner.gitlab-ci.yml"

variables:
  CONTAINER_IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME"
  CYPRESS_CACHE_FOLDER: "$CI_PROJECT_DIR/cache/Cypress"
  npm_config_cache: "$CI_PROJECT_DIR/.npm"

install-dependencies:
  stage: setup
  script:
    - npm ci
  artifacts:
    paths:
      - .cache/*
      - cache/Cypress
      - node_modules
      - .npm

run-pre-commit:
  needs:
    - job: install-dependencies
      artifacts: true

lint:
  stage: check
  script:
    - npm run code-quality
  artifacts:
    reports:
      codequality: gl-codequality.json

build-container:
  stage: build
  image: docker:latest
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  script:
    - docker build -t $CONTAINER_IMAGE --build-arg REACT_APP_MUI_PRO_LICENSE_KEY=${REACT_APP_MUI_PRO_LICENSE_KEY} .
    - docker push $CONTAINER_IMAGE
  needs:
    - job: install-dependencies
      artifacts: true

build-storybook:
  stage: build
  script:
    - npm run build-storybook
  needs:
    - job: install-dependencies
      artifacts: true
  artifacts:
    paths:
      - storybook-static

run-sonar-scanner:
  stage: test
  needs:
    - job: build-container

.test-components:
  stage: test
  image: cypress/browsers:node-20.10.0-chrome-118.0.5993.88-1-ff-118.0.2-edge-118.0.2088.46-1
  script:
    - npm ci
    - npm start &
    - CHOKIDAR_USEPOLLING=true WATCHPACK_POLLING=true npx cypress run --component --browser ${BROWSER}
  needs: [] # no requirements since it does an install
  artifacts:
    when: on_failure
    paths:
      - cypress/videos
      - cypress/screenshots

test-components-chrome:
  extends: .test-components
  variables:
    BROWSER: chrome

test-components-firefox:
  extends: .test-components
  variables:
    BROWSER: firefox

.deploy:
  stage: deploy
  image: registry.esss.lu.se/ics-docker/awxkit
  script:
    - >
      awx job_templates launch deploy-ccce-${INSTANCE}
      --extra_vars "ce_deploy_ui_container_image_tag: $CI_COMMIT_REF_NAME"
      --job_tags ce-deploy-ui
      --monitor
  needs:
    - build-container
  environment:
    name: ${INSTANCE}
    url: https://ce-deploy-${INSTANCE}.cslab.esss.lu.se/
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: never
    - if: $CI_COMMIT_BRANCH || $CI_COMMIT_TAG
      when: manual

deploy-to-test:
  extends: .deploy
  variables:
    INSTANCE: test

deploy-to-demo:
  extends: .deploy
  variables:
    INSTANCE: demo