# 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    = "woodpecker"
version = "3.14.1"

[source]
tarball = "https://github.com/woodpecker-ci/woodpecker/releases/download/v3.14.1/woodpecker-src.tar.gz"
# FIXME sha256: el wrapper lo calcula (Alpine publica sha512). sha512 de Alpine:
# sha512 = "6a8a7183f2a7ffaa9df6b4e23396153ceedfd08e666ec9aecd49de35ff75b09aff437c76452878769270e548fe4d564031a1fbe9dff84a217334e97214e4c510"
sha256  = "dafba02f6a55f748a80d0fa4d66720c7436af446baf903e5187553834226f3a4"
patches = ["respect-cgo-flags.patch", "disable-race-tests.patch", "disable-ui-openai-generation.patch", "skip-alternate-unix-sh-test.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() {
export TARGETARCH="$(go env GOHOSTARCH)"
	make build -j1 STATIC_BUILD=false VERSION=3.14.1
	make docs
}
_abuild_phase
'''
# de package() de Alpine (traducido $pkgdir→/out):
install = '''
_abuild_phase() {
# Install server
	install -Dm755 "$builddir"/dist/woodpecker-server \
		"/out"/usr/bin/woodpecker-server

	# Install initd & conf
	install -Dm755 "$srcdir"/woodpecker-server.initd \
		"/out"/etc/init.d/woodpecker-server
	install -Dm640 -o woodpecker -g woodpecker "$srcdir"/woodpecker-server.conf \
		"/out"/etc/woodpecker/server.conf

	# Install web resources
	install -d -m 755 -o woodpecker -g woodpecker "/out"/usr/share/webapps/woodpecker
	cp -R "$builddir"/web/dist/* "/out"/usr/share/webapps/woodpecker/

	# Create empty log & lib directories
	install -d -m0750 -o woodpecker -g woodpecker \
		"/out"/var/log/woodpecker "/out"/var/lib/woodpecker

	# Install logrotate rules
	install -Dm644 "$srcdir"/woodpecker-server.logrotate \
		"/out"/etc/logrotate.d/woodpecker-server

	# Install mandocs
	mkdir -p "/out"/usr/share/doc/woodpecker
	cp -R "$builddir"/docs/docs/* "/out"/usr/share/doc/woodpecker/
}
_abuild_phase
'''

# depends de runtime de Alpine (NO build-deps): openrc

[deps]
build = ["go-swag", "sqlite", "pnpm"]
