Skip to content

Commit

Permalink
fix(package-service): solve problem when installing multiple packages…
Browse files Browse the repository at this point in the history
… from a @<package_manager> file
  • Loading branch information
yunielrc committed Sep 22, 2023
1 parent 0d81a6e commit ee01c77
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 19 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Optional Dependencies:
```sh
# SYSTEM: Linux yuniel-pc 6.1.51-1-MANJARO #1 SMP PREEMPT_DYNAMIC Sat Sep 2 23:22:36 UTC 2023 x86_64 GNU/Linux
# PACMAN
yay 12.1.2-1
yay 12.1.3-1
snapd 2.60.3-1
docker 1:24.0.5-1
docker-compose 2.20.3-1
Expand Down Expand Up @@ -319,9 +319,9 @@ make 4.4.1-2
python-pre-commit 2.20.0-3
shfmt 3.7.0-1
shellcheck 0.9.0-47
nodejs 20.6.0-1
npm 9.8.1-1
bash-bats 1.10.0-1
nodejs 20.6.1-1
npm 10.1.0-1
bash-bats 1.10.0-2
bash-bats-assert-git 2.1.0-1
bash-bats-file 0.4.0-2
bash-bats-support-git 0.3.0-1
Expand Down
6 changes: 3 additions & 3 deletions packages-dev-manjaro.versions
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ make 4.4.1-2
python-pre-commit 2.20.0-3
shfmt 3.7.0-1
shellcheck 0.9.0-47
nodejs 20.6.0-1
npm 9.8.1-1
bash-bats 1.10.0-1
nodejs 20.6.1-1
npm 10.1.0-1
bash-bats 1.10.0-2
bash-bats-assert-git 2.1.0-1
bash-bats-file 0.4.0-2
bash-bats-support-git 0.3.0-1
Expand Down
2 changes: 1 addition & 1 deletion packages-opt-manjaro.versions
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# SYSTEM: Linux yuniel-pc 6.1.51-1-MANJARO #1 SMP PREEMPT_DYNAMIC Sat Sep 2 23:22:36 UTC 2023 x86_64 GNU/Linux
# PACMAN
yay 12.1.2-1
yay 12.1.3-1
snapd 2.60.3-1
docker 1:24.0.5-1
docker-compose 2.20.3-1
Expand Down
14 changes: 7 additions & 7 deletions src/usr/lib/ydf/components/package/ydf-package-service.bash
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ ydf::package_service::__instruction_postinstall() {
ydf::package_service::__instruction_@pacman() {
local -r pkg_name="$1"
# select the first no empty line
local -r pacman_pkg_name="$(ydf::utils::print_1line <@pacman)"
local -r pacman_pkg_name="$(ydf::utils::text_file_to_words @pacman)"

sudo -H pacman -Syu --noconfirm --needed "${pacman_pkg_name:-"$pkg_name"}"
eval sudo -H pacman -Syu --noconfirm --needed "${pacman_pkg_name:-"$pkg_name"}"
}

#
Expand All @@ -163,9 +163,9 @@ ydf::package_service::__instruction_@pacman() {
ydf::package_service::__instruction_@yay() {
local -r pkg_name="$1"
# select the first no empty line
local -r yay_pkg_name="$(ydf::utils::print_1line <@yay)"
local -r yay_pkg_name="$(ydf::utils::text_file_to_words @yay)"

sudo -H yay -Syu --noconfirm --needed "${yay_pkg_name:-"$pkg_name"}"
eval sudo -H yay -Syu --noconfirm --needed "${yay_pkg_name:-"$pkg_name"}"
}

#
Expand All @@ -180,9 +180,9 @@ ydf::package_service::__instruction_@yay() {
ydf::package_service::__instruction_@flatpak() {
local -r pkg_name="$1"
# select the first no empty line
local -r flatpak_pkg_name="$(ydf::utils::print_1line <@flatpak)"
local -r flatpak_pkg_name="$(ydf::utils::text_file_to_words @flatpak)"

sudo -H flatpak install --assumeyes --noninteractive flathub "${flatpak_pkg_name:-"$pkg_name"}"
eval sudo -H flatpak install --assumeyes --noninteractive flathub "${flatpak_pkg_name:-"$pkg_name"}"
}

#
Expand All @@ -197,7 +197,7 @@ ydf::package_service::__instruction_@flatpak() {
ydf::package_service::__instruction_@snap() {
local -r pkg_name="$1"
# select the first no empty line
local -r snap_pkg_name="$(ydf::utils::print_1line <@snap)"
local -r snap_pkg_name="$(ydf::utils::text_file_to_words @snap)"
# eval allows include options along with package name
eval sudo -H snap install "${snap_pkg_name:-"$pkg_name"}"
}
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/packages/21multi@pacman/@pacman
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

dust nnn
bat
1 change: 1 addition & 0 deletions tests/fixtures/packages/21multi@pacman/install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo '5dust@pacman: install succeed'
1 change: 1 addition & 0 deletions tests/fixtures/packages/21multi@pacman/postinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo '5dust@pacman: postinstall succeed'
1 change: 1 addition & 0 deletions tests/fixtures/packages/21multi@pacman/preinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo '5dust@pacman: preinstall succeed'
24 changes: 20 additions & 4 deletions tests/usr/lib/ydf/components/package/ydf-package-service.i.bats
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# shellcheck disable=SC2317
load test_helper

setup() {
Expand All @@ -15,7 +16,6 @@ setup() {
__YDF_PACKAGE_SERVICE_ENVSUBST_FILE \
__YDF_PACKAGE_SERVICE_PACKAGES_DIR


if [[ -f /home/vedv/.yzsh-gen.env ]]; then
rm -f /home/vedv/.yzsh-gen.env
fi
Expand Down Expand Up @@ -46,7 +46,6 @@ setup() {

# }


# Tests for ydf::package_service::get_instructions_names()
@test "ydf::package_service::get_instructions_names() Should list instructions names for default_os" {

Expand Down Expand Up @@ -140,7 +139,6 @@ setup() {
mkdir "${BATS_TEST_TMPDIR}/pkg1"
chmod 000 "${BATS_TEST_TMPDIR}/pkg1"


ydf::package_service::get_packages_dir() {
echo "$BATS_TEST_TMPDIR"
}
Expand Down Expand Up @@ -319,6 +317,25 @@ docker_compose
assert_output --regexp "dust"
}

@test "ydf::package_service::__instruction_@pacman() Should succeed with multiples packages" {
if [[ "$YDF_PACKAGE_SERVICE_DEFAULT_OS" != manjaro ]]; then
skip "Only for manjaro"
fi

cd "${TEST_FIXTURES_DIR}/packages/21multi@pacman"

run ydf::package_service::__instruction_@pacman '21multi@pacman'

assert_success

run pacman -Q dust nnn bat

assert_success
assert_output --regexp "dust .*
nnn .*
bat .*"
}

# Tests for ydf::package_service::__instruction_@yay()
@test "ydf::package_service::__instruction_@yay() Should succeed" {

Expand Down Expand Up @@ -680,7 +697,6 @@ added line2 to file11
local -r _package_name=''
local -r _instruction=''


run ydf::package_service::__recursive_copy_with_envsubst \
"$_package_name" "$_instruction"

Expand Down

0 comments on commit ee01c77

Please sign in to comment.