Skip to content

Commit

Permalink
feat(package-service): make envsubst variables availables in scripts …
Browse files Browse the repository at this point in the history
…instructions
  • Loading branch information
yunielrc committed Sep 22, 2023
1 parent 6d0d1ea commit 32e89c2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/usr/lib/ydf/components/package/ydf-package-service.bash
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,13 @@ ydf::package_service::get_instructions_names() {
# Returns:
# 0 on success, non-zero on error.
#
ydf::package_service::__instruction_preinstall() {
ydf::package_service::__instruction_preinstall() (
set -o allexport
# shellcheck disable=SC1090
source "$__YDF_PACKAGE_SERVICE_ENVSUBST_FILE"

bash ./preinstall
}
)

#
# Execute install script
Expand All @@ -119,9 +123,13 @@ ydf::package_service::__instruction_preinstall() {
# Returns:
# 0 on success, non-zero on error.
#
ydf::package_service::__instruction_install() {
ydf::package_service::__instruction_install() (
set -o allexport
# shellcheck disable=SC1090
source "$__YDF_PACKAGE_SERVICE_ENVSUBST_FILE"

bash ./install
}
)

#
# Execute postinstall script
Expand All @@ -130,9 +138,13 @@ ydf::package_service::__instruction_install() {
# Returns:
# 0 on success, non-zero on error.
#
ydf::package_service::__instruction_postinstall() {
ydf::package_service::__instruction_postinstall() (
set -o allexport
# shellcheck disable=SC1090
source "$__YDF_PACKAGE_SERVICE_ENVSUBST_FILE"

bash ./postinstall
}
)

#
# Execute @pacman instruction
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/packages/23scriptvars/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo "install: MY_CONFIG1: ${MY_CONFIG1}"
echo "install: HOME: ${HOME}"
1 change: 1 addition & 0 deletions tests/fixtures/packages/23scriptvars/postinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "postinstall: MY_CONFIG2: ${MY_CONFIG2}"
1 change: 1 addition & 0 deletions tests/fixtures/packages/23scriptvars/preinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "preinstall: FILE11_1: ${FILE11_1}"
34 changes: 34 additions & 0 deletions tests/usr/lib/ydf/components/package/ydf-package-service.i.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1140,3 +1140,37 @@ line 11
> FAILED. INSTALLING packages
ERROR> Installing packages"
}

# Tests for ydf::package_service::__instruction_preinstall()
@test "ydf::package_service::__instruction_preinstall() Should succeed With variables" {

cd "${TEST_FIXTURES_DIR}/packages/23scriptvars"

run ydf::package_service::__instruction_preinstall

assert_success
assert_output "preinstall: FILE11_1: file11_1"
}

# Tests for ydf::package_service::__instruction_install()
@test "ydf::package_service::__instruction_install() Should succeed With variables" {

cd "${TEST_FIXTURES_DIR}/packages/23scriptvars"

run ydf::package_service::__instruction_install

assert_success
assert_output "install: MY_CONFIG1: my_config1
install: HOME: /home/vedv"
}

# Tests for ydf::package_service::__instruction_postinstall()
@test "ydf::package_service::__instruction_postinstall() Should succeed With variables" {

cd "${TEST_FIXTURES_DIR}/packages/23scriptvars"

run ydf::package_service::__instruction_postinstall

assert_success
assert_output "postinstall: MY_CONFIG2: my config2"
}

0 comments on commit 32e89c2

Please sign in to comment.