Skip to content
Draft
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
38 changes: 38 additions & 0 deletions .github/workflows/update-dotnet-install-scripts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Update dotnet-install Scripts

on:
workflow_dispatch:
schedule:
- cron: '0 6 * * *' # Daily at 06:00 UTC

permissions:
contents: write
pull-requests: write

jobs:
update-scripts:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'dotnet' }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Download dotnet-install.sh
run: |
curl -sSL -o src/Aspire.Cli/Resources/dotnet-install.sh https://dot.net/v1/dotnet-install.sh
- name: Download dotnet-install.ps1
run: |
curl -sSL -o src/Aspire.Cli/Resources/dotnet-install.ps1 https://dot.net/v1/dotnet-install.ps1
- name: Create or update pull request
uses: dotnet/actions-create-pull-request@e8d799aa1f8b17f324f9513832811b0a62f1e0b1
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update-dotnet-install-scripts
base: main
commit-message: "[Automated] Update dotnet-install scripts"
labels: |
area-cli
area-engineering-systems
title: "[Automated] Update dotnet-install scripts"
body: "Auto-generated update of embedded dotnet-install.sh and dotnet-install.ps1 scripts from https://dot.net/v1/."
5 changes: 5 additions & 0 deletions src/Aspire.Cli/Aspire.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\dotnet-install.sh" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eerhardt bloat 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably lighter than the alternative!

<EmbeddedResource Include="Resources\dotnet-install.ps1" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resources\ExecCommandStrings.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down
28 changes: 18 additions & 10 deletions src/Aspire.Cli/DotNet/DotNetSdkInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using Aspire.Cli.Configuration;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -148,15 +149,22 @@ public async Task InstallAsync(CancellationToken cancellationToken = default)
Directory.CreateDirectory(sdksDirectory);

// Determine which install script to use based on the platform
var (scriptUrl, scriptFileName, scriptRunner) = GetInstallScriptInfo();
var (resourceName, scriptFileName, scriptRunner) = GetInstallScriptInfo();

// Download the install script
// Extract the install script from embedded resources
var scriptPath = Path.Combine(sdksDirectory, scriptFileName);
using (var httpClient = new HttpClient())
var assembly = Assembly.GetExecutingAssembly();
using (var resourceStream = assembly.GetManifestResourceStream(resourceName))
{
httpClient.Timeout = TimeSpan.FromMinutes(5);
var scriptContent = await httpClient.GetStringAsync(scriptUrl, cancellationToken);
await File.WriteAllTextAsync(scriptPath, scriptContent, cancellationToken);
if (resourceStream == null)
{
throw new InvalidOperationException($"Could not find embedded resource: {resourceName}");
}

using (var fileStream = File.Create(scriptPath))
{
await resourceStream.CopyToAsync(fileStream, cancellationToken);
}
}

// Make the script executable on Unix-like systems
Expand Down Expand Up @@ -303,23 +311,23 @@ private string GetSdksDirectory()
/// <summary>
/// Gets the install script information based on the current platform.
/// </summary>
/// <returns>A tuple containing the script URL, script file name, and script runner command.</returns>
private static (string ScriptUrl, string ScriptFileName, string ScriptRunner) GetInstallScriptInfo()
/// <returns>A tuple containing the embedded resource name, script file name, and script runner command.</returns>
private static (string ResourceName, string ScriptFileName, string ScriptRunner) GetInstallScriptInfo()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Try pwsh first (PowerShell Core), then fall back to powershell (Windows PowerShell)
var powerShellExecutable = GetAvailablePowerShell();
return (
"https://dot.net/v1/dotnet-install.ps1",
"Aspire.Cli.Resources.dotnet-install.ps1",
"dotnet-install.ps1",
powerShellExecutable
);
}
else
{
return (
"https://dot.net/v1/dotnet-install.sh",
"Aspire.Cli.Resources.dotnet-install.sh",
"dotnet-install.sh",
"bash"
);
Expand Down
Loading
Loading