default:
  image: node:20-bookworm

  cache:
    paths:
      - node_modules

ci:
  stage: build
  before_script:
    # Without apt update, apt install fails.
    - apt update --yes

    # Install playwright dependencies.
    - apt install --yes libasound2 libatk-bridge2.0-0 libatspi2.0-0 libcups2 libdbus-1-3 libdrm2 libnss3 libgbm1 libxcomposite1 libwayland-client0 libxdamage1 libxfixes3 libxkbcommon0 libxrandr2

    # Install ssh-agent if not already installed, it is required by Docker.
    - "which ssh-agent || apt install -y openssh-client"
    # Run ssh-agent (inside the build environment)
    - eval $(ssh-agent -s)

    # `esbuild` 0.13.8 fails when rebuilding it twice.
    # => Reinstall it every time.
    - rm -Rf node_modules/esbuild
    #
    - npm install
    # Needed when Node version changes:
    - rm -f .env
    - ln -s example.env .env
    - npm rebuild
    - rm -f .env

    - npx playwright install chromium

    # Compile gitlab-ci TypeScript script.
    - npx tsc --declaration --project gitlab-ci/tsconfig.json
  script:
    # Execute gitlab-ci JavaScript script.
    - node --experimental-specifier-resolution=node gitlab-ci/build/gitlab-ci.js