#!/usr/bin/env execlineb
# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
# SPDX-License-Identifier: BSD-2-Clause

elgetopt "c:"
importas -D "cargo" default_cargo CARGO
importas -D $default_cargo CARGO ELGETOPT_c
backtick -E version {
  pipeline {
    $CARGO metadata --format-version 1
  }
  jq -r ".packages[] | select(.name == \"media-type-version\") | .version"
}
if {
  $CARGO fmt --check
}
if {
  $CARGO fc build
}
if {
  $CARGO doc --no-deps --all-features
}
if {
  $CARGO fc nextest run
}
if {
  backtick -E -I nix_shell_version {
    redirfd -w 2 /dev/null
    nix-shell --version
  }
  ifelse {
    eltest $? -ne 0 -o -z $nix_shell_version
  } {
    echo "No nix-shell program, skipping reuse"
  }
  nix-shell --pure -p git -p reuse --run "reuse lint"
}
if {
  if {
    rm -rf target/package
  }
  if {
    $CARGO publish --dry-run
  }
  cd "target/package/media-type-version-${version}"
  if {
    $CARGO test
  }
  cd "../mtv-extract-${version}"
  if {
    $CARGO --config "patch.\"crates-io\".\"media-type-version\".path=\"../media-type-version-${version}\"" test
  }
  cd "../test-mtv-data-${version}"
  $CARGO --config "patch.\"crates-io\".\"media-type-version\".path=\"../media-type-version-${version}\"" test
}
if {
  rust/tools/el-run-clippy -c $CARGO -n
}
echo "Seems fine"
