Skip to content

Commit 131b410

Browse files
gowridurgadgowridurgad
andauthored
Add support for workloads input (#693)
* Add workloads input * fix typo * resloves conflicts * Doc update --------- Co-authored-by: gowridurgad <gowridurgad@gmail.com>
1 parent baa11fb commit 131b410

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,3 +590,36 @@ jobs:
590590
- name: Verify dotnet (higher version)
591591
shell: pwsh
592592
run: __tests__/verify-dotnet.ps1 -Patterns "^${{ matrix.lower-version }}$", "^${{ matrix.higher-version }}$"
593+
594+
test-setup-with-workloads-input:
595+
runs-on: ${{ matrix.operating-system }}
596+
strategy:
597+
fail-fast: false
598+
matrix:
599+
operating-system:
600+
[ubuntu-latest, windows-latest, macos-15-intel, macos-latest]
601+
steps:
602+
- name: Checkout
603+
uses: actions/checkout@v6
604+
- name: Clear toolcache
605+
shell: pwsh
606+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
607+
608+
- name: Setup dotnet 9.0 with workloads
609+
uses: ./
610+
id: setup-dotnet
611+
with:
612+
dotnet-version: '9.0'
613+
workloads: wasm-tools
614+
- name: Verify workload
615+
shell: pwsh
616+
run: |
617+
$output = dotnet workload list | Out-String
618+
Write-Host "Workload list output:"
619+
Write-Host $output
620+
if ($output -notmatch "wasm-tools") {
621+
throw "Expected workload 'wasm-tools' not found"
622+
}
623+
- name: Verify dotnet
624+
shell: pwsh
625+
run: __tests__/verify-dotnet.ps1 -Patterns "^9\.0"

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,22 @@ steps:
231231
```
232232
> **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.
233233

234+
## Using the `workloads` input
235+
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.
236+
237+
```yaml
238+
steps:
239+
- uses: actions/checkout@v5
240+
- name: Setup .NET with workloads
241+
uses: actions/setup-dotnet@v5
242+
with:
243+
dotnet-version: '9.0.x'
244+
workloads: workload1, workload2 # Specify the workloads required for the project, such as wasm-tools, maui, etc.
245+
- run: dotnet build <my project>
246+
```
247+
248+
> **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.
249+
234250
# Outputs and environment variables
235251

236252
## Outputs

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ inputs:
2424
cache-dependency-path:
2525
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.'
2626
required: false
27+
workloads:
28+
description: 'Optional SDK workloads to install for additional platform support. Examples: wasm-tools, maui, aspire.'
29+
required: false
2730
outputs:
2831
cache-hit:
2932
description: 'A boolean value to indicate if a cache was hit.'

dist/setup/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57145,6 +57145,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5714557145
Object.defineProperty(exports, "__esModule", ({ value: true }));
5714657146
exports.run = run;
5714757147
const core = __importStar(__nccwpck_require__(42186));
57148+
const exec = __importStar(__nccwpck_require__(71514));
5714857149
const installer_1 = __nccwpck_require__(12574);
5714957150
const fs = __importStar(__nccwpck_require__(57147));
5715057151
const path_1 = __importDefault(__nccwpck_require__(71017));
@@ -57206,6 +57207,24 @@ async function run() {
5720657207
installedDotnetVersions.push(installedVersion);
5720757208
}
5720857209
installer_1.DotnetInstallDir.addToPath();
57210+
const workloadsInput = core.getInput('workloads');
57211+
if (workloadsInput) {
57212+
const workloads = workloadsInput
57213+
.split(',')
57214+
.map(w => w.trim())
57215+
.filter(Boolean);
57216+
if (workloads.length) {
57217+
try {
57218+
core.info(`Refreshing workload manifests...`);
57219+
await exec.exec('dotnet', ['workload', 'update']);
57220+
core.info(`Installing workloads: ${workloads.join(', ')}`);
57221+
await exec.exec('dotnet', ['workload', 'install', ...workloads]);
57222+
}
57223+
catch (err) {
57224+
throw new Error(`Failed to install workloads [${workloads.join(', ')}]: ${err}`);
57225+
}
57226+
}
57227+
}
5720957228
}
5721057229
const sourceUrl = core.getInput('source-url');
5721157230
const configFile = core.getInput('config-file');

src/setup-dotnet.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as core from '@actions/core';
2+
import * as exec from '@actions/exec';
23
import {DotnetCoreInstaller, DotnetInstallDir} from './installer';
34
import * as fs from 'fs';
45
import path from 'path';
@@ -74,6 +75,28 @@ export async function run() {
7475
installedDotnetVersions.push(installedVersion);
7576
}
7677
DotnetInstallDir.addToPath();
78+
79+
const workloadsInput = core.getInput('workloads');
80+
if (workloadsInput) {
81+
const workloads = workloadsInput
82+
.split(',')
83+
.map(w => w.trim())
84+
.filter(Boolean);
85+
86+
if (workloads.length) {
87+
try {
88+
core.info(`Refreshing workload manifests...`);
89+
await exec.exec('dotnet', ['workload', 'update']);
90+
91+
core.info(`Installing workloads: ${workloads.join(', ')}`);
92+
await exec.exec('dotnet', ['workload', 'install', ...workloads]);
93+
} catch (err) {
94+
throw new Error(
95+
`Failed to install workloads [${workloads.join(', ')}]: ${err}`
96+
);
97+
}
98+
}
99+
}
77100
}
78101

79102
const sourceUrl: string = core.getInput('source-url');

0 commit comments

Comments
 (0)