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
  tags:
    - linux
  before_script:
    - curl https://sh.rustup.rs -sSf | sh -s -- -y
    - source "$HOME/.cargo/env"
  script:
    - cd rust-src
    - cargo check
    - rustup component add clippy
    - cargo clippy -- -Dwarnings

wasm_build:
  tags:
    - linux
  stage: wasm
  extends:
    - .build_base
  before_script:
    - curl https://sh.rustup.rs -sSf | sh -s -- -y
    - source "$HOME/.cargo/env"
    - 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
