pipeline:
  prepare:task:
    image: rust:latest
    commands:
      - mkdir .ci_tmp
      - sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b .ci_tmp

  build:backend:
    group: build
    image: rust:latest
    commands:
      - rustc --version && cargo --version
      - ./.ci_tmp/task build:backend
    # volumes:
    #   - rust_registry:/usr/local/cargo
    when:
      path:
        - migrations/**/*
        - src/**/*
        - Cargo.lock
        - Taskfile.yml

  build:frontend:
    group: build
    image: node:lts
    commands:
      - node --version && npm --version
      - ./.ci_tmp/task build:frontend
    when:
      path:
        - webui/**/*
        - Taskfile.yml

  lint:backend:
    group: lint
    image: rust:latest
    commands:
      - rustup component add clippy
      - ./.ci_tmp/task lint:backend
      - git status -vvv
    # volumes:
    #   - rust_registry:/usr/local/cargo
    when:
      path:
        - migrations/**/*
        - src/**/*
        - Cargo.lock
        - Taskfile.yml

  lint:frontend:
    group: lint
    image: node:lts
    commands:
      - node --version && npm --version
      - ./.ci_tmp/task lint:frontend
    when:
      path:
        - webui/**/*
        - Taskfile.yml

  lint:jslib:
    group: lint
    image: node:lts
    commands:
      - node --version && npm --version
      - ./.ci_tmp/task lint:jslib
    when:
      path:
        - tools/upend_js/**/*
        - Taskfile.yml

  lint:webext:
    group: lint
    image: node:lts
    commands:
      - node --version && npm --version
      - ./.ci_tmp/task lint:webext
    when:
      path:
        - webext/**/*
        - Taskfile.yml

  test:backend:
    group: test
    image: rust:latest
    commands:
      - curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C /usr/local/cargo/bin
      - ./.ci_tmp/task test:backend
    # volumes:
    #   - rust_registry:/usr/local/cargo
    when:
      path:
        - migrations/**/*
        - src/**/*
        - Cargo.lock
        - Taskfile.yml

  package:
    group: release
    image: rust:latest
    commands:
      - cd ./.ci_tmp/
      - wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
      - chmod +x linuxdeploy-x86_64.AppImage
      - ./linuxdeploy-x86_64.AppImage --appimage-extract
      - ln -s $PWD/squashfs-root/AppRun /usr/local/bin/linuxdeploy-x86_64.AppImage
      - cd -
      - git status -vvv
      - ./.ci_tmp/task package
    when:
      event: [tag]

  publish:
    image: woodpeckerci/plugin-gitea-release
    settings:
      base_url: https://git.thm.place
      files:
        - "*.AppImage"
      checksum: sha512
      api_key:
        from_secret: API_KEY
      target: main
    when:
      event: [tag]
