stages:
  - test
  - deploy

# The Docker image that will be used to build your app
image: node:22.14.0
# Functions that should be executed before the build script is run
before_script:
  - npm i

pages:
  script:
    - npm run build
  artifacts:
    expire_in: 1 week
    paths:
      # The folder that contains the files to be exposed at the Page URL
      - public
  rules:
    # This ensures that only pushes to the default branch will trigger
    # a pages deploy
    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH

check:
  stage: test
  allow_failure: yes
  script:
    - npm i
    - npx svelte-kit sync
    - npx svelte-check

  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"

develop:
  artifacts:
    expire_in: 1 week
    paths:
      - public

  environment:
    name: review/$CI_COMMIT_REF_SLUG
    url: https://$CI_PROJECT_NAMESPACE.pages.inpt.fr/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/index.html

  script:
    - ENVIRONMENT_URL=$CI_ENVIRONMENT_URL npm run build

  stage: deploy
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"

  variables:
    PUBLIC_URL: /-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public
