Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/github-cli/scripts/install-extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ install_extension() {

mkdir -p "${extensions_root}"
if [ ! -d "${extensions_root}/${repo_name}" ]; then
git \
-c credential.helper= \
-c credential.helper='!gh auth git-credential' \
clone --depth 1 "https://github.com/${extension}.git" "${extensions_root}/${repo_name}"
if ! gh extension install "${extension}"; then
git \
-c credential.helper= \
-c credential.helper='!gh auth git-credential' \
clone --depth 1 "https://github.com/${extension}.git" "${extensions_root}/${repo_name}"
fi
fi
}

Expand Down Expand Up @@ -79,6 +81,12 @@ if [ "$#" -ge 2 ]; then
url="${url#ssh://git@github.com/}"
url="${url#git@github.com:}"
echo "$url"
elif [ -f "$d/manifest.yml" ]; then
owner="$(sed -nE 's/^[[:space:]]*owner:[[:space:]]*"?([^"#]+)"?.*$/\1/p' "$d/manifest.yml" | sed -n '1p')"
name="$(sed -nE 's/^[[:space:]]*name:[[:space:]]*"?([^"#]+)"?.*$/\1/p' "$d/manifest.yml" | sed -n '1p')"
if [ -n "$owner" ] && [ -n "$name" ]; then
echo "$owner/$name"
fi
fi
done
fi
Expand Down
2 changes: 1 addition & 1 deletion src/rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Installs Rust, common Rust utilities, and their required dependencies
| version | Select or enter a version of Rust to install. | string | latest |
| profile | Select a rustup install profile. | string | minimal |
| targets | Optional comma separated list of additional Rust targets to install. | string | - |
| components | Optional, comma separated list of Rust components to be installed | string | rust-analyzer,rust-src,rustfmt,clippy |
| components | Optional, comma separated list of Rust components to be installed. Set to 'none' to install no components beyond the selected profile. | string | rust-analyzer,rust-src,rustfmt,clippy |

## Customizations

Expand Down
7 changes: 4 additions & 3 deletions src/rust/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "rust",
"version": "1.5.1",
"version": "1.6.0",
"name": "Rust",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/rust",
"description": "Installs Rust, common Rust utilities, and their required dependencies",
Expand Down Expand Up @@ -61,12 +61,13 @@
"components": {
"type": "string",
"default": "rust-analyzer,rust-src,rustfmt,clippy",
"description": "Optional, comma separated list of Rust components to be installed",
"description": "Optional, comma separated list of Rust components to be installed. Set to 'none' to install no components beyond the selected profile.",
"proposals": [
"rust-analyzer,rust-src,rustfmt,clippy",
"rust-analyzer,rust-src",
"rustfmt,clippy,rust-docs",
"llvm-tools-preview,rust-src,rustfmt"
"llvm-tools-preview,rust-src,rustfmt",
"none"
]
}
},
Expand Down
32 changes: 19 additions & 13 deletions src/rust/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
RUST_VERSION="${VERSION:-"latest"}"
RUSTUP_PROFILE="${PROFILE:-"minimal"}"
RUSTUP_TARGETS="${TARGETS:-""}"
IFS=',' read -ra components <<< "${COMPONENTS:-rust-analyzer,rust-src,rustfmt,clippy}"
# Set to "none" to install no components beyond the selected profile.
RUSTUP_COMPONENTS="${COMPONENTS:-rust-analyzer,rust-src,rustfmt,clippy}"
IFS=',' read -ra components <<< "${RUSTUP_COMPONENTS}"

export CARGO_HOME="${CARGO_HOME:-"/usr/local/cargo"}"
export RUSTUP_HOME="${RUSTUP_HOME:-"/usr/local/rustup"}"
Expand Down Expand Up @@ -396,19 +398,23 @@ if [ "${UPDATE_RUST}" = "true" ]; then
echo "Updating Rust..."
rustup update 2>&1
fi
# Install Rust components
echo "Installing Rust components..."
for component in "${components[@]}"; do
# Trim leading and trailing whitespace
component="${component#"${component%%[![:space:]]*}"}" && component="${component%"${component##*[![:space:]]}"}"
if [ -n "${component}" ]; then
echo "Installing Rust component: ${component}"
if ! rustup component add "${component}" 2>&1; then
echo "Warning: Failed to install component '${component}'. It may not be available for this toolchain." >&2
exit 1
# Install Rust components (skip entirely when explicitly set to "none")
if [ "${RUSTUP_COMPONENTS}" = "none" ]; then
echo "Skipping Rust components installation as 'components' is set to 'none'."
else
echo "Installing Rust components..."
for component in "${components[@]}"; do
# Trim leading and trailing whitespace
component="${component#"${component%%[![:space:]]*}"}" && component="${component%"${component##*[![:space:]]}"}"
if [ -n "${component}" ]; then
echo "Installing Rust component: ${component}"
if ! rustup component add "${component}" 2>&1; then
echo "Warning: Failed to install component '${component}'. It may not be available for this toolchain." >&2
exit 1
fi
fi
fi
done
done
fi

if [ -n "${RUSTUP_TARGETS}" ]; then
IFS=',' read -ra targets <<< "${RUSTUP_TARGETS}"
Expand Down
2 changes: 2 additions & 0 deletions test/github-cli/install_extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ check "gh-version" gh --version

check "gh-extension-installed" gh extension list | grep -q 'dlvhdr/gh-dash'
check "gh-extension-installed-2" gh extension list | grep -q 'github/gh-copilot'
check "gh-extension-installed-3" gh extension list | grep -q 'github/gh-aw'
check "gh-aw-runs" gh aw version

# Report result
reportResults
2 changes: 1 addition & 1 deletion test/github-cli/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"features": {
"github-cli": {
"version": "latest",
"extensions": "dlvhdr/gh-dash,github/gh-copilot"
"extensions": "dlvhdr/gh-dash,github/gh-copilot,github/gh-aw"
}
}
}
Expand Down
40 changes: 40 additions & 0 deletions test/rust/rust_with_none_components.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Helper function to check component is installed
check_component_installed() {
local component=$1
if rustup component list | grep -q "${component}.*installed"; then
return 0 # Component is installed (success)
else
return 1 # Component is not installed (failure)
fi
}

# Helper function to check component is NOT installed
check_component_not_installed() {
local component=$1
if rustup component list | grep -q "${component}.*installed"; then
return 1 # Component is installed (failure)
else
return 0 # Component is not installed (success)
fi
}

# Definition specific tests
check "cargo version" cargo --version
check "rustc version" rustc --version
check "correct rust version" rustup target list | grep aarch64-unknown-linux-gnu

# When components is set to "none", none of the default components should be installed
check "rust-analyzer not installed" check_component_not_installed "rust-analyzer"
check "rust-src not installed" check_component_not_installed "rust-src"
check "rustfmt not installed" check_component_not_installed "rustfmt"
check "clippy not installed" check_component_not_installed "clippy"

# Report result
reportResults
10 changes: 10 additions & 0 deletions test/rust/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@
"components": ""
}
}
},
"rust_with_none_components": {
"image": "ubuntu:noble",
"features": {
"rust": {
"version": "latest",
"targets": "aarch64-unknown-linux-gnu",
"components": "none"
}
}
},
"rust_with_centos": {
"image": "centos:centos7",
Expand Down
Loading