# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           github 1.0
PortGroup           golang 1.0

go.setup            github.com/zitadel/zitadel 4.20.5 v
revision            0
categories          security net
license             AGPL-3
maintainers         @wu21-web openmaintainer

description         Identity infrastructure, simplified for you
long_description    ZITADEL is an open-source identity and access management \
                    platform with single sign-on, multi-factor authentication, \
                    passkeys, and support for OpenID Connect, OAuth 2.0, and \
                    SAML. It provides multi-tenancy, delegated administration, \
                    and audit trails through its APIs and web console.

homepage            https://zitadel.com
platforms           {darwin >= 21}
supported_archs     arm64 x86_64
installs_libs       no

checksums           rmd160  daf4dd1ed621a154c395117829e03c9e4124e1ea \
                    sha256  56c4c371a1bb8baff9f51ae17dbb92daf3d4d2a117d1623539bc2ae3098f3041 \
                    size    168133530

go.offline_build    no
go.toolchain_min    1.26.0

depends_build-append \
                    path:bin/node:nodejs22 \
                    port:pnpm \
                    port:curl \
                    port:unzip

build.env-append    CGO_ENABLED=0 \
                    npm_config_manage_package_manager_versions=true \
                    CI=true \
                    NX_DAEMON=false \
                    NX_NO_CLOUD=true \
                    NX_TUI=false \
                    NG_CLI_ANALYTICS=false \
                    CYPRESS_INSTALL_BINARY=0 \
                    PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1

use_configure       yes
configure.cmd       ${prefix}/bin/pnpm
configure.pre_args
configure.args      install --frozen-lockfile \
                    --store-dir=${workpath}/pnpm-store

pre-build {
    set generation_env {}
    foreach assignment ${build.env} {
        lappend generation_env [shellescape ${assignment}]
    }
    system -W ${worksrcpath} \
        "/usr/bin/env [join ${generation_env} { }] [shellescape ${prefix}/bin/pnpm] exec nx run-many --projects=@zitadel/api --targets=generate,build-console --parallel=1 --skip-nx-cache"
}

build.args          -trimpath -buildvcs=false \
                    -ldflags="-s -w \
                        -X github.com/zitadel/zitadel/cmd/build.version=v${version}" \
                    -o ${name} .

destroot {
    xinstall -m 0755 ${worksrcpath}/${name} ${destroot}${prefix}/bin

    set docdir ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${docdir}
    xinstall -m 0644 ${worksrcpath}/README.md \
        ${worksrcpath}/LICENSE ${docdir}

    set examplesdir ${destroot}${prefix}/share/examples/${name}
    xinstall -d ${examplesdir}
    xinstall -m 0644 ${worksrcpath}/cmd/defaults.yaml ${examplesdir}
    xinstall -m 0644 ${worksrcpath}/cmd/setup/steps.yaml ${examplesdir}
}

test.run            yes
test.cmd            ${worksrcpath}/${name}
test.args           --version
test.target

# No pre-releases
github.livecheck.regex {([0-9]+\.[0-9]+\.[0-9]+)}

notes "\
Requires PostgreSQL. Deploy Login V2 separately if needed.
Configuration examples: ${prefix}/share/examples/${name}
Documentation: https://zitadel.com/docs/self-hosting/deploy/macos"
