stages:
  - install
  - rs_check_lint
  - wasm
  - ts_check_lint
  - test
  - build
  - deploy

npm_ci:
  stage: install
  tags:
    - linux
  script: npm ci
  artifacts:
    paths:
      - node_modules

.build_base:
  tags:
    - linux
  dependencies:
    - npm_ci

rs_check_lint:
  stage: rs_check_lint
  image: rust:latest
  tags:
    - linux
  script:
    - cd rust-src
    - cargo check
    - rustup component add clippy
    - cargo clippy -- -Dwarnings

wasm_build:
  tags:
    - linux
  image: rust:latest
  stage: wasm
  extends:
    - .build_base
  before_script:
    - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
  script:
    - wasm-pack build ./rust-src --target web
  artifacts:
    paths:
      - rust-src/pkg
      - node_modules

ts_check_lint:
  dependencies:
    - npm_ci
    - wasm_build
  stage: ts_check_lint
  tags:
    - linux
  script:
    - npx tsc
    - npm run lint

npm_build:
  dependencies:
    - wasm_build
  stage: build
  image: git-registry.mycard.moe/mycard/docker-runner-base:master-x86
  tags:
    - linux
  script:
    - cp neos.config.prod.json neos.config.json
    - npm run build:prod
  artifacts:
    paths:
      - dist

deploy:
  stage: deploy
  tags:
    - linux
  only:
    - main
  dependencies:
    - npm_build
  script:
    - mv neos-assets dist/
    - aws s3 --endpoint=https://minio.mycard.moe:9000 sync --delete dist/ s3://mycard/neos
