Skip to content

Commit

Permalink
app/resources: fix go provisioning
Browse files Browse the repository at this point in the history
  • Loading branch information
alexAubin committed Mar 6, 2025
1 parent da6dc39 commit c67b280
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion helpers/helpers.v2.1.d/go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ynh_go_install() {
mkdir -p "${GOENV_ROOT}/shims"

# Install the requested version of Go
local final_go_version=$("$GOENV_ROOT/plugins/xxenv-latest/bin/goenv-latest" --print "$go_version")
local final_go_version=$(PATH=$GOENV_ROOT/bin:$PATH "$GOENV_ROOT/plugins/xxenv-latest/bin/goenv-latest" --print "$go_version")
go_version=$final_go_version
ynh_app_setting_set --app="$app" --key="go_version" --value="$go_version"

Expand Down
12 changes: 6 additions & 6 deletions src/tests/test_app_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,26 +509,26 @@ def test_resource_go():
r(conf, "testapp").provision_or_update()

go_version = app_setting("testapp", "go_version")
assert go_version
assert go_version and go_version.startswith("1.22.")
go_dir = f"{r.GOENV_ROOT}/versions/{go_version}/bin"
assert os.path.exists(go_dir)

env = {
"PATH": f"{go_dir}:{os.environ['PATH']}",
}

assert "go1.22 linux" in check_output("go version", env=env)
assert check_output("go version", env=env).startswith(f"go version go{go_version} linux/")

with tempfile.TemporaryDirectory(prefix="ynh_") as d:
with open("{d.name}/helloworld.go", "w") as f:
with open("{d}/helloworld.go", "w") as f:
f.write("""
package main
import "fmt"
func main() { fmt.Println("hello world") }
""")
check_call("go build helloworld.go", cwd=d.name, env=env)
assert os.path.exists(f"{d.name}/helloworld")
assert "hello world" in check_output("./helloworld", cwd=d.name)
check_call("go build helloworld.go".split(), cwd=d, env=env)
assert os.path.exists(f"{d}/helloworld")
assert "hello world" in check_output("./helloworld", cwd=d)


def test_resource_composer():
Expand Down
10 changes: 5 additions & 5 deletions src/utils/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1724,10 +1724,10 @@ def provision_or_update(self, context: Dict = {}):
export RUBY_CONFIGURE_OPTS='--disable-install-doc --with-jemalloc'
export MAKE_OPTS='-j2'
{self.RBENV_ROOT}/bin/rbenv install --skip-existing '{final_ruby_version}' 2>&1
if rbenv alias --list | grep --quiet '{self.app} '; then
rbenv alias {self.app} --remove
if {self.RBENV_ROOT}/bin/rbenv alias --list | grep --quiet '{self.app} '; then
{self.RBENV_ROOT}/bin/rbenv alias {self.app} --remove
fi
rbenv alias {self.app} '{final_ruby_version}'
{self.RBENV_ROOT}/bin/rbenv alias {self.app} '{final_ruby_version}'
""",
)
self.garbage_collect_unused_versions()
Expand Down Expand Up @@ -1791,8 +1791,8 @@ def provision_or_update(self, context: Dict = {}):

self.update_goenv()
final_go_version = check_output(
f"{self.GOENV_ROOT}/plugins/xxenv-latest/bin/goenv-latest --print '{self.version}'",
env={"GOENV_ROOT": self.GOENV_ROOT},
f"{self.GOENV_ROOT}/plugins/xxenv-latest/bin/goenv-latest --print {self.version}",
env={"GOENV_ROOT": self.GOENV_ROOT, "PATH": self.GOENV_ROOT + "/bin/:" + os.environ["PATH"]},
)
self.set_setting("go_version", final_go_version)
self._run_script(
Expand Down

0 comments on commit c67b280

Please sign in to comment.