feat: do not rely on git for versioning

It causes lots of pain when building with `nix` for a local `flake.nix`.

Not sure if it's a good general solution:
* now it requires a manual step of updating `./version` on each release.
* we're losing commit hash abbreviation, like `0.5.3-5-gbe5a291`

I guess, this can be fixed by installing git-pre-commit-hook, but even
then it'd be wrong, because the output of `git describe --tags --always`
won't be the same before and after commit.
This commit is contained in:
Igor Ramazanov 2025-03-11 17:46:02 +00:00
parent af733eb311
commit 8268de92c4
5 changed files with 6 additions and 12 deletions

View File

@ -28,10 +28,9 @@ rec {
}; };
in { in {
formatter = pkgs.alejandra; formatter = pkgs.alejandra;
packages = rec { packages = {
headplane = pkgs.callPackage ./nix/package.nix {}; headplane = pkgs.callPackage ./nix/package.nix {};
headplane-agent = pkgs.callPackage ./nix/agent.nix {}; headplane-agent = pkgs.callPackage ./nix/agent.nix {};
default = headplane;
}; };
devShell = pkgs.devshell.mkShell rec { devShell = pkgs.devshell.mkShell rec {
name = description; name = description;

View File

@ -1,8 +1,7 @@
{buildGoModule}: {buildGoModule}:
buildGoModule { buildGoModule {
pname = "hp_agent"; pname = "hp_agent";
# TODO: take the latest `git tag`, if commits do not match, append `-SNAPSHOT`. version = builtins.replaceStrings ["\n"] [""] (builtins.readFile ../version);
version = "0.5.3";
src = ../.; src = ../.;
vendorHash = "sha256-G0kahv3mPTL/mxU2U+0IytJaFVPXMbMBktbLMfM0BO8="; vendorHash = "sha256-G0kahv3mPTL/mxU2U+0IytJaFVPXMbMBktbLMfM0BO8=";
ldflags = ["-s" "-w"]; ldflags = ["-s" "-w"];

View File

@ -9,11 +9,7 @@
}: }:
stdenv.mkDerivation (finalAttrs: { stdenv.mkDerivation (finalAttrs: {
pname = "headplane"; pname = "headplane";
version = builtins.replaceStrings ["\n"] [""] (builtins.readFile ../version);
# TODO: take the latest `git tag`, if commits do not match, append `-SNAPSHOT`.
version = "0.5.3";
# TODO: requires `.git` directory.
src = ../.; src = ../.;
nativeBuildInputs = [ nativeBuildInputs = [

1
version Normal file
View File

@ -0,0 +1 @@
0.5.3-SNAPSHOT

View File

@ -2,7 +2,7 @@ import { reactRouter } from '@react-router/dev/vite';
import { defineConfig } from 'vite'; import { defineConfig } from 'vite';
import babel from 'vite-plugin-babel'; import babel from 'vite-plugin-babel';
import tsconfigPaths from 'vite-tsconfig-paths'; import tsconfigPaths from 'vite-tsconfig-paths';
import { execSync } from 'node:child_process'; import fs from 'node:fs';
import tailwindcss from 'tailwindcss'; import tailwindcss from 'tailwindcss';
import autoprefixer from 'autoprefixer'; import autoprefixer from 'autoprefixer';
@ -11,8 +11,7 @@ if (prefix.endsWith('/')) {
throw new Error('Prefix must not end with a slash'); throw new Error('Prefix must not end with a slash');
} }
// Load the version via git tags const version = fs.readFileSync("version", "utf8");
const version = execSync('git describe --tags --always').toString().trim();
if (!version) { if (!version) {
throw new Error('Unable to execute git describe'); throw new Error('Unable to execute git describe');
} }