# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=zizmor
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.19.0
pkgrel=1
pkgdesc="A static analysis tool for GitHub Actions (mingw-w64)"
url='https://github.com/zizmorcore/zizmor'
msys2_repository_url='https://github.com/zizmorcore/zizmor'
msys2_changelog_url='https://docs.zizmor.sh/release-notes/'
msys2_references=(
  'anitya: 378497'
  'archlinux: zizmor'
  'purl: pkg:cargo/zizmor'
)
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
source=("https://github.com/zizmorcore/${_realname}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('c9be8ca32ce657a692aab12b524e63b77c9d146058a4465ee9cf980da5a4cbe6')

prepare() {
  cd "${_realname}-${pkgver}"

  cargo fetch --locked --target "${RUST_CHOST}"
}

build() {
  cd "${_realname}-${pkgver}"

  cargo build --frozen --release -p zizmor
}

check() {
  cd "${_realname}-${pkgver}"

  cargo test --frozen --release -p zizmor
}

package() {
  cd "${_realname}-${pkgver}"

  install -Dm755 -t "${pkgdir}${MINGW_PREFIX}/bin" target/release/zizmor.exe

  local _complete="target/release/zizmor --completions"
  install -Dm644 <($_complete bash) "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/${_realname}"
  install -Dm644 <($_complete fish) "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/${_realname}.fish"
  install -Dm644 <($_complete zsh) "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_${_realname}"
  install -Dm644 LICENSE -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
