# -*- 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           golang 1.0

go.setup            gitlab.com/gitlab-org/gitlab-runner 18.5.0 v
revision            0

homepage            https://docs.gitlab.com/runner/

description         GitLab Runner

long_description    \
    GitLab Runner is the open source project that is used to run your jobs \
    and send the results back to GitLab. It is used in conjunction with \
    GitLab CI, the open-source continuous integration service included with \
    GitLab that coordinates the jobs.

categories          devel
installs_libs       no
license             MIT
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

checksums           rmd160  d7e405c1ee152189c87b747336339bf21540cca4 \
                    sha256  b977384ca23ab98725eee2dbd233a4c08d845175a0979607f6007571add5f5cb \
                    size    2054740

# Allow Go to fetch deps at build time
go.offline_build no

pre-build {
    # Reproduce the "runner-bin-host" target from the upstream Makefile
    # Lookup REVISION from https://gitlab.com/gitlab-org/gitlab-runner/-/releases/v${version}
    set release_info [exec curl -s "https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab-runner/releases/v${version}"]
    regexp {"short_id"\s*:\s*"(.{8})"} ${release_info}     matched short_id
    regexp {^(\d+)\.(\d+)\.}           ${version}          matched major minor

    set go_ldflags     " \
        -X ${go.package}/common.NAME=${go.package} \
        -X ${go.package}/common.VERSION=${version} \
        -X ${go.package}/common.REVISION=${short_id} \
        -X ${go.package}/common.BUILT=unknown \
        -X ${go.package}/common.BRANCH=${major}-${minor}-stable \
        -s -w "

    build.args\
        -ldflags \"${go_ldflags}\" -o out/binaries/${name} ${go.package}
}

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