gitlab-runner: Add main program, version check hook, and Nix update script. Fix Darwin builds. (#395906)

This commit is contained in:
Gaétan Lepage 2025-04-07 09:05:26 +02:00 committed by GitHub
commit e3a3c72a7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,80 +1,103 @@
{ {
lib, lib,
stdenv,
bash,
buildGoModule, buildGoModule,
fetchFromGitLab, fetchFromGitLab,
bash, nix-update-script,
versionCheckHook,
}: }:
let buildGoModule (finalAttrs: {
version = "17.2.0";
in
buildGoModule rec {
inherit version;
pname = "gitlab-runner"; pname = "gitlab-runner";
version = "17.2.0";
commonPackagePath = "gitlab.com/gitlab-org/gitlab-runner/common";
ldflags = [
"-X ${commonPackagePath}.NAME=gitlab-runner"
"-X ${commonPackagePath}.VERSION=${version}"
"-X ${commonPackagePath}.REVISION=v${version}"
];
# For patchShebangs
buildInputs = [ bash ];
vendorHash = "sha256-1MwHss76apA9KoFhEU6lYiUACrPMGYzjhds6nTyNuJI=";
src = fetchFromGitLab { src = fetchFromGitLab {
owner = "gitlab-org"; owner = "gitlab-org";
repo = "gitlab-runner"; repo = "gitlab-runner";
rev = "v${version}"; tag = "v${finalAttrs.version}";
hash = "sha256-a2Igy4DS3fYTvPW1vvDrH/DjMQ4lG9cm/P3mFr+y9s4="; hash = "sha256-a2Igy4DS3fYTvPW1vvDrH/DjMQ4lG9cm/P3mFr+y9s4=";
}; };
vendorHash = "sha256-1MwHss76apA9KoFhEU6lYiUACrPMGYzjhds6nTyNuJI=";
# For patchShebangs
nativeBuildInputs = [ bash ];
patches = [ patches = [
./fix-shell-path.patch ./fix-shell-path.patch
./remove-bash-test.patch ./remove-bash-test.patch
]; ];
prePatch = '' prePatch =
# Remove some tests that can't work during a nix build ''
# Remove some tests that can't work during a nix build
# Requires to run in a git repo # Requires to run in a git repo
sed -i "s/func TestCacheArchiverAddingUntrackedFiles/func OFF_TestCacheArchiverAddingUntrackedFiles/" commands/helpers/file_archiver_test.go sed -i "s/func TestCacheArchiverAddingUntrackedFiles/func OFF_TestCacheArchiverAddingUntrackedFiles/" commands/helpers/file_archiver_test.go
sed -i "s/func TestCacheArchiverAddingUntrackedUnicodeFiles/func OFF_TestCacheArchiverAddingUntrackedUnicodeFiles/" commands/helpers/file_archiver_test.go sed -i "s/func TestCacheArchiverAddingUntrackedUnicodeFiles/func OFF_TestCacheArchiverAddingUntrackedUnicodeFiles/" commands/helpers/file_archiver_test.go
# No writable developer environment # No writable developer environment
rm common/build_test.go rm common/build_test.go
rm common/build_settings_test.go rm common/build_settings_test.go
rm executors/custom/custom_test.go rm executors/custom/custom_test.go
# No docker during build # No docker during build
rm executors/docker/terminal_test.go rm executors/docker/terminal_test.go
rm executors/docker/docker_test.go rm executors/docker/docker_test.go
rm helpers/docker/auth/auth_test.go rm helpers/docker/auth/auth_test.go
rm executors/docker/services_test.go rm executors/docker/services_test.go
''; ''
+ lib.optionalString stdenv.buildPlatform.isDarwin ''
# No keychain access during build breaks X.509 certificate tests
rm helpers/certificate/x509_test.go
rm network/client_test.go
'';
excludedPackages = [ excludedPackages = [
# CI helper script for pushing images to Docker and ECR registries # CI helper script for pushing images to Docker and ECR registries
#
# https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/4139 # https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/4139
"./scripts/sync-docker-images" "./scripts/sync-docker-images"
]; ];
postInstall = '' ldflags =
install packaging/root/usr/share/gitlab-runner/clear-docker-cache $out/bin let
''; ldflagsPackageVariablePrefix = "gitlab.com/gitlab-org/gitlab-runner/common";
in
[
"-X ${ldflagsPackageVariablePrefix}.NAME=gitlab-runner"
"-X ${ldflagsPackageVariablePrefix}.VERSION=${finalAttrs.version}"
"-X ${ldflagsPackageVariablePrefix}.REVISION=${finalAttrs.src.tag}"
];
preCheck = '' preCheck = ''
# Make the tests pass outside of GitLab CI # Make the tests pass outside of GitLab CI
export CI=0 export CI=0
''; '';
meta = with lib; { # Many tests start servers which bind to ports
description = "GitLab Runner the continuous integration executor of GitLab"; __darwinAllowLocalNetworking = true;
license = licenses.mit;
homepage = "https://docs.gitlab.com/runner/"; postInstall = ''
platforms = platforms.unix ++ platforms.darwin; install packaging/root/usr/share/gitlab-runner/clear-docker-cache $out/bin
maintainers = with maintainers; [ zimbatm ] ++ teams.gitlab.members; '';
doInstallCheck = true;
nativeInstallCheckInputs = [ versionCheckHook ];
versionCheckProgramArg = "--version";
passthru = {
updateScript = nix-update-script { };
}; };
}
meta = {
description = "GitLab Runner the continuous integration executor of GitLab";
homepage = "https://docs.gitlab.com/runner";
license = lib.licenses.mit;
mainProgram = "gitlab-runner";
maintainers = with lib.maintainers; [ zimbatm ] ++ lib.teams.gitlab.members;
};
})