image: node:22

default:
  interruptible: true

stages:
  - build
  - deploy

build:
  stage: build
  before_script:
    - yarn install --ignore-scripts
    - apt-get update -y && apt-get install -y zip
  script:
    - yarn lint
    - yarn i18n && git diff --quiet || (echo "Locale files are out of date. Please run `yarn i18n`" && exit 1)
    - NODE_ENV=production yarn build
    - cp dist/index.html dist/404.html
    - cd dist && zip -r ../soapbox.zip . && cd ..
  artifacts:
    paths:
     - soapbox.zip

review:
  stage: deploy
  environment:
    name: review/$CI_COMMIT_REF_NAME
    url: https://$CI_COMMIT_REF_SLUG.git.soapbox.pub
  before_script:
    - apt-get update -y && apt-get install -y unzip
  script:
    - unzip soapbox.zip -d dist
    - npx -y surge dist $CI_COMMIT_REF_SLUG.git.soapbox.pub
  allow_failure: true
  when: manual

pages:
  stage: deploy
  before_script:
    - apt-get update -y && apt-get install -y unzip
  script:
    # artifacts are kept between jobs
    - unzip soapbox.zip -d public
  variables:
    NODE_ENV: production
  artifacts:
    paths:
    - public
  only:
    variables:
      - $CI_DEFAULT_BRANCH == $CI_COMMIT_REF_NAME