From 131b410979e0b49e2162c0718030257b22d6dc2c Mon Sep 17 00:00:00 2001 From: gowridurgad <159780674+gowridurgad@users.noreply.github.com> Date: Thu, 29 Jan 2026 05:42:03 +0530 Subject: [PATCH] Add support for workloads input (#693) * Add workloads input * fix typo * resloves conflicts * Doc update --------- Co-authored-by: gowridurgad --- .github/workflows/e2e-tests.yml | 33 +++++++++++++++++++++++++++++++++ README.md | 16 ++++++++++++++++ action.yml | 3 +++ dist/setup/index.js | 19 +++++++++++++++++++ src/setup-dotnet.ts | 23 +++++++++++++++++++++++ 5 files changed, 94 insertions(+) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 89f866c..d190a5f 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -590,3 +590,36 @@ jobs: - name: Verify dotnet (higher version) shell: pwsh run: __tests__/verify-dotnet.ps1 -Patterns "^${{ matrix.lower-version }}$", "^${{ matrix.higher-version }}$" + + test-setup-with-workloads-input: + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: + [ubuntu-latest, windows-latest, macos-15-intel, macos-latest] + steps: + - name: Checkout + uses: actions/checkout@v6 + - name: Clear toolcache + shell: pwsh + run: __tests__/clear-toolcache.ps1 ${{ runner.os }} + + - name: Setup dotnet 9.0 with workloads + uses: ./ + id: setup-dotnet + with: + dotnet-version: '9.0' + workloads: wasm-tools + - name: Verify workload + shell: pwsh + run: | + $output = dotnet workload list | Out-String + Write-Host "Workload list output:" + Write-Host $output + if ($output -notmatch "wasm-tools") { + throw "Expected workload 'wasm-tools' not found" + } + - name: Verify dotnet + shell: pwsh + run: __tests__/verify-dotnet.ps1 -Patterns "^9\.0" diff --git a/README.md b/README.md index 8a56bfd..ef0156b 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,22 @@ steps: ``` > **Note**: It's the only way to push a package to nuget.org feed for macOS/Linux machines due to API key config store limitations. +## Using the `workloads` input +The `workloads` input allows you to install .NET workloads as part of the SDK setup. Workloads provide additional platform tools and dependencies for frameworks. This action automatically runs `dotnet workload update` before installing the specified workloads to ensure manifests are refreshed and existing workloads are updated to their latest compatible versions. + +```yaml +steps: +- uses: actions/checkout@v5 +- name: Setup .NET with workloads + uses: actions/setup-dotnet@v5 + with: + dotnet-version: '9.0.x' + workloads: workload1, workload2 # Specify the workloads required for the project, such as wasm-tools, maui, etc. +- run: dotnet build +``` + +> **Note**: Ensure workloads are compatible with your runner's OS, architecture, and .NET SDK version before enabling workload installation. Some workloads may require additional installation time due to large toolchain downloads. + # Outputs and environment variables ## Outputs diff --git a/action.yml b/action.yml index 73bd19d..ca97791 100644 --- a/action.yml +++ b/action.yml @@ -24,6 +24,9 @@ inputs: cache-dependency-path: description: 'Used to specify the path to a dependency file: packages.lock.json. Supports wildcards or a list of file names for caching multiple dependencies.' required: false + workloads: + description: 'Optional SDK workloads to install for additional platform support. Examples: wasm-tools, maui, aspire.' + required: false outputs: cache-hit: description: 'A boolean value to indicate if a cache was hit.' diff --git a/dist/setup/index.js b/dist/setup/index.js index cfaad21..697703d 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -57145,6 +57145,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.run = run; const core = __importStar(__nccwpck_require__(42186)); +const exec = __importStar(__nccwpck_require__(71514)); const installer_1 = __nccwpck_require__(12574); const fs = __importStar(__nccwpck_require__(57147)); const path_1 = __importDefault(__nccwpck_require__(71017)); @@ -57206,6 +57207,24 @@ async function run() { installedDotnetVersions.push(installedVersion); } installer_1.DotnetInstallDir.addToPath(); + const workloadsInput = core.getInput('workloads'); + if (workloadsInput) { + const workloads = workloadsInput + .split(',') + .map(w => w.trim()) + .filter(Boolean); + if (workloads.length) { + try { + core.info(`Refreshing workload manifests...`); + await exec.exec('dotnet', ['workload', 'update']); + core.info(`Installing workloads: ${workloads.join(', ')}`); + await exec.exec('dotnet', ['workload', 'install', ...workloads]); + } + catch (err) { + throw new Error(`Failed to install workloads [${workloads.join(', ')}]: ${err}`); + } + } + } } const sourceUrl = core.getInput('source-url'); const configFile = core.getInput('config-file'); diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 2a628a5..36a3a63 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -1,4 +1,5 @@ import * as core from '@actions/core'; +import * as exec from '@actions/exec'; import {DotnetCoreInstaller, DotnetInstallDir} from './installer'; import * as fs from 'fs'; import path from 'path'; @@ -74,6 +75,28 @@ export async function run() { installedDotnetVersions.push(installedVersion); } DotnetInstallDir.addToPath(); + + const workloadsInput = core.getInput('workloads'); + if (workloadsInput) { + const workloads = workloadsInput + .split(',') + .map(w => w.trim()) + .filter(Boolean); + + if (workloads.length) { + try { + core.info(`Refreshing workload manifests...`); + await exec.exec('dotnet', ['workload', 'update']); + + core.info(`Installing workloads: ${workloads.join(', ')}`); + await exec.exec('dotnet', ['workload', 'install', ...workloads]); + } catch (err) { + throw new Error( + `Failed to install workloads [${workloads.join(', ')}]: ${err}` + ); + } + } + } } const sourceUrl: string = core.getInput('source-url');