Skip to content
Merged
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
41 changes: 41 additions & 0 deletions dotnet/install/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# dotnet/install

Install one or more .NET SDK versions.

## Install a single channel

```yaml
tasks:
- key: dotnet
call: dotnet/install 1.0.0
with:
dotnet-channel: "8.0"
```

## Install from global.json

```yaml
tasks:
- key: dotnet
use: code
call: dotnet/install 1.0.0
with:
global-json-file: global.json
filter:
- global.json
```

## Install multiple channels in one call

```yaml
tasks:
- key: dotnet
call: dotnet/install 1.0.0
with:
dotnet-channels: '["8.0", "9.0", "10.0"]'
dotnet-quality: preview
```

When installing multiple SDKs, `--skip-non-versioned-files` will automatically be appended to the install script for subsequent installs, so they do not overwrite non-versioned files from earlier installs.

`dotnet/install` automatically configures `PATH` and `DOTNET_ROOT` for downstream tasks.
116 changes: 116 additions & 0 deletions dotnet/install/bin/install-dotnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/env bash
set -ueo pipefail

if [[ -z "${GLOBAL_JSON_FILE}" && -z "${DOTNET_CHANNEL}" && -z "${DOTNET_CHANNELS}" ]]; then
cat << EOF > "$(mktemp "$RWX_ERRORS/error-XXXX")"
Invalid parameters: set \`global-json-file\`, \`dotnet-channel\`, or \`dotnet-channels\`.
EOF
exit 2
fi

if [[ -n "${GLOBAL_JSON_FILE}" && ! -f "${GLOBAL_JSON_FILE}" ]]; then
cat << EOF > "$(mktemp "$RWX_ERRORS/error-XXXX")"
Invalid parameter: \`global-json-file\` path does not exist.

Received \`${GLOBAL_JSON_FILE}\`
EOF
exit 2
fi

DOTNET_INSTALL_DIR="/opt/dotnet"
DOTNET_INSTALL_SCRIPT_DIR="$(mktemp -d)"
DOTNET_INSTALL_SCRIPT_PATH="${DOTNET_INSTALL_SCRIPT_DIR}/dotnet-install.sh"

cleanup() {
rm -rf "$DOTNET_INSTALL_SCRIPT_DIR"
}
trap cleanup EXIT

sudo mkdir -p "$DOTNET_INSTALL_DIR"
sudo chown "$(id -un):$(id -gn)" "$DOTNET_INSTALL_DIR"
curl -Lsfo "$DOTNET_INSTALL_SCRIPT_PATH" https://dot.net/v1/dotnet-install.sh
chmod +x "$DOTNET_INSTALL_SCRIPT_PATH"

export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0
export DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2
export DOTNET_ROOT="$DOTNET_INSTALL_DIR"
export PATH="$DOTNET_ROOT:$PATH"

channels=()
if [[ -n "${DOTNET_CHANNELS}" ]]; then
normalized="$(echo "$DOTNET_CHANNELS" | tr -d '[:space:]')"
if [[ "$normalized" =~ ^\[.*\]$ ]]; then
inner="${normalized#[}"
inner="${inner%]}"
if [[ -n "$inner" ]]; then
IFS=',' read -r -a raw_channels <<< "$inner"
for raw_channel in "${raw_channels[@]}"; do
channel="${raw_channel#\"}"
channel="${channel%\"}"
channel="${channel#\'}"
channel="${channel%\'}"
if [[ -n "$channel" ]]; then
channels+=("$channel")
fi
done
fi
else
if [[ "$DOTNET_CHANNELS" == *","* ]]; then
IFS=',' read -r -a raw_channels <<< "$DOTNET_CHANNELS"
else
IFS=' ' read -r -a raw_channels <<< "$DOTNET_CHANNELS"
fi

for raw_channel in "${raw_channels[@]}"; do
channel="$(echo "$raw_channel" | xargs)"
if [[ -n "$channel" ]]; then
channels+=("$channel")
fi
done
fi
fi

if [[ ${#channels[@]} -eq 0 && -n "${DOTNET_CHANNEL}" ]]; then
channels=("$DOTNET_CHANNEL")
fi

if [[ -n "${GLOBAL_JSON_FILE}" ]]; then
echo "Installing .NET SDK from ${GLOBAL_JSON_FILE}"
bash "$DOTNET_INSTALL_SCRIPT_PATH" --jsonfile "$GLOBAL_JSON_FILE" --install-dir "$DOTNET_INSTALL_DIR" --no-path
else
if [[ ${#channels[@]} -eq 0 ]]; then
cat << EOF > "$(mktemp "$RWX_ERRORS/error-XXXX")"
Invalid parameters: could not determine any .NET channel from \`dotnet-channel\` or \`dotnet-channels\`.
EOF
exit 2
fi

idx=0
for channel in "${channels[@]}"; do
echo "Installing .NET SDK channel ${channel}"

command=(bash "$DOTNET_INSTALL_SCRIPT_PATH" --channel "$channel" --install-dir "$DOTNET_INSTALL_DIR" --no-path)

if [[ -n "${DOTNET_QUALITY}" ]]; then
command+=(--quality "$DOTNET_QUALITY")
fi

if [[ ${#channels[@]} -gt 1 && $idx -gt 0 ]]; then
command+=(--skip-non-versioned-files)
fi

"${command[@]}"
idx=$((idx + 1))
done
fi

echo "$DOTNET_INSTALL_DIR" >> "$RWX_ENV/PATH"
echo "$DOTNET_INSTALL_DIR" >> "$RWX_ENV/DOTNET_ROOT"
echo "$DOTNET_SKIP_FIRST_TIME_EXPERIENCE" >> "$RWX_ENV/DOTNET_SKIP_FIRST_TIME_EXPERIENCE"
echo "$DOTNET_CLI_TELEMETRY_OPTOUT" >> "$RWX_ENV/DOTNET_CLI_TELEMETRY_OPTOUT"
echo "$DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER" >> "$RWX_ENV/DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER"
echo "$DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX" >> "$RWX_ENV/DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX"

dotnet --version
44 changes: 44 additions & 0 deletions dotnet/install/rwx-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: dotnet/install
version: 1.0.0
description: Install the .NET SDK
source_code_url: https://github.com/rwx-cloud/packages/tree/main/dotnet/install
issue_tracker_url: https://github.com/rwx-cloud/packages/issues

parameters:
dotnet-channel:
description: "Single .NET SDK channel/version to install, eg. 8.0"
required: false
dotnet-channels:
description: "Array-style list of .NET SDK channels/versions to install in one call, eg. [\"8.0\", \"9.0\"]"
required: false
dotnet-quality:
description: "Optional .NET SDK quality, eg. ga, preview, daily"
required: false
global-json-file:
description: "Path to a global.json file used to determine the SDK version"
required: false

tasks:
- key: install-libicu-dev
run: |
if ! dpkg -s libicu-dev >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y --no-install-recommends libicu-dev
sudo apt-get clean
fi

- key: install-dotnet
use: install-libicu-dev
run: |
source "$RWX_PACKAGE_PATH/rwx-utils.sh"
if ! rwx_os_package_manager_in apt; then
echo "Unsupported operating system or package manager \`$(rwx_os_package_manager)\`" > "$(mktemp "$RWX_ERRORS/error-XXXX")"
exit 1
fi

$RWX_PACKAGE_PATH/bin/install-dotnet
env:
DOTNET_CHANNEL: ${{ params.dotnet-channel }}
DOTNET_CHANNELS: ${{ params.dotnet-channels }}
DOTNET_QUALITY: ${{ params.dotnet-quality }}
GLOBAL_JSON_FILE: ${{ params.global-json-file }}
22 changes: 22 additions & 0 deletions dotnet/install/rwx-test-base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"image": "ubuntu:22.04",
"config": "rwx/base 1.0.0",
"arch": "x86_64"
},
{
"image": "ubuntu:22.04",
"config": "rwx/base 1.0.0",
"arch": "arm64"
},
{
"image": "ubuntu:24.04",
"config": "rwx/base 1.0.0",
"arch": "x86_64"
},
{
"image": "ubuntu:24.04",
"config": "rwx/base 1.0.0",
"arch": "arm64"
}
]
73 changes: 73 additions & 0 deletions dotnet/install/rwx-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
base:
image: ${{ init.base-image }}
config: ${{ init.base-config }}
arch: ${{ init.base-arch }}

tasks:
- key: install-channel-8
call: ${{ init.package-digest }}
with:
dotnet-channel: "8.0"

- key: install-channel-8--assert
use: install-channel-8
run: dotnet --version | grep '^8\.'

- key: install-channel-9
call: ${{ init.package-digest }}
with:
dotnet-channel: "9.0"

- key: install-channel-9--assert
use: install-channel-9
run: dotnet --version | grep '^9\.'

- key: install-channel-10-preview
call: ${{ init.package-digest }}
with:
dotnet-channel: "10.0"
dotnet-quality: preview

- key: install-channel-10-preview--assert
use: install-channel-10-preview
run: dotnet --version | grep '^10\.'

- key: write-global-json
run: |
cat > global.json << 'EOF'
{
"sdk": {
"version": "8.0.100"
}
}
EOF

- key: install-global-json
use: write-global-json
call: ${{ init.package-digest }}
with:
global-json-file: global.json
filter:
- global.json

- key: install-global-json--assert
use: install-global-json
run: dotnet --version | grep '^8\.'

- key: install-multiple-sdks
call: ${{ init.package-digest }}
with:
dotnet-channels: '["8.0","9.0"]'

- key: install-multiple-sdks--assert
use: install-multiple-sdks
run: |
dotnet --list-sdks | grep '^8\.'
dotnet --list-sdks | grep '^9\.'

- key: dotnet-tool-install
use: install-channel-8
run: |
dotnet tool install -g dotnet-format
export PATH="$HOME/.dotnet/tools:$PATH"
dotnet format --version
Loading