# -*- 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.8.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  7c9491f06d87bdf66bd525d2c831be18e9588176 \
                    sha256  b0eeffa6cf82cc48a030a58cfafe7dddc75dcbac71f61265a2252317981b66cb \
                    size    2198530

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