From a2ee9f2f99d325fd83754c8846b92fa7eb30489a Mon Sep 17 00:00:00 2001 From: Ashish SHUKLA Date: Fri, 5 Jan 2024 22:08:08 +0100 Subject: [PATCH] fix: executable path in hooks On platforms, where soft-serve executable gets installed in a path that is not the same throughout installation, or upgrades, hooks break. Some examples of such a situation is when moving soft-serve repositories from one OS to another OS, or on NixOS/Guix This commit passes the path to the current executable as an environment variable $SOFT_SERVE_EXE_PATH to the hooks. To fix/update existing repository hooks: [/path/to/soft-serve/repos] $ grep -ERl \ '^[^[:space:]]+soft-serve[^[:space:]]+' . | xargs sed -r -e \ 's,^([^[:space:]]*soft-serve[^[:space:]]*),"${SOFT_SERVE_EXE_PATH}",g' -i --- pkg/config/config.go | 9 ++++++++- pkg/hooks/gen.go | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index ecbd940c7..c861bef04 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -151,7 +151,14 @@ type Config struct { // Environ returns the config as a list of environment variables. func (c *Config) Environ() []string { - envs := []string{} + ex, err := os.Executable() + if err != nil { + ex = "soft-serve" + } + ex = filepath.ToSlash(ex) + envs := []string{ + fmt.Sprintf("SOFT_SERVE_EXE_PATH=%s", ex), + } if c == nil { return envs } diff --git a/pkg/hooks/gen.go b/pkg/hooks/gen.go index 467b2f263..6c4ceba1c 100644 --- a/pkg/hooks/gen.go +++ b/pkg/hooks/gen.go @@ -78,7 +78,7 @@ func GenerateHooks(_ context.Context, cfg *config.Config, repo string) error { Hook string Args string }{ - Executable: ex, + Executable: "\"${SOFT_SERVE_EXE_PATH}\"", Hook: hook, Args: args, }); err != nil {