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

Improving go helper #2023

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open

Improving go helper #2023

wants to merge 4 commits into from

Conversation

yalh76
Copy link
Contributor

@yalh76 yalh76 commented Dec 29, 2024

The problem

There was some issues and missing parts in the go helper

Solution

Use the Ruby helper as starting point to improve the go helper

PR Status

Ready

How to test

Put it in package like lxd and use it / I can do some test PR to show that it works

@yalh76 yalh76 requested a review from alexAubin December 29, 2024 04:50
@tituspijean

This comment was marked as resolved.

@yalh76

This comment was marked as resolved.

helpers/helpers.v1.d/go Outdated Show resolved Hide resolved
ynh_print_info --message="Downloading goenv..."
git init -q
git remote add origin https://github.com/syndbg/goenv.git
goenv="$(command -v goenv $goenv_install_dir/bin/goenv | grep "$goenv_install_dir/bin/goenv" | head -1)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command will fail if goenv is not present. You should something like that instead:

if command -v …

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case

rbenv="$(command -v rbenv $rbenv_install_dir/bin/rbenv | grep "$rbenv_install_dir/bin/rbenv" | head -1)"

and
rbenv="$(command -v rbenv $RBENV_INSTALL_DIR/bin/rbenv | grep "$RBENV_INSTALL_DIR/bin/rbenv" | head -1)"

should not be ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me what's troublesome is : what is it doing in the first place x_X

It looks like this is meant to verify that $RBENV_INSTALL_DIR/bin/rbenv exists (and maybe is executable) ? Shouldn't we just use something like

rbenv="$RBENV_INSTALL_DIR/bin/rbenv"
if [[ -x "$rbenv" ]]
then
     ...
else
     ...
fi

(In fact that was the original code x_x)

@yalh76 yalh76 requested a review from Salamandar January 9, 2025 22:36
Comment on lines -229 to +238
local installed_apps=$(yunohost app list --output-as json --quiet | jq -r .apps[].id)
local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uuuuh not sure why switching to the new version ... the current one with json and jq seems much more clean and robust ? Is it that the ruby helpers still use an hacky grep ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes ruby helper still using grep

local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$')

and
local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$')

Comment on lines -195 to +204
HOME=$install_dir eval "$(goenv init -)"
export HOME=${HOME:-"/root/"}
eval "$(goenv init -)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would tend to keep the previous syntax such that HOME doesn't get change in the rest of the script which could have side effect idk ... also we probably want to make sure that HOME is the app's install dir and not /root/ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove :
the part :

# Set environment for Go users
echo "#goenv
export GOENV_ROOT=$GOENV_INSTALL_DIR
export PATH=\"$GOENV_INSTALL_DIR/bin:$PATH\"
eval \"\$(goenv init -)\"
#goenv" > /etc/profile.d/goenv.sh
# Load the environment
export HOME=${HOME:-"/root/"}
eval "$(goenv init -)"

from each helper Go and Ruby; helper 2 and helper2.1

The first part /etc/profile.d/**** is to set the environment variables at startup of the Bash shell. But we don't need go and ruby environment variables set to each users.

The second part eval \"\$(goenv init -)\" is to initialise environment for current user, but we don't need that either, as all we need is done in _ynh_load_go_in_path_and_other_tweaks same for ruby

helpers/helpers.v1.d/go Outdated Show resolved Hide resolved
export GOENV_ROOT="$goenv_install_dir"
export goenv_root="$goenv_install_dir"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(are we sure that having that same var in lowercase is actually useful for anything x_x ... i guess it comes from copypasting the same stuff as for ruby but that sounds very meh)

Copy link
Contributor Author

@yalh76 yalh76 Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think, it's usefull, but was in ruby helper

Comment on lines -27 to +30
# Get the absolute path of this version of go
go_dir="$GOENV_INSTALL_DIR/versions/$app/bin"
# Get the absolute path of this version of Go
go_dir="$GOENV_INSTALL_DIR/versions/$go_version/bin"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm super confused because it is $app for the ruby helper x_X Or is the ruby helper also wrong ? https://github.com/YunoHost/yunohost/blob/dev/helpers/helpers.v2.1.d/ruby#L30

I don't understand what defines the name of these folder ... I assume they are created when calling rbenv install ? X_x

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruby helper use the alias plugins :

if git remote -v 2> /dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then

and
if git remote -v 2> /dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then

That plugins is not available for goenv, so there is no $app in $GOENV_INSTALL_DIR/versions/

ynh_print_info --message="Downloading goenv..."
git init -q
git remote add origin https://github.com/syndbg/goenv.git
goenv="$(command -v goenv $goenv_install_dir/bin/goenv | grep "$goenv_install_dir/bin/goenv" | head -1)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me what's troublesome is : what is it doing in the first place x_X

It looks like this is meant to verify that $RBENV_INSTALL_DIR/bin/rbenv exists (and maybe is executable) ? Shouldn't we just use something like

rbenv="$RBENV_INSTALL_DIR/bin/rbenv"
if [[ -x "$rbenv" ]]
then
     ...
else
     ...
fi

(In fact that was the original code x_x)

@alexAubin
Copy link
Member

(Now i'm just super confused about what's the best starting point between ruby and go, but it definitely looks like the ruby helper code could use some simplifications too @_@)

Co-authored-by: Alexandre Aubin <[email protected]>
@yalh76
Copy link
Contributor Author

yalh76 commented Jan 12, 2025

(Now i'm just super confused about what's the best starting point between ruby and go, but it definitely looks like the ruby helper code could use some simplifications too @_@)

I don't know either.

The point is: Go helper was a copy/pasta of Ruby as experimental helper.
goenv is like a fork of rbenv
So both helper should be relativly the same: that was the case when you implemented 2.1 helpers

@Limezy
Copy link

Limezy commented Jan 24, 2025

Hi all, thanks for your work on the matter !
Do you have any visibility on what is blocking this PR to move further ?
There are a few apps left in a broken state for installation as of now (at least Headscale and Outline, but maybe a few others)
I wish I could help but I'm unfortunately very limited in my knowledge of go (and Yunohost helpers mechanisms)
Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants