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

Current make watch target fails to find air even after successful installation #74

Closed
andrerocco opened this issue Nov 11, 2023 · 2 comments · Fixed by #127
Closed

Current make watch target fails to find air even after successful installation #74

andrerocco opened this issue Nov 11, 2023 · 2 comments · Fixed by #127

Comments

@andrerocco
Copy link
Contributor

andrerocco commented Nov 11, 2023

Description

When running make watch after successfully installing air, the Makefile still prompts "air is not installed. Do you want to install it now? (y/n)". This happens even though air has been installed and is available in the PATH.

It seems like the GOPATH has been deprecated in Go 1.16 and should not be relied on.

Environment

  • Go version: 1.21.0
  • OS: Ubuntu 22.04

Additional Information

Here is the watch target in the Makefile:

watch:
	@if [ -x "$(GOPATH)/bin/air" ]; then \
	    "$(GOPATH)/bin/air"; \
		@echo "Watching...";\
	else \
	    read -p "air is not installed. Do you want to install it now? (y/n) " choice; \
	    if [ "$$choice" = "y" ]; then \
			go install github.com/cosmtrek/air@latest; \
	        "$(GOPATH)/bin/air"; \
				@echo "Watching...";\
	    else \
	        echo "You chose not to install air. Exiting..."; \
	        exit 1; \
	    fi; \
	fi
@smantic
Copy link

smantic commented Nov 22, 2023

$GOPATH itself is not deprecated, what this was doing was fine. https://blog.smantic.dev/posts/gopath-is-not-deprecated/

What is deprecated is using $GOPATH as the workspace for go projects. This was typically where you developed go codebases before go modules.

read -p "Go's 'air' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
    go install github.com/cosmtrek/air@latest; 
    \air;\
echo "Watching...";\

This assumes that the user has added $GOBIN ($GOPATH/bin) to the user's path. This isnt a thing that happens automatically. The previous implementation did not assume that the user had $GOBIN in their path.

@andrerocco
Copy link
Contributor Author

Yess @smantic, the description of the issue is indeed wrong, thanks for pointing it out.

My experience (and from issue #111 apparently) was that the previous implementation ran on every run of make watch. So it would install air on the system but not detect the installation afterward. Then I think neither the previous implementation should be relied upon.

I'm currious to see if people will have issues with the new implementation as you said that. I will take look into what could solution could be taken to make this as more generalized (work on more machines) as possible.

SudoSurya pushed a commit to SudoSurya/go-blueprint that referenced this issue Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants