Skip to content

Commit 382964d

Browse files
Copilotmitchdennydavidfowl
authored andcommitted
Embed dotnet-install scripts as resources in Aspire CLI (#12296)
* Initial plan * Embed dotnet-install scripts as resources in Aspire CLI - Add dotnet-install.sh and dotnet-install.ps1 as embedded resources - Update DotNetSdkInstaller to extract scripts from embedded resources instead of downloading - Remove HttpClient download logic - Add test to verify embedded scripts are accessible Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com> * Add GitHub Action to auto-update dotnet-install scripts Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> * Update workflow to run daily instead of weekly Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> * Use C# 8 using declaration syntax for cleaner code Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com> Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
1 parent 12fc58a commit 382964d

File tree

6 files changed

+3546
-10
lines changed

6 files changed

+3546
-10
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Update dotnet-install Scripts
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 6 * * *' # Daily at 06:00 UTC
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
update-scripts:
14+
runs-on: ubuntu-latest
15+
if: ${{ github.repository_owner == 'dotnet' }}
16+
steps:
17+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
18+
19+
- name: Download dotnet-install.sh
20+
run: |
21+
curl -sSL -o src/Aspire.Cli/Resources/dotnet-install.sh https://dot.net/v1/dotnet-install.sh
22+
23+
- name: Download dotnet-install.ps1
24+
run: |
25+
curl -sSL -o src/Aspire.Cli/Resources/dotnet-install.ps1 https://dot.net/v1/dotnet-install.ps1
26+
27+
- name: Create or update pull request
28+
uses: dotnet/actions-create-pull-request@e8d799aa1f8b17f324f9513832811b0a62f1e0b1
29+
with:
30+
token: ${{ secrets.GITHUB_TOKEN }}
31+
branch: update-dotnet-install-scripts
32+
base: main
33+
commit-message: "[Automated] Update dotnet-install scripts"
34+
labels: |
35+
area-cli
36+
area-engineering-systems
37+
title: "[Automated] Update dotnet-install scripts"
38+
body: "Auto-generated update of embedded dotnet-install.sh and dotnet-install.ps1 scripts from https://dot.net/v1/."

src/Aspire.Cli/Aspire.Cli.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@
119119
</Compile>
120120
</ItemGroup>
121121

122+
<ItemGroup>
123+
<EmbeddedResource Include="Resources\dotnet-install.sh" />
124+
<EmbeddedResource Include="Resources\dotnet-install.ps1" />
125+
</ItemGroup>
126+
122127
<ItemGroup>
123128
<EmbeddedResource Update="Resources\ExecCommandStrings.resx">
124129
<Generator>ResXFileCodeGenerator</Generator>

src/Aspire.Cli/DotNet/DotNetSdkInstaller.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics;
5+
using System.Reflection;
56
using System.Runtime.InteropServices;
67
using Aspire.Cli.Configuration;
78
using Microsoft.Extensions.Configuration;
@@ -143,17 +144,20 @@ public async Task InstallAsync(CancellationToken cancellationToken = default)
143144
Directory.CreateDirectory(sdksDirectory);
144145

145146
// Determine which install script to use based on the platform
146-
var (scriptUrl, scriptFileName, scriptRunner) = GetInstallScriptInfo();
147+
var (resourceName, scriptFileName, scriptRunner) = GetInstallScriptInfo();
147148

148-
// Download the install script
149+
// Extract the install script from embedded resources
149150
var scriptPath = Path.Combine(sdksDirectory, scriptFileName);
150-
using (var httpClient = new HttpClient())
151+
var assembly = Assembly.GetExecutingAssembly();
152+
using var resourceStream = assembly.GetManifestResourceStream(resourceName);
153+
if (resourceStream == null)
151154
{
152-
httpClient.Timeout = TimeSpan.FromMinutes(5);
153-
var scriptContent = await httpClient.GetStringAsync(scriptUrl, cancellationToken);
154-
await File.WriteAllTextAsync(scriptPath, scriptContent, cancellationToken);
155+
throw new InvalidOperationException($"Could not find embedded resource: {resourceName}");
155156
}
156157

158+
using var fileStream = File.Create(scriptPath);
159+
await resourceStream.CopyToAsync(fileStream, cancellationToken);
160+
157161
// Make the script executable on Unix-like systems
158162
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
159163
{
@@ -298,23 +302,23 @@ private string GetSdksDirectory()
298302
/// <summary>
299303
/// Gets the install script information based on the current platform.
300304
/// </summary>
301-
/// <returns>A tuple containing the script URL, script file name, and script runner command.</returns>
302-
private static (string ScriptUrl, string ScriptFileName, string ScriptRunner) GetInstallScriptInfo()
305+
/// <returns>A tuple containing the embedded resource name, script file name, and script runner command.</returns>
306+
private static (string ResourceName, string ScriptFileName, string ScriptRunner) GetInstallScriptInfo()
303307
{
304308
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
305309
{
306310
// Try pwsh first (PowerShell Core), then fall back to powershell (Windows PowerShell)
307311
var powerShellExecutable = GetAvailablePowerShell();
308312
return (
309-
"https://dot.net/v1/dotnet-install.ps1",
313+
"Aspire.Cli.Resources.dotnet-install.ps1",
310314
"dotnet-install.ps1",
311315
powerShellExecutable
312316
);
313317
}
314318
else
315319
{
316320
return (
317-
"https://dot.net/v1/dotnet-install.sh",
321+
"Aspire.Cli.Resources.dotnet-install.sh",
318322
"dotnet-install.sh",
319323
"bash"
320324
);

0 commit comments

Comments
 (0)