taskvisor 0.0.11

Event-driven task orchestration with restart, backoff, and user-defined subscribers
Documentation
version: '3'

vars:
  git_root:
    sh: git rev-parse --show-toplevel

  rust_version: "1.90.0"
  cache_dir: ".cache"

tasks:
  default:
    desc: Default task.
    cmds:
      - echo "Please enter a task or use '-l' or '--list-all' to list all available tasks"
    silent: true

  # ================================================#
  # ---------------------INTERNAL-------------------#
  # ================================================#

  _docker/run:
    desc: Internal wrapper to run task in containers.
    internal: true
    silent: true
    requires:
      vars: [ IMAGE, CMD, MOUNT_DIR ]
    dir: "{{.git_root}}"
    cmd: |
      set -euo pipefail
      
      if ! docker image inspect "{{.IMAGE}}" >/dev/null 2>&1; then
        echo "pulling: {{.IMAGE}}"
      
        docker pull -q "{{.IMAGE}}" >/dev/null 2>&1 || {
          echo "Failed to pull image: {{.IMAGE}}"
          exit 1
        }
      fi
      docker run --rm --init --pull=never \
        --security-opt no-new-privileges \
        --user $(id -u):$(id -g) \
        --cap-drop=ALL \
        \
        --volume "{{.git_root}}/{{.MOUNT_DIR}}:/workspace:rw" \
        {{if .VOLUMES}}{{range $vol := .VOLUMES}}--volume {{$vol}} {{end}}{{end}} \
        {{if .ENVS}}{{range $env := .ENVS}}--env "{{$env}}" {{end}}{{end}} \
        \
        --workdir /workspace \
        {{.IMAGE}} \
        {{.CMD}}

  _cargo/tool:
    desc: Internal wrapper for running cargo tools.
    internal: true
    silent: true
    requires:
      vars: [ CMD ]
    cmds:
      - cmd: mkdir -p "{{.git_root}}/{{.cache_dir}}"
      - task: _docker/run
        vars:
          IMAGE: "ghcr.io/soltihq/cargo-tools:{{.rust_version}}"
          CMD: "{{.CMD}}"
          MOUNT_DIR: "."
          VOLUMES:
            - "{{.git_root}}/{{.cache_dir}}:/tmp/{{.cache_dir}}"
          ENVS:
            - "CARGO_TARGET_DIR=/tmp/{{.cache_dir}}/target"
            - "CARGO_HOME=/tmp/{{.cache_dir}}/cargo"
            - "RUSTUP_TOOLCHAIN={{.rust_version}}"
            - "RUSTUP_NO_UPDATE_CHECK=1"
            - "CARGO_INCREMENTAL=0"
            - "RUSTFLAGS=-D warnings"

  # ================================================#
  # ----------------------PUBLIC--------------------#
  # ================================================#

  cargo/fmt:
    desc: Run 'cargo fmt'.
    silent: true
    cmds:
      - task: _cargo/tool
        vars:
          CMD: "fmt --check --verbose"

  cargo/check:
    desc: Run 'cargo check'.
    silent: true
    cmds:
      - task: _cargo/tool
        vars:
          CMD: "check"

  cargo/clippy:
    desc: Run 'cargo clippy'.
    silent: true
    cmds:
      - task: _cargo/tool
        vars:
          CMD: "clippy --all --all-features -- -D warnings"

  cargo/test:
    desc: Run 'cargo test'.
    silent: true
    cmds:
      - task: _cargo/tool
        vars:
          CMD: "test --all --all-features"

  cargo/docs:
    desc: Run 'rustdoc'.
    silent: true
    cmds:
      - task: _cargo/tool
        vars:
          CMD: >-
            +nightly rustdoc --lib -Zrustdoc-map --features "logging controller"
            -Zunstable-options -Zrustdoc-scrape-examples
            --config 'build.rustdocflags=["--cfg","docsrs","-Z","unstable-options","--cap-lints","warn"]'

  cargo/audit:
    desc: Run 'audit'.
    silent: true
    cmds:
      - task: _cargo/tool
        vars:
          CMD: "audit"

  # ================================================#
  # ----------------------MANUAL--------------------#
  # ================================================#

  cargo/audit/fix:
    desc: Run 'audit' with auto fix
    silent: true
    cmds:
      - task: _cargo/tool
        vars:
          CMD: "audit fix"