From 058402c0cc4bf87c36c7b643ba1207fb37955e96 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Wed, 11 Sep 2024 22:47:24 +0900 Subject: [PATCH] feat(r-dependent-packages): new `skip` option to skip R package installation (#241) --- src/r-dependent-packages/devcontainer-feature.json | 7 ++++--- src/r-dependent-packages/install.sh | 5 +++-- src/r-dependent-packages/lifecycle_script.sh | 1 + test/r-dependent-packages/r-ver-skip.sh | 12 ++++++++++++ test/r-dependent-packages/scenarios.json | 8 ++++++++ 5 files changed, 28 insertions(+), 5 deletions(-) create mode 100755 test/r-dependent-packages/r-ver-skip.sh diff --git a/src/r-dependent-packages/devcontainer-feature.json b/src/r-dependent-packages/devcontainer-feature.json index 9883f55..ec66e40 100644 --- a/src/r-dependent-packages/devcontainer-feature.json +++ b/src/r-dependent-packages/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "R packages from the DESCRIPTION file (via pak)", "id": "r-dependent-packages", - "version": "0.1.0", + "version": "0.2.0", "description": "This Feature sets scripts to install dependent R packages from the DESCRIPTION file in the repository.", "documentationURL": "https://github.com/rocker-org/devcontainer-features/tree/main/src/r-dependent-packages", "options": { @@ -11,9 +11,10 @@ "enum": [ "onCreate", "updateContent", - "postCreate" + "postCreate", + "skip" ], - "description": "When to install the dependent R packages? Each option corresponds to the lifecycle scripts." + "description": "When to install the dependent R packages? Each option corresponds to the lifecycle scripts. 'skip' means to skip the installation." }, "pakVersion": { "type": "string", diff --git a/src/r-dependent-packages/install.sh b/src/r-dependent-packages/install.sh index 1fa0384..4eb8955 100644 --- a/src/r-dependent-packages/install.sh +++ b/src/r-dependent-packages/install.sh @@ -78,10 +78,11 @@ install_pak "${PAK_VERSION}" # Replace the target lifecycle script echo "Set the lifecycle script for '${WHEN}'..." +LIFECYCLE_SCRIPT_PATH="${LIFECYCLE_SCRIPTS_DIR}/${WHEN,,}.sh" sed \ -e "s|@ROOT@|${ROOT}|" \ -e "s|@REPOS@|${REPOS//"'"/'"'}|" \ -e "s|@DEPS@|${DEPS}|" \ - lifecycle_script.sh >"${LIFECYCLE_SCRIPTS_DIR}/${WHEN,,}.sh" - + lifecycle_script.sh >"${LIFECYCLE_SCRIPT_PATH}" +echo "The lifecycle script is generated at '${LIFECYCLE_SCRIPT_PATH}'" echo "Done!" diff --git a/src/r-dependent-packages/lifecycle_script.sh b/src/r-dependent-packages/lifecycle_script.sh index e8f7315..d885828 100755 --- a/src/r-dependent-packages/lifecycle_script.sh +++ b/src/r-dependent-packages/lifecycle_script.sh @@ -19,6 +19,7 @@ fix_permissions() { fix_permissions "${PKG_PACKAGE_CACHE_DIR}" +echo "The manifest DESCRIPTION file was set to '@ROOT@/DESCRIPTION'" echo "Install dependent R packages..." R -q -e \ diff --git a/test/r-dependent-packages/r-ver-skip.sh b/test/r-dependent-packages/r-ver-skip.sh new file mode 100755 index 0000000..c9ad6fa --- /dev/null +++ b/test/r-dependent-packages/r-ver-skip.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +# Feature-specific tests +check "R pak package" bash -c "R -q -e 'names(installed.packages()[, 3])' | grep pak" + +# Report result +reportResults diff --git a/test/r-dependent-packages/scenarios.json b/test/r-dependent-packages/scenarios.json index 2ccca09..4405065 100644 --- a/test/r-dependent-packages/scenarios.json +++ b/test/r-dependent-packages/scenarios.json @@ -16,6 +16,14 @@ } } }, + "r-ver-skip": { + "image": "rocker/r-ver:4", + "features": { + "r-dependent-packages": { + "when": "skip" + } + } + }, "r-ver-updatecontent": { "image": "rocker/r-ver:4", "features": {