dev: support fish shell in sg
Created by: michaellzc
The problem
For sg start
or sg setup
yields unexpected errors that are hard to understand
Whenever fish
users run sg setup
or sg start
, they will never get past the sanity check because the cli will try to source
a non-existing ShellConfigPath
file.
❌ Check "git" failed with the following errors:
unexpected output from git server: source: '/Users/michael' is not a file
git version 2.35.1
⋊> ~/C/s/sourcegraph on main ◦ go run ./dev/sg start 15:16:46
💡 Running 4 checks...
✅ Check "docker" success!
✅ Check "redis" success!
✅ Check "postgres" success!
❌ Check "git" failed with the following errors:
unexpected output from git server: source: '/Users/michael' is not a file
git version 2.35.1
I started trying to get sg
to work with fish
. With this commit
-
sg setup
should work nicely withfish
-
sg start
will no longer error out right away provided they have followedsg setup
to install all dependencies
However, they still may not be able to run Sourcegraph unless their bash
environment is also configured properly. This can be verified by running SHELL=(which bash) go run ./dev/sg setup
.
When running sg setup
or sg start
, it first tries to verify dependencies based on the $PATH
available in the fish
shell. However, when it comes to invoking scripts or commands defined sg.config.yaml
, these commands are always run in a fresh bash shell via bash -c
(this is expected because some of the scripts such as caddy
only work with bash-compatible shell). This is problematic when the user doesn't have things like asdf-shim setup properly under bash
but only fish
. fish
users will end up seeing error complaining fail to meet go
or node
version constraint because asdf
is not configured properly in .bashrc
and .tool-versions
is not picked up automatically.
The workaround for fish
user is first setting up the asdf
and other dependencies in bash
by running SHELL=(which bash) go run ./dev/sg setup
, then fish
users will be able to just run sg start
.
Maybe we can add a warning message for fish
shell users to run sg setup
in bash
to double-check they have the correct environment setup? An alternative is just don't support fish
, and do this https://github.com/sourcegraph/sourcegraph/pull/31537
Implementation
I ended up adding a warning message during checks
if user is running on unsupported shell (neither bash
nor zsh
) to let users know they're on an unsupported path and they should run SHELL=(which bash) sg setup
to setup their environment in case of error.
Test plan
On fish
shell, assuming both fish
and bash
has all dependencies configured properly
This should just work
go run ./dev/sg start
You should see
⋊> ~/C/s/sourcegraph on 02-19-dev_add_fish_support_to_sg ⨯ go run ./dev/sg start 12:17:54
💡 Running 4 checks...
⚠️ You're running on unsupported shell `fish`.
⚠️ If you run into error, you may run `SHELL=(which bash) sg setup` to setup your environment.
✅ Check "docker" success!
⠹ Running check "redis"...