Skip to content

Commit 9c6c75e

Browse files
committed
Use DotnetMuxer to locate dotnet and simplify workflows
- Add DotnetMuxer helper (from .NET Foundation) to find the active dotnet - Update Program.cs to report the resolved dotnet path - Update go.csproj: adjust RIDs, remove unconditional AOT, update descriptions - Refactor build.yml: run publish for RIDs + pack - Simplify publish.yml: remove native-aot matrix job, streamline publish/pack/push
1 parent 4fdff35 commit 9c6c75e

6 files changed

Lines changed: 91 additions & 138 deletions

File tree

.github/workflows/build.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ on:
2121

2222
env:
2323
DOTNET_NOLOGO: true
24-
PackOnBuild: true
25-
GeneratePackageOnBuild: true
2624
VersionPrefix: 42.42.${{ github.run_number }}
2725
VersionLabel: ${{ github.ref }}
2826
GH_TOKEN: ${{ secrets.GH_TOKEN }}
@@ -69,14 +67,21 @@ jobs:
6967
uses: devlooped/actions-dotnet-env@v1
7068

7169
- name: 🙏 build
72-
run: |
73-
dotnet build -m:1 -bl:build.binlog -p:RuntimeIdentifiers=any
74-
dotnet build src/go/go.csproj -bl:runtime.binlog -p:RuntimeIdentifiers=any -r any
70+
run: dotnet build -m:1 -bl:build.binlog
7571

7672
- name: 🧪 test
7773
shell: pwsh
7874
run: dnx --yes retest -- --no-build
7975

76+
- name: 🙏 publish
77+
shell: pwsh
78+
run: |
79+
$rids = dotnet msbuild src/go/go.csproj -getproperty:RuntimeIdentifiers
80+
$rids | %{ $_.Split(';') } | %{ $_.Trim() } | ? { $_ } | %{ dotnet publish src/go/go.csproj -r $_ }
81+
82+
- name: 📦 pack
83+
run: dotnet pack src/go/go.csproj --no-build -m:1 -bl:pack.binlog
84+
8085
- name: 🐛 logs
8186
uses: actions/upload-artifact@v4
8287
if: runner.debug && always()

.github/workflows/publish.yml

Lines changed: 16 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -14,63 +14,10 @@ env:
1414
GH_TOKEN: ${{ secrets.GH_TOKEN }}
1515
MSBUILDTERMINALLOGGER: auto
1616
SLEET_FEED_URL: https://api.nuget.org/v3/index.json
17-
18-
defaults:
19-
run:
20-
shell: pwsh
21-
17+
2218
jobs:
23-
native-aot:
24-
name: native-aot-${{ matrix.rid }}
25-
runs-on: ${{ matrix.os }}
26-
strategy:
27-
fail-fast: false
28-
matrix:
29-
include:
30-
- os: ubuntu-latest
31-
rid: linux-x64
32-
- os: ubuntu-24.04-arm
33-
rid: linux-arm64
34-
- os: windows-latest
35-
rid: win-x64
36-
- os: windows-11-arm
37-
rid: win-arm64
38-
- os: macos-15-intel
39-
rid: osx-x64
40-
- os: macos-latest
41-
rid: osx-arm64
42-
steps:
43-
- name: 🤘 checkout
44-
uses: actions/checkout@v4
45-
46-
- name: ⚙ dotnet
47-
uses: devlooped/actions-dotnet-env@v1
48-
49-
- name: 📦 pack
50-
run: |
51-
dotnet pack src/go/go.csproj -c $env:Configuration -r ${{ matrix.rid }} -bl:"pack-${{ matrix.rid }}.binlog"
52-
53-
- name: 📤 package
54-
uses: actions/upload-artifact@v4
55-
with:
56-
name: package-${{ matrix.rid }}
57-
path: bin/*.${{ matrix.rid }}.*.nupkg
58-
retention-days: 30
59-
if-no-files-found: error
60-
61-
- name: 🐛 logs
62-
uses: actions/upload-artifact@v4
63-
if: runner.debug && always()
64-
with:
65-
name: logs-${{ matrix.rid }}
66-
path: '*.binlog'
67-
6819
publish:
69-
needs: native-aot
7020
runs-on: ${{ vars.PUBLISH_AGENT || 'ubuntu-latest' }}
71-
env:
72-
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
73-
SLEET_CONNECTION: ${{ secrets.SLEET_CONNECTION }}
7421
steps:
7522
- name: 🤘 checkout
7623
uses: actions/checkout@v4
@@ -87,79 +34,33 @@ jobs:
8734
- name: 🧪 test
8835
run: dnx --yes retest -- --no-build
8936

90-
- name: 📦 pointer
37+
- name: 🙏 publish
38+
shell: pwsh
9139
run: |
92-
dotnet pack src/go/go.csproj -c $env:Configuration -bl:pointer-pack.binlog
40+
$rids = dotnet msbuild src/go/go.csproj -getproperty:RuntimeIdentifiers
41+
$rids | %{ $_.Split(';') } | %{ $_.Trim() } | ? { $_ } | %{ dotnet publish src/go/go.csproj -r $_ }
9342
94-
- name: 📦 fallback
95-
run: |
96-
dotnet pack src/go/go.csproj -c $env:Configuration -r any -bl:any-pack.binlog
97-
98-
- name: 📤 package
99-
uses: actions/upload-artifact@v4
100-
with:
101-
name: package-any
102-
path: bin/*.nupkg
103-
retention-days: 30
104-
if-no-files-found: error
105-
106-
- name: 📥 packages
107-
uses: actions/download-artifact@v4
108-
with:
109-
pattern: package-*
110-
path: bin
111-
merge-multiple: true
43+
- name: 📦 pack
44+
run: dotnet pack src/go/go.csproj --no-build -m:1 -bl:pack.binlog
11245

11346
- name: 🐛 logs
11447
uses: actions/upload-artifact@v4
11548
if: runner.debug && always()
11649
with:
117-
name: logs-publish
50+
name: logs
11851
path: '*.binlog'
11952

12053
- name: 🚀 nuget
54+
env:
55+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
12156
if: ${{ env.NUGET_API_KEY != '' && github.event.action != 'prereleased' }}
122-
run: |
123-
$packages = @(Get-ChildItem bin -Filter *.nupkg | Where-Object Name -NotLike '*.symbols.nupkg' | Sort-Object Name)
124-
$runtimePackagePattern = '^go\.(win-x64|win-arm64|linux-x64|linux-arm64|osx-x64|osx-arm64|any)\..+\.nupkg$'
125-
$runtimePackages = @($packages | Where-Object Name -Match $runtimePackagePattern)
126-
$pointerPackages = @($packages | Where-Object Name -NotMatch $runtimePackagePattern)
127-
128-
if ($runtimePackages.Count -eq 0) { throw 'No RID-specific or fallback packages found.' }
129-
if ($pointerPackages.Count -eq 0) { throw 'No top-level pointer package found.' }
130-
131-
foreach ($package in $runtimePackages) {
132-
dotnet nuget push $package.FullName -s https://api.nuget.org/v3/index.json -k $env:NUGET_API_KEY --skip-duplicate
133-
}
134-
135-
foreach ($package in $pointerPackages) {
136-
dotnet nuget push $package.FullName -s https://api.nuget.org/v3/index.json -k $env:NUGET_API_KEY --skip-duplicate
137-
}
57+
working-directory: bin
58+
run: dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k ${{secrets.NUGET_API_KEY}} --skip-duplicate
13859

13960
- name: 🚀 sleet
61+
env:
62+
SLEET_CONNECTION: ${{ secrets.SLEET_CONNECTION }}
14063
if: env.SLEET_CONNECTION != ''
14164
run: |
142-
$packages = @(Get-ChildItem bin -Filter *.nupkg | Where-Object Name -NotLike '*.symbols.nupkg' | Sort-Object Name)
143-
$runtimePackagePattern = '^go\.(win-x64|win-arm64|linux-x64|linux-arm64|osx-x64|osx-arm64|any)\..+\.nupkg$'
144-
$runtimePackages = @($packages | Where-Object Name -Match $runtimePackagePattern)
145-
$pointerPackages = @($packages | Where-Object Name -NotMatch $runtimePackagePattern)
146-
147-
if ($runtimePackages.Count -eq 0) { throw 'No RID-specific or fallback packages found.' }
148-
if ($pointerPackages.Count -eq 0) { throw 'No top-level pointer package found.' }
149-
150-
$runtimePath = Join-Path $env:RUNNER_TEMP runtime-packages
151-
$pointerPath = Join-Path $env:RUNNER_TEMP pointer-package
152-
New-Item -ItemType Directory -Force -Path $runtimePath, $pointerPath | Out-Null
153-
154-
Copy-Item -Path $runtimePackages.FullName -Destination $runtimePath
155-
Copy-Item -Path $pointerPackages.FullName -Destination $pointerPath
156-
157-
$sleetVersion = (Invoke-RestMethod -Uri $env:SLEET_FEED_URL).'sleet:version'
158-
if ($sleetVersion) {
159-
dotnet tool update sleet -g --allow-downgrade --version $sleetVersion
160-
} else {
161-
dotnet tool update sleet -g --allow-downgrade
162-
}
163-
164-
sleet push $runtimePath --config none -f --verbose -p "SLEET_FEED_CONTAINER=nuget" -p "SLEET_FEED_CONNECTIONSTRING=$env:SLEET_CONNECTION" -p "SLEET_FEED_TYPE=azure"
165-
sleet push $pointerPath --config none -f --verbose -p "SLEET_FEED_CONTAINER=nuget" -p "SLEET_FEED_CONNECTIONSTRING=$env:SLEET_CONNECTION" -p "SLEET_FEED_TYPE=azure"
65+
dotnet tool update sleet -g --allow-downgrade --version $(curl -s --compressed ${{ vars.SLEET_FEED_URL }} | jq '.["sleet:version"]' -r)
66+
sleet push bin --config none -f --verbose -p "SLEET_FEED_CONTAINER=nuget" -p "SLEET_FEED_CONNECTIONSTRING=${{ secrets.SLEET_CONNECTION }}" -p "SLEET_FEED_TYPE=azure" || echo "No packages found"

src/go/DotnetMuxer.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Runtime.InteropServices;
5+
6+
namespace Devlooped;
7+
8+
public static class DotnetMuxer
9+
{
10+
public static FileInfo? Path { get; }
11+
12+
static DotnetMuxer()
13+
{
14+
var muxerFileName = ExecutableName("dotnet");
15+
var fxDepsFile = GetDataFromAppDomain("FX_DEPS_FILE");
16+
17+
if (string.IsNullOrEmpty(fxDepsFile))
18+
return;
19+
20+
var muxerDir = new FileInfo(fxDepsFile).Directory?.Parent?.Parent?.Parent;
21+
if (muxerDir == null)
22+
return;
23+
24+
var muxerCandidate = new FileInfo(System.IO.Path.Combine(muxerDir.FullName, muxerFileName));
25+
if (muxerCandidate.Exists)
26+
Path = muxerCandidate;
27+
}
28+
29+
public static string? GetDataFromAppDomain(string propertyName)
30+
=> AppContext.GetData(propertyName) as string;
31+
32+
public static string ExecutableName(this string withoutExtension)
33+
=> RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
34+
? withoutExtension + ".exe"
35+
: withoutExtension;
36+
}

src/go/Program.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
if (args is ["--help" or "-h" or "-?"])
1+
using Devlooped;
2+
3+
if (args is ["--help" or "-h" or "-?"])
24
{
3-
Console.WriteLine("go");
5+
Console.WriteLine("Locates the dotnet executable used to run this tool.");
6+
Console.WriteLine();
7+
Console.WriteLine("Usage: go [--help]");
48
return 0;
59
}
610

11+
var path = DotnetMuxer.Path?.FullName;
12+
if (path is null)
13+
{
14+
Console.Error.WriteLine("dotnet executable not found.");
15+
return 1;
16+
}
17+
18+
Console.WriteLine(path);
719
return 0;

src/go/go.csproj

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,32 @@
88
<RootNamespace>Devlooped</RootNamespace>
99
<SignAssembly>false</SignAssembly>
1010
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
11-
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
1211

13-
<Description>A dotnet global tool.</Description>
12+
<Description>A dotnet global tool that locates the dotnet executable.</Description>
1413
<PackageId>go</PackageId>
1514
<PackAsTool>true</PackAsTool>
16-
<PackBuildOutput>false</PackBuildOutput>
1715
<PackageReadmeFile>readme.md</PackageReadmeFile>
1816
<PackageTags>dotnet dotnet-tool</PackageTags>
1917
<PackageProjectUrl>https://github.com/devlooped/go</PackageProjectUrl>
2018

21-
<!-- Allow running on whatever latest version users have. See https://docs.microsoft.com/en-us/dotnet/core/versions/selection#framework-dependent-apps-roll-forward -->
22-
<!-- Useful for RID=any -->
23-
<RollForward>LatestMajor</RollForward>
24-
<RuntimeIdentifiers>win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64;any</RuntimeIdentifiers>
25-
26-
<PublishAot>true</PublishAot>
27-
<StripSymbols>true</StripSymbols>
28-
</PropertyGroup>
29-
30-
<PropertyGroup Condition="'$(RuntimeIdentifier)' == 'any'">
31-
<PublishAot>false</PublishAot>
19+
<RuntimeIdentifier Condition="$(BuildingInsideVisualStudio) == 'true'">win-x64</RuntimeIdentifier>
20+
<RuntimeIdentifiers>
21+
linux-x64;
22+
linux-arm64;
23+
osx-arm64;
24+
osx-x64;
25+
win-x64;
26+
win-arm64
27+
</RuntimeIdentifiers>
28+
<PublishSelfContained>false</PublishSelfContained>
3229
</PropertyGroup>
3330

3431
<ItemGroup>
3532
<None Include="readme.md" PackagePath="readme.md" Pack="true" />
3633
<None Include="Properties\*.*" />
3734
</ItemGroup>
3835

39-
<Target Name="RenderHelp" AfterTargets="Build" Condition="$(NoHelp) != 'true' and $(DesignTimeBuild) != 'true' and '$(PublishAot)' != 'true' and '$(RuntimeIdentifier)' == ''">
36+
<Target Name="RenderHelp" AfterTargets="Build" Condition="$(NoHelp) != 'true' and $(DesignTimeBuild) != 'true' and '$(RuntimeIdentifier)' == ''">
4037
<WriteLinesToFile Lines="```shell" Overwrite="true" Encoding="UTF-8" File="$(MSBuildProjectDirectory)\help.md" />
4138
<Exec Command="dotnet &quot;$(TargetPath)&quot; --help &gt;&gt; &quot;$(MSBuildProjectDirectory)\help.md&quot;" StdOutEncoding="UTF-8" EnvironmentVariables="NO_COLOR=true" />
4239
<WriteLinesToFile Lines="```" Overwrite="false" Encoding="UTF-8" File="$(MSBuildProjectDirectory)\help.md" />

src/go/help.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
```shell
2-
go
2+
Locates the dotnet executable used to run this tool.
3+
4+
Usage: go [--help]
35
```

0 commit comments

Comments
 (0)