Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: executable path in hooks #459

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"gopkg.in/yaml.v3"
)

var binPath = "soft"

// SSHConfig is the configuration for the SSH server.
type SSHConfig struct {
// ListenAddr is the address on which the SSH server will listen.
Expand Down Expand Up @@ -151,7 +153,9 @@ type Config struct {

// Environ returns the config as a list of environment variables.
func (c *Config) Environ() []string {
envs := []string{}
envs := []string{
fmt.Sprintf("SOFT_SERVE_BIN_PATH=%s", binPath),
}
if c == nil {
return envs
}
Expand Down Expand Up @@ -419,3 +423,9 @@ func parseAuthKeys(aks []string) []ssh.PublicKey {
func (c *Config) AdminKeys() []ssh.PublicKey {
return parseAuthKeys(c.InitialAdminKeys)
}

func init() {
if ex, err := os.Executable(); err == nil {
binPath = filepath.ToSlash(ex)
}
}
12 changes: 2 additions & 10 deletions pkg/hooks/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ func GenerateHooks(_ context.Context, cfg *config.Config, repo string) error {
return err
}

ex, err := os.Executable()
if err != nil {
return err
}

// Convert to forward slashes for Windows.
ex = filepath.ToSlash(ex)

for _, hook := range []string{
PreReceiveHook,
UpdateHook,
Expand Down Expand Up @@ -78,7 +70,7 @@ func GenerateHooks(_ context.Context, cfg *config.Config, repo string) error {
Hook string
Args string
}{
Executable: ex,
wahjava marked this conversation as resolved.
Show resolved Hide resolved
Executable: "\"${SOFT_SERVE_BIN_PATH}\"",
Hook: hook,
Args: args,
}); err != nil {
Expand All @@ -88,7 +80,7 @@ func GenerateHooks(_ context.Context, cfg *config.Config, repo string) error {

// Write the soft-serve hook inside ${hook}.d directory.
hp = filepath.Join(hp, "soft-serve")
err = os.WriteFile(hp, data.Bytes(), os.ModePerm) //nolint:gosec
err := os.WriteFile(hp, data.Bytes(), os.ModePerm) //nolint:gosec
if err != nil {
log.WithPrefix("hooks").Error("failed to write hook", "err", err)
continue
Expand Down
Loading