From dab7aa20ed898ed1264edbc7f1ae241427cc3ba6 Mon Sep 17 00:00:00 2001 From: emilylange Date: Tue, 2 Apr 2024 17:04:16 +0200 Subject: [PATCH 1/2] forgejo: add missing internal version ldflags Those two ldlfags provide the version string for the /api/forgejo/v1/version API endpoint and the forgejo_sem_ver database table. Prio to this change, /api/forgejo/v1/version returned "development" and the database table "1.0.0". The proper version string, which we are now providing, is a combination of a hardcoded version compatibility string (like "gitea-1.21.8") and the forgejo semver version. The forgejo semver version in forgejo v1.21.8-0 is technically hardcoded in the Makefile, but will use git describe starting with the next major release (which will also be the release when forgejo makes this semver user facing). So in summary, this commit is a bug fix in our nixpkgs packaging and prepares us for the next major release. --- .../version-management/forgejo/default.nix | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pkgs/applications/version-management/forgejo/default.nix b/pkgs/applications/version-management/forgejo/default.nix index 0060dea785dd..5b0c24140107 100644 --- a/pkgs/applications/version-management/forgejo/default.nix +++ b/pkgs/applications/version-management/forgejo/default.nix @@ -46,7 +46,23 @@ buildGoModule rec { owner = "forgejo"; repo = "forgejo"; rev = "v${version}"; - hash = "sha256-nufhGsibpPrGWpVg75Z6qdzlc1K+p36mMjlS2MtsuAI="; + hash = "sha256-eIxITMvb1q4L2lejbmuPPQ8XG5YYjTo+9RosPEJgZ3g="; + # Forgejo has multiple different version strings that need to be provided + # via ldflags. main.ForgejoVersion for example is a combination of a + # hardcoded gitea compatibility version string (in the Makefile) and + # git describe and is easiest to get by invoking the Makefile. + # So we do that, store it the src FOD to then extend the ldflags array + # in preConfigure. + # The `echo -e >> Makefile` is temporary and already part of the next + # major release. Furthermore, the ldflags will change next major release + # and need to be updated accordingly. + leaveDotGit = true; + postFetch = '' + cd "$out" + echo -e 'show-version-full:\n\t@echo ''${FORGEJO_VERSION}' >> Makefile + make show-version-full > FULL_VERSION + find "$out" -name .git -print0 | xargs -0 rm -rf + ''; }; vendorHash = "sha256-+1apPnqbIfp2Nu1ieI2DdHo4gndZObmcq/Td+ZtkILM="; @@ -76,6 +92,10 @@ buildGoModule rec { "-X 'main.Tags=${lib.concatStringsSep " " tags}'" ]; + preConfigure = '' + export ldflags+=" -X code.gitea.io/gitea/routers/api/forgejo/v1.ForgejoVersion=$(cat FULL_VERSION) -X main.ForgejoVersion=$(cat FULL_VERSION)" + ''; + preBuild = '' go run build/merge-forgejo-locales.go ''; From 680bc07727ccc10448e4f16c8b7e61cd41c475b0 Mon Sep 17 00:00:00 2001 From: emilylange Date: Tue, 2 Apr 2024 17:04:29 +0200 Subject: [PATCH 2/2] nixosTests.forgejo: test /api/forgejo/v1/version We forgot to set two version related ldflags in our packaging and this should prevent this from going unnoticed again. Further details are in dab7aa20ed898ed1264edbc7f1ae241427cc3ba6. --- nixos/tests/forgejo.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nixos/tests/forgejo.nix b/nixos/tests/forgejo.nix index 6acd6acb50fa..b14df0a2c74f 100644 --- a/nixos/tests/forgejo.nix +++ b/nixos/tests/forgejo.nix @@ -108,6 +108,12 @@ let assert "BEGIN PGP PUBLIC KEY BLOCK" in server.succeed("curl http://localhost:3000/api/v1/signing-key.gpg") + api_version = json.loads(server.succeed("curl http://localhost:3000/api/forgejo/v1/version")).get("version") + assert "development" != api_version and "-gitea-" in api_version, ( + "/api/forgejo/v1/version should not return 'development' " + + f"but should contain a gitea compatibility version string. Got '{api_version}' instead." + ) + server.succeed( "curl --fail http://localhost:3000/user/sign_up | grep 'Registration is disabled. " + "Please contact your site administrator.'"