Skip to content

Commit e3a3c72

Browse files
authored
gitlab-runner: Add main program, version check hook, and Nix update script. Fix Darwin builds. (#395906)
2 parents f152666 + 89933df commit e3a3c72

File tree

1 file changed

+66
-43
lines changed

1 file changed

+66
-43
lines changed
Lines changed: 66 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,103 @@
11
{
22
lib,
3+
stdenv,
4+
bash,
35
buildGoModule,
46
fetchFromGitLab,
5-
bash,
7+
nix-update-script,
8+
versionCheckHook,
69
}:
710

8-
let
9-
version = "17.2.0";
10-
in
11-
buildGoModule rec {
12-
inherit version;
11+
buildGoModule (finalAttrs: {
1312
pname = "gitlab-runner";
14-
15-
commonPackagePath = "gitlab.com/gitlab-org/gitlab-runner/common";
16-
ldflags = [
17-
"-X ${commonPackagePath}.NAME=gitlab-runner"
18-
"-X ${commonPackagePath}.VERSION=${version}"
19-
"-X ${commonPackagePath}.REVISION=v${version}"
20-
];
21-
22-
# For patchShebangs
23-
buildInputs = [ bash ];
24-
25-
vendorHash = "sha256-1MwHss76apA9KoFhEU6lYiUACrPMGYzjhds6nTyNuJI=";
13+
version = "17.2.0";
2614

2715
src = fetchFromGitLab {
2816
owner = "gitlab-org";
2917
repo = "gitlab-runner";
30-
rev = "v${version}";
18+
tag = "v${finalAttrs.version}";
3119
hash = "sha256-a2Igy4DS3fYTvPW1vvDrH/DjMQ4lG9cm/P3mFr+y9s4=";
3220
};
3321

22+
vendorHash = "sha256-1MwHss76apA9KoFhEU6lYiUACrPMGYzjhds6nTyNuJI=";
23+
24+
# For patchShebangs
25+
nativeBuildInputs = [ bash ];
26+
3427
patches = [
3528
./fix-shell-path.patch
3629
./remove-bash-test.patch
3730
];
3831

39-
prePatch = ''
40-
# Remove some tests that can't work during a nix build
32+
prePatch =
33+
''
34+
# Remove some tests that can't work during a nix build
4135
42-
# Requires to run in a git repo
43-
sed -i "s/func TestCacheArchiverAddingUntrackedFiles/func OFF_TestCacheArchiverAddingUntrackedFiles/" commands/helpers/file_archiver_test.go
44-
sed -i "s/func TestCacheArchiverAddingUntrackedUnicodeFiles/func OFF_TestCacheArchiverAddingUntrackedUnicodeFiles/" commands/helpers/file_archiver_test.go
36+
# Requires to run in a git repo
37+
sed -i "s/func TestCacheArchiverAddingUntrackedFiles/func OFF_TestCacheArchiverAddingUntrackedFiles/" commands/helpers/file_archiver_test.go
38+
sed -i "s/func TestCacheArchiverAddingUntrackedUnicodeFiles/func OFF_TestCacheArchiverAddingUntrackedUnicodeFiles/" commands/helpers/file_archiver_test.go
4539
46-
# No writable developer environment
47-
rm common/build_test.go
48-
rm common/build_settings_test.go
49-
rm executors/custom/custom_test.go
40+
# No writable developer environment
41+
rm common/build_test.go
42+
rm common/build_settings_test.go
43+
rm executors/custom/custom_test.go
5044
51-
# No docker during build
52-
rm executors/docker/terminal_test.go
53-
rm executors/docker/docker_test.go
54-
rm helpers/docker/auth/auth_test.go
55-
rm executors/docker/services_test.go
56-
'';
45+
# No docker during build
46+
rm executors/docker/terminal_test.go
47+
rm executors/docker/docker_test.go
48+
rm helpers/docker/auth/auth_test.go
49+
rm executors/docker/services_test.go
50+
''
51+
+ lib.optionalString stdenv.buildPlatform.isDarwin ''
52+
# No keychain access during build breaks X.509 certificate tests
53+
rm helpers/certificate/x509_test.go
54+
rm network/client_test.go
55+
'';
5756

5857
excludedPackages = [
5958
# CI helper script for pushing images to Docker and ECR registries
59+
#
6060
# https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/4139
6161
"./scripts/sync-docker-images"
6262
];
6363

64-
postInstall = ''
65-
install packaging/root/usr/share/gitlab-runner/clear-docker-cache $out/bin
66-
'';
64+
ldflags =
65+
let
66+
ldflagsPackageVariablePrefix = "gitlab.com/gitlab-org/gitlab-runner/common";
67+
in
68+
[
69+
"-X ${ldflagsPackageVariablePrefix}.NAME=gitlab-runner"
70+
"-X ${ldflagsPackageVariablePrefix}.VERSION=${finalAttrs.version}"
71+
"-X ${ldflagsPackageVariablePrefix}.REVISION=${finalAttrs.src.tag}"
72+
];
6773

6874
preCheck = ''
6975
# Make the tests pass outside of GitLab CI
7076
export CI=0
7177
'';
7278

73-
meta = with lib; {
79+
# Many tests start servers which bind to ports
80+
__darwinAllowLocalNetworking = true;
81+
82+
postInstall = ''
83+
install packaging/root/usr/share/gitlab-runner/clear-docker-cache $out/bin
84+
'';
85+
86+
doInstallCheck = true;
87+
88+
nativeInstallCheckInputs = [ versionCheckHook ];
89+
90+
versionCheckProgramArg = "--version";
91+
92+
passthru = {
93+
updateScript = nix-update-script { };
94+
};
95+
96+
meta = {
7497
description = "GitLab Runner the continuous integration executor of GitLab";
75-
license = licenses.mit;
76-
homepage = "https://docs.gitlab.com/runner/";
77-
platforms = platforms.unix ++ platforms.darwin;
78-
maintainers = with maintainers; [ zimbatm ] ++ teams.gitlab.members;
98+
homepage = "https://docs.gitlab.com/runner";
99+
license = lib.licenses.mit;
100+
mainProgram = "gitlab-runner";
101+
maintainers = with lib.maintainers; [ zimbatm ] ++ lib.teams.gitlab.members;
79102
};
80-
}
103+
})

0 commit comments

Comments
 (0)