Skip to content

Commit

Permalink
friskies
Browse files Browse the repository at this point in the history
  • Loading branch information
alexAubin committed Feb 10, 2025
1 parent 86e9ce4 commit 62ca720
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 32 deletions.
26 changes: 0 additions & 26 deletions helpers/helpers.v1.d/utils
Original file line number Diff line number Diff line change
Expand Up @@ -461,30 +461,4 @@ ynh_user_get_info() {
# Requires YunoHost version 2.4.0 or higher.
ynh_user_list() {
yunohost user list --output-as json --quiet | jq -r ".users | keys[]"
}

# Setup/update a git clone, meant to be used internally to fetch technical tools like goenv, rbenv
#
# [internal]
#
function _ynh_git_clone()
{
local url_and_branch="$1"
local dest_dir="$2"
local url="$(cut -f1 -d: <<< "$url_and_branch")"
local branch="$(cut -f2 -d: <<< "$url_and_branch")"
branch=${branch:-master}

mkdir -p "$dest_dir"
pushd "$dest_dir" || return 1
if ! [ -d "$dest_dir/.git" ]
then
git init -q
git remote add origin "$url"
else
git remote set-url origin "$url"
fi
git fetch -q --tags --prune origin "$branch"
git reset --hard origin/"$branch"
popd || return 1
}
4 changes: 3 additions & 1 deletion helpers/helpers.v2.1.d/go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

readonly export GOENV_ROOT="/opt/goenv"
readonly GOENV_ROOT="/opt/goenv"
export GOENV_ROOT

_ynh_load_go_in_path_and_other_tweaks() {

Expand Down Expand Up @@ -109,6 +110,7 @@ _ynh_go_cleanup() {
local installed_go_versions=$($GOENV_ROOT/bin/goenv versions --bare --skip-aliases | grep -Ev '/')
for installed_go_version in $installed_go_versions; do
if ! grep -qE "^go_version: '?$installed_go_version'?" /etc/yunohost/apps/*/settings.yml
then
ynh_print_info "Removing Go-$installed_go_version"
$GOENV_ROOT/bin/goenv uninstall --force "$installed_go_version"
fi
Expand Down
3 changes: 2 additions & 1 deletion helpers/helpers.v2.1.d/nodejs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

readonly export N_PREFIX="/opt/node_n"
readonly N_PREFIX="/opt/node_n"
export N_PREFIX

# [internal]
_ynh_load_nodejs_in_path_and_other_tweaks() {
Expand Down
4 changes: 3 additions & 1 deletion helpers/helpers.v2.1.d/ruby
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

readonly export RBENV_ROOT="/opt/rbenv"
readonly RBENV_ROOT="/opt/rbenv"
export RBENV_ROOT

_ynh_load_ruby_in_path_and_other_tweaks() {

Expand Down Expand Up @@ -119,6 +120,7 @@ _ynh_ruby_cleanup() {
local installed_ruby_versions=$(rbenv versions --bare --skip-aliases | grep -Ev '/')
for installed_ruby_version in $installed_ruby_versions; do
if ! grep -qE "^ruby_version: '?$installed_ruby_version'?" /etc/yunohost/apps/*/settings.yml
then
ynh_print_info "Removing Ruby-$installed_ruby_version"
$RBENV_ROOT/bin/rbenv uninstall --force "$installed_ruby_version"
fi
Expand Down
29 changes: 29 additions & 0 deletions helpers/helpers.v2.1.d/utils
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,32 @@ ynh_smart_mktemp() {

echo "$(mktemp --directory --tmpdir="$tmpdir")"
}


# Setup/update a git clone, meant to be used internally to fetch technical tools like goenv, rbenv
#
# [internal]
#
function _ynh_git_clone()
{
local url="$1"
local dest_dir="$2"
# FIXME: hmmm we might want some way to specify the branch ? idk
#local url="$(cut -f1 -d: <<< "$url_and_branch")"
#local branch="$(cut -f2 -d: <<< "$url_and_branch")"
local branch
branch=${branch:-master}

mkdir -p "$dest_dir"
pushd "$dest_dir" || return 1
if ! [ -d "$dest_dir/.git" ]
then
git init -q
git remote add origin "$url"
else
git remote set-url origin "$url"
fi
git fetch -q --tags --prune origin "$branch"
git reset --hard origin/"$branch"
popd || return 1
}
3 changes: 3 additions & 0 deletions tests/test_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ trap cleanup EXIT SIGINT

# =========================================================

export YNH_STDINFO=1
export YNH_ARCH=$(dpkg --print-architecture)

# Dummy http server, to serve archives for ynh_setup_source
HTTPSERVER_DIR=$(mktemp -d)
HTTPSERVER_PORT=1312
Expand Down
12 changes: 9 additions & 3 deletions tests/test_helpers.v2.1.d/ynhtest_nodejs_ruby_go_composer.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env bash

ynhtest_nodejs_install() {
local install_dir="$(mktemp -d -p "$VAR_WWW")"

nodejs_version=20
ynh_nodejs_install

node --version | grep -q '^v20\.'

install_dir="$(mktemp -d -p "$VAR_WWW")"
pushd $install_dir
# Install a random simple package to validate npm is in the path and working
npm install ansi-styles
Expand All @@ -16,13 +17,14 @@ ynhtest_nodejs_install() {
}

ynhtest_ruby_install() {
local install_dir="$(mktemp -d -p "$VAR_WWW")"

ruby_version=3.3.5
ynh_ruby_install

ruby --version
ruby --version | grep '^3\.3\.5'

install_dir="$(mktemp -d -p "$VAR_WWW")"
pushd $install_dir
# FIXME: should test installing as non-root with ynh_exec_as_app to validate PATH propagation ?
gem install bundler passenger --no-document
Expand All @@ -31,13 +33,14 @@ ynhtest_ruby_install() {
}

ynhtest_go_install() {
local install_dir="$(mktemp -d -p "$VAR_WWW")"

go_version=1.22
ynh_go_install

go version
go version | grep 'go1.22 linux'

install_dir="$(mktemp -d -p "$VAR_WWW")"
pushd $install_dir
# FIXME: should test building as non-root with ynh_exec_as_app to validate PATH propagation ?
cat << EOF > helloworld.go
Expand All @@ -52,7 +55,10 @@ EOF
}

ynhtest_composer_install() {
local install_dir="$(mktemp -d -p "$VAR_WWW")"

composer_version="2.8.3"
php_version=8.2

install_dir="$(mktemp -d -p "$VAR_WWW")"
pushd $install_dir
Expand Down

0 comments on commit 62ca720

Please sign in to comment.