# Importada de Alpine aports por `hammer import-alpine` (Etapa G). PUNTO DE PARTIDA — pero
# YA trae los parches de musl de Alpine (lo que un import de nix pierde). Pendiente: el
# sha256 del tarball (el wrapper lo calcula), y adaptar build/install del shell de abuild.
name    = "gitlab-runner"
version = "19.0.1"

[source]
tarball = "https://gitlab.com/gitlab-org/gitlab-runner/-/archive/v19.0.1/gitlab-runner-v19.0.1.tar.gz"
# FIXME sha256: el wrapper lo calcula (Alpine publica sha512). sha512 de Alpine:
# sha512 = "fa07957baa4f89141f9cbe342e10afb3f202312db4ba3edd28c904ad9acb65b64d0a5dcae0e2d46920d06d2c990c83d5546c523b464389c5976d28745d1c59a5"
sha256  = "c44d94d9a5bcc0298ac5c61b9fbb49c10ee3ccf7f622a7c5684ea74040c38af6"
patches = ["syslog-log-format.patch", "use-logrus-syslog-hook.patch"]

[build]
compiler = "zig-cc"
target   = "x86_64-linux-musl"
link     = "static"
flags    = []

[build.phases]
# de build() de Alpine (traducido; el lab provee $CBUILD/$CHOST — Etapa G Fase 3; revisá --shared para estático):
compile = '''
_abuild_phase() {
# This is used to determine what version of
	# https://hub.docker.com/r/gitlab/gitlab-runner-helper/tags to use.
	local gitrev
	gitrev="$(jq -r '.commit.short_id' "$srcdir/gitlab-runner-19.0.1-tags.json")"
	echo "Tag v19.0.1 resolved to SHA $gitrev" >&2

	local ldflags="
		-X gitlab.com/gitlab-org/gitlab-runner/common.NAME=gitlab-runner
		-X gitlab.com/gitlab-org/gitlab-runner/common.VERSION=19.0.1
		-X gitlab.com/gitlab-org/gitlab-runner/common.REVISION=$gitrev
		-X gitlab.com/gitlab-org/gitlab-runner/common.BUILT=$(date -d @"$SOURCE_DATE_EPOCH" -u +%Y-%m-%dT%H:%M:%S%z)
		-X gitlab.com/gitlab-org/gitlab-runner/common.BRANCH=master
		"
	# required for github.com/docker/docker
	export GO111MODULE=auto
	go build -ldflags "$ldflags" -o bin/gitlab-runner
	go build -ldflags "$ldflags" -o bin/gitlab-runner-helper \
		./apps/gitlab-runner-helper
}
_abuild_phase
'''
# de package() de Alpine (traducido $pkgdir→/out):
install = '''
_abuild_phase() {
install -Dm755 bin/gitlab-runner -t "/out"/usr/bin/

	install -Dm755 "$srcdir"/gitlab-runner.initd "/out"/etc/init.d/gitlab-runner
	install -Dm644 "$srcdir"/gitlab-runner.confd "/out"/etc/conf.d/gitlab-runner
	install -Dm644 "$srcdir"/gitlab-runner.logrotate "/out"/etc/logrotate.d/gitlab-runner

	install -d -m750 -o "$pkgusers" -g "$pkggroups" "/out"/etc/gitlab-runner
	install -d -m700 -o "$pkgusers" -g "$pkggroups" "/out"/var/lib/gitlab-runner
}
_abuild_phase
'''

[deps]
build = ["jq"]
