# -*- 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 19.3.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  4b7d63e6d5c1ddaa5c0d9b13babd5ae26899c87a \
                    sha256  93ddf6a712cfea1e431c74a41e17a93c0f03275d88fb51d83661e531dc9cdf98 \
                    size    2962749

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

go.toolchain_min    1.26

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/
}
