Skip to content

Commit

Permalink
#963 specific powershell module version install (#993)
Browse files Browse the repository at this point in the history
* #963 specific powershell module version install

* review comments addressed

* added test for the version specific module installation and addressed review comments

* Update src/powershell/install.sh

* Update src/powershell/install.sh

* Update src/powershell/install.sh

---------

Co-authored-by: Samruddhi Khandale <samruddhikhandale@github.com>
  • Loading branch information
prathameshzarkar9 and samruddhikhandale committed Jun 11, 2024
1 parent 6a9dd07 commit 865f69c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/powershell/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "powershell",
"version": "1.3.5",
"version": "1.4.0",
"name": "PowerShell",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/powershell",
"description": "Installs PowerShell along with needed dependencies. Useful for base Dockerfiles that often are missing required install dependencies like gpg.",
Expand All @@ -18,7 +18,7 @@
"modules": {
"type": "string",
"default": "",
"description": "Optional comma separated list of PowerShell modules to install."
"description": "Optional comma separated list of PowerShell modules to install. If you need to install a specific version of a module, use '==' to specify the version (e.g. 'az.resources==2.5.0')"
},
"powershellProfileURL": {
"type": "string",
Expand Down
16 changes: 13 additions & 3 deletions src/powershell/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,24 @@ if [ "${use_github}" = "true" ]; then
install_using_github
fi

# If PowerShell modules are requested, loop through and install
# If PowerShell modules are requested, loop through and install
if [ ${#POWERSHELL_MODULES[@]} -gt 0 ]; then
echo "Installing PowerShell Modules: ${POWERSHELL_MODULES}"
modules=(`echo ${POWERSHELL_MODULES} | tr ',' ' '`)
for i in "${modules[@]}"
do
echo "Installing ${i}"
pwsh -Command "Install-Module -Name ${i} -AllowClobber -Force -Scope AllUsers" || continue
module_parts=(`echo ${i} | tr '==' ' '`)
module_name="${module_parts[0]}"
args="-Name ${module_name} -AllowClobber -Force -Scope AllUsers"
if [ "${#module_parts[@]}" -eq 2 ]; then
module_version="${module_parts[1]}"
echo "Installing ${module_name} v${module_version}"
args+=" -RequiredVersion ${module_version}"
else
echo "Installing latest version for ${i} module"
fi

pwsh -Command "Install-Module $args" || continue
done
fi

Expand Down
13 changes: 13 additions & 0 deletions test/powershell/install_modules_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -e

# Import test library for `check` command
source dev-container-features-test-lib

# Extension-specific tests
check "az.resources" pwsh -Command "(Get-Module -ListAvailable -Name Az.Resources).Version.ToString()" | grep 2.5.0
check "az.storage" pwsh -Command "(Get-Module -ListAvailable -Name Az.Storage).Version.ToString()" | grep 4.3.0

# Report result
reportResults
8 changes: 8 additions & 0 deletions test/powershell/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,13 @@
"powershellProfileURL": "https://raw.githubusercontent.com/codspace/powershell-profile/main/Test-Profile.ps1"
}
}
},
"install_modules_version": {
"image": "mcr.microsoft.com/devcontainers/base:jammy",
"features": {
"powershell": {
"modules": "az.resources==2.5.0, az.storage==4.3.0"
}
}
}
}

0 comments on commit 865f69c

Please sign in to comment.