Skip to content

Commit

Permalink
fix: executable path in hooks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wahjava committed Jan 6, 2024
1 parent d1d7d7f commit a2ee9f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Check warning on line 157 in pkg/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/config.go#L156-L157

Added lines #L156 - L157 were not covered by tests
ex = filepath.ToSlash(ex)
envs := []string{
fmt.Sprintf("SOFT_SERVE_EXE_PATH=%s", ex),
}
if c == nil {
return envs
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/hooks/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a2ee9f2

Please sign in to comment.